当前位置: 首页>>代码示例>>C#>>正文


C# SslStream.EndAuthenticateAsServer方法代码示例

本文整理汇总了C#中System.Net.Security.SslStream.EndAuthenticateAsServer方法的典型用法代码示例。如果您正苦于以下问题:C# SslStream.EndAuthenticateAsServer方法的具体用法?C# SslStream.EndAuthenticateAsServer怎么用?C# SslStream.EndAuthenticateAsServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Security.SslStream的用法示例。


在下文中一共展示了SslStream.EndAuthenticateAsServer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: connectionHandler

            public connectionHandler(Socket socket, HttpServer server, bool secure)
            {
                Socket = socket;

                _requestId = Rnd.Next();
                _requestStart = DateTime.UtcNow;
                _server = server;
                _secure = secure;

                _server.Log.Info(4, "{0:X8} Incoming connection from {1}".Fmt(_requestId, socket.RemoteEndPoint));

                _buffer = new byte[1024];
                _bufferDataOffset = 0;
                _bufferDataLength = 0;

                _headersSoFar = "";

                lock (server._activeConnectionHandlers)
                    server._activeConnectionHandlers.Add(this);

                var stream = new NetworkStream(socket, ownsSocket: true);
                if (_secure)
                {
                    var secureStream = new SslStream(stream);
                    _stream = secureStream;
                    secureStream.BeginAuthenticateAsServer(new X509Certificate2(server.Options.CertificatePath, server.Options.CertificatePassword), false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, true, ar =>
                    {
                        try
                        {
                            secureStream.EndAuthenticateAsServer(ar);
                        }
                        catch (Exception e)
                        {
                            Socket.Close();
                            cleanupIfDone();
                            if (_server.ResponseExceptionHandler != null)
                                _server.ResponseExceptionHandler(null, e, null);
                            return;
                        }
                        receiveMoreHeaderData();
                    }, null);
                }
                else
                {
                    _stream = stream;
                    receiveMoreHeaderData();
                }
            }
开发者ID:RT-Projects,项目名称:RT.Servers,代码行数:48,代码来源:HttpServer.cs

示例2: ProcessConnection

        void ProcessConnection(Socket listener, IAsyncResult ar)
        {
            Socket ns = listener.EndAccept (ar);
            ns.NoDelay = true;
            SslStream ssl = new SslStream (new NetworkStream (ns, true));

            ssl.BeginAuthenticateAsServer (cert, (IAsyncResult ar2) => {
                try {
                    ssl.EndAuthenticateAsServer (ar2);
                    Protocol p = new Protocol ();
                    p.OnMessage += (incoming) => {
                        var hdr = incoming.Header;
                        // TODO timeout handling
                        if (hdr ["type"].AsString(null) != "request") {
                            Logger.LogError ("received non-request");
                            incoming.Discard ();
                            return;
                        }
                        if (!hdr.ContainsKey ("request_id")) {
                            Logger.LogError ("Received request with no request_id");
                            incoming.Discard ();
                            return;
                        }
                        var id = hdr ["request_id"];
                        reqh (incoming, (reply) => {
                            reply.Header ["type"] = "reply";
                            reply.Header ["request_id"] = id;
                            p.SendMessage (reply);
                        });
                    };
                    p.OnClose += (error) => {
                        Logger.LogInfo ("scamp connection closed: {0}", error);
                    };
                    p.Start (ssl);
                } catch (Exception ex) {
                    Logger.LogError ("connection server authenticate: {0}", ex);
                }
            }, null);
        }
开发者ID:dnorman,项目名称:scamp,代码行数:39,代码来源:SCAMPSOAServer.cs


注:本文中的System.Net.Security.SslStream.EndAuthenticateAsServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。