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


C# SslStream.AuthenticateAsServer方法代码示例

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


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

示例1: HttpConnection

        public HttpConnection(ILogger logger, Socket sock, EndPointListener epl, bool secure, X509Certificate cert, string connectionId)
        {
            _connectionId = connectionId;
            _logger = logger;
            this.sock = sock;
            this.epl = epl;
            this.secure = secure;
            this.cert = cert;
            this.SetSocketTimeout(sock);
            if (secure == false)
            {
                stream = new NetworkStream(sock, false);
            }
            else
            {
                //ssl_stream = epl.Listener.CreateSslStream(new NetworkStream(sock, false), false, (t, c, ch, e) =>
                //{
                //    if (c == null)
                //        return true;
                //    var c2 = c as X509Certificate2;
                //    if (c2 == null)
                //        c2 = new X509Certificate2(c.GetRawCertData());
                //    client_cert = c2;
                //    client_cert_errors = new int[] { (int)e };
                //    return true;
                //});
                //stream = ssl_stream.AuthenticatedStream;

                ssl_stream = new SslStream(new NetworkStream(sock, false), false);
                ssl_stream.AuthenticateAsServer(cert);
                stream = ssl_stream;
            }
            timer = new ResumableTimer(OnTimeout);
            Init();
        }
开发者ID:tekhedd,项目名称:SocketHttpListener,代码行数:35,代码来源:HttpConnection.cs

示例2: dajStrumienJakoSerwer

        protected override Stream dajStrumienJakoSerwer(TcpClient polaczenie)
        {
            var strumien = new SslStream(polaczenie.GetStream(), false);
            strumien.AuthenticateAsServer(certyfikat, false, SslProtocols.Tls, false);

            return strumien;
        }
开发者ID:salazarrus,项目名称:mojczat,代码行数:7,代码来源:CentralaSSL.cs

示例3: ListenerThreadEntry

        static void ListenerThreadEntry()
        {
            try
            {
                var listener = new TcpListener(IPAddress.Any, Port);
                listener.Start();

                using (var socket = listener.AcceptSocket())
                {
                    var serverCertificate = new X509Certificate2(CertsPath + @"\test.pfx");
                    var stream = new NetworkStream(socket);
                    using (var sslStream = new SslStream(stream, false))
                    {
                        sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, false);

                        // terminate the connection
                        sslStream.Close();
                        socket.Disconnect(false);
                        socket.Close();

                        // this code will fail
                        using (var reader = new StreamReader(sslStream))
                        {
                            var line = reader.ReadLine();
                            Console.WriteLine("> " + line);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
开发者ID:fandrei,项目名称:TcpClientTest2,代码行数:34,代码来源:Program.cs

示例4: processClient

        private void processClient(TcpClient client)
        {
            X509Certificate certificate = new X509Certificate("..\\..\\..\\Certificate\\Certificate.pfx", "KTYy77216");
            // SslStream; leaveInnerStreamOpen = false;
            SslStream stream = new SslStream(client.GetStream(), false);
            try
            {
                // clientCertificateRequired = false
                // checkCertificateRevocation = true;
                stream.AuthenticateAsServer(certificate, false, SslProtocols.Tls, true);
                Console.WriteLine("Waiting for client message ...");

                // Read a message from the client
                string input = readMessage(stream);
                Console.WriteLine("Received: {0}", input);

                // Write a message to the client
                byte[] message = Encoding.UTF8.GetBytes("Hello client, this is a message from the server :)<EOF>");
                Console.WriteLine("Sending message to client ...");
                stream.Write(message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                stream.Close();
                client.Close();
                return;
            }
            finally
            {
                stream.Close();
                client.Close();
            }
        }
开发者ID:bemk,项目名称:rhc,代码行数:34,代码来源:SslTcpServer.cs

示例5: OnAcceptUpgrade

 protected override Stream OnAcceptUpgrade(Stream stream, out SecurityMessageProperty remoteSecurity)
 {
     SslStream stream2 = new SslStream(stream, false, new RemoteCertificateValidationCallback(this.ValidateRemoteCertificate));
     try
     {
         stream2.AuthenticateAsServer(this.parent.ServerCertificate, this.parent.RequireClientCertificate, SslProtocols.Default, false);
     }
     catch (AuthenticationException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException(exception.Message, exception));
     }
     catch (IOException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException(System.ServiceModel.SR.GetString("NegotiationFailedIO", new object[] { exception2.Message }), exception2));
     }
     if (System.ServiceModel.Security.SecurityUtils.ShouldValidateSslCipherStrength())
     {
         System.ServiceModel.Security.SecurityUtils.ValidateSslCipherStrength(stream2.CipherStrength);
     }
     remoteSecurity = this.clientSecurity;
     if (this.IsChannelBindingSupportEnabled)
     {
         this.channelBindingToken = ChannelBindingUtility.GetToken(stream2);
     }
     return stream2;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:SslStreamSecurityUpgradeAcceptor.cs

示例6: Zombie

        public Zombie(ServerMainForm form, TcpClient client)
        {
            this.mainForm = form;
            this.zombieListView = mainForm.zombieListView;
            this.client = client;
            this.netStream = client.GetStream();
            sslStream = new SslStream(netStream);

            if (sslSecured)
            {
                // Build the server cert from resources
                Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CCSURAT_Server.Resources.Server.pfx");
                byte[] bytes = new byte[stream.Length];
                stream.Read(bytes, 0, bytes.Length);
                serverCertificate = new X509Certificate2(bytes, "cs492");

                sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, false);

                // Create stream writer/reader objects, could be used for easier read/write
                sw = new StreamWriter(sslStream);
                sr = new StreamReader(sslStream);
            }

            this.active = true;

            // initialize monitor list
            monitors = new List<ControlClasses.Monitor>();
            
            // initialize ping check objects
            pingSender = new Ping();

            // request basic PC info (computer name, username, cpu, etc...)
            this.SendData("[[START]][[/START]]");
            Console.Beep();
        }
开发者ID:gotoel,项目名称:CCSURAT,代码行数:35,代码来源:Zombie.cs

示例7: InterceptConnect

        /// <summary>
        /// Intercepts a HTTP CONNECT so we can filter the encrypted requests
        /// </summary>
        public static Stream InterceptConnect(Request request, Stream clientStream, CachedConnection remote)
        {
            //This code may work but it has not been tested yet.
            string certPath = Path.Combine (Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
                "HitProxy"), "server.pfx");
            if (File.Exists (certPath) == false)
                throw new FileNotFoundException ("Need a server certificate", certPath);

            X509Certificate cert = X509Certificate2.CreateFromCertFile (certPath);

            request.Response = new Response (remote);
            request.Response.HttpVersion = "HTTP/1.1";
            request.Response.HttpCode = HttpStatusCode.OK;
            request.Response.HTTPMessage = HttpStatusCode.OK.ToString ();
            request.Response.KeepAlive = false;
            request.Response.Add ("Proxy-Agent: HitProxy");
            request.Response.SendHeaders (clientStream);

            //Client
            SslStream ssl = new SslStream (clientStream, false, RemoteCertificateValidation, LocalCertValidation);
            try {
                ssl.AuthenticateAsServer (cert, false, System.Security.Authentication.SslProtocols.Tls, false);
            } catch (Exception e) {
                Console.WriteLine (e.Message);
                throw;
            }

            //Remote server
            SslStream remoteSsl = new SslStream (remote.Stream, false, RemoteCertificateValidation);
            remoteSsl.AuthenticateAsClient (request.Uri.Host);
            remote.Stream = remoteSsl;
            return ssl;
        }
开发者ID:hultqvist,项目名称:HitProxy,代码行数:36,代码来源:ConnectProxy.cs

示例8: handler

        ///<summary>
        ///Forwards incoming clientdata to PacketHandler.
        ///</summary>
        public void handler()
        {
            clientStream = new SslStream(tcpClient.GetStream(), true);
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            Kettler_X7_Lib.Objects.Packet pack = null;

            X509Certificate serverCertificate = serverControl.getCertificate();

            try
            {
                clientStream.AuthenticateAsServer(serverCertificate,false, SslProtocols.Tls, false);
            }
            catch (Exception)
            {
                Console.WriteLine("Authentication failed");
                disconnect();
            }

            for (; ; )
            {
                try
                {
                    pack = formatter.Deserialize(clientStream) as Kettler_X7_Lib.Objects.Packet;
                    PacketHandler.getPacket(serverControl, this, pack);
                }
                catch
                {
                    disconnect();
                }

                Thread.Sleep(10);
            }
        }
开发者ID:rvnijnatten,项目名称:IP2,代码行数:36,代码来源:Client.cs

示例9: connectForwardServerCallBack

        public static void connectForwardServerCallBack(IAsyncResult ar)
        {
            ProxyConnection conn = (ProxyConnection)ar.AsyncState;
            conn.serverSocket.EndConnect(ar);
            ProxySwapDataTask proxy = new ProxySwapDataTask(conn);

            //now we have both server socket and client socket, we can pass the data back and forth for both side
            System.Diagnostics.Debug.Assert(true == conn.clientSocket.Connected);
            System.Diagnostics.Debug.Assert(true == conn.serverSocket.Connected);

            WinTunnel.WriteTextToConsole(string.Format("ProxyConnection#{0}-- client socket or server socket start receiving data....",
                    conn.connNumber));
            WinTunnel.connMgr.AddConnection(conn);

            conn.clientStream =  conn.clientSocket.GetStream();
            if (conn.m_bHttpsClient)
            {
                SslStream sslStream = new SslStream(conn.clientSocket.GetStream(), false);
                sslStream.AuthenticateAsServer(WinTunnel.CertificateForClientConnection, false, SslProtocols.Tls, true);
                conn.clientStream = sslStream;
            }

            conn.serverStream = conn.serverSocket.GetStream();
            if (conn.m_bHttpsServer)
            {
                SslStream sslStream = new SslStream(conn.serverStream, false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
                sslStream.AuthenticateAsClient(conn.serverName);
                conn.serverStream = sslStream;
            }

            conn.clientStream.BeginRead(conn.clientReadBuffer, 0, ProxyConnection.BUFFER_SIZE, new AsyncCallback(clientReadCallBack), conn);
            //Read data from the server socket
            conn.serverStream.BeginRead(conn.serverReadBuffer, 0, ProxyConnection.BUFFER_SIZE, new AsyncCallback(serverReadCallBack), conn);
        }
开发者ID:jonathanli2,项目名称:HttpProxyTunnel,代码行数:34,代码来源:ProxySwapDataTask.cs

示例10: Client

 public Client(TcpClient client, ServerHandler handler, bool ssl)
 {
     Handler = handler;
     RawClient = client;
     if (!ssl) {
         Writer = new StreamWriter(RawClient.GetStream());
         Reader = new StreamReader(RawClient.GetStream());
     } else {
         if (cert == null) {
             var path = Path.GetFullPath(Path.Combine(References.GCPD_FOLDER, Config.User.Ssl_Cert_Path));
             if (!(new FileInfo(path)).Exists)
                 throw new Exception("certificate does not exist at " + path);
             cert = new X509Certificate2(path, Config.User.Ssl_Cert_Pass);
         }
         try {
             SslStream stream = new SslStream(RawClient.GetStream(), false);
             stream.AuthenticateAsServer(cert, false, System.Security.Authentication.SslProtocols.Tls, false);
             Writer = new StreamWriter(stream);
             Reader = new StreamReader(stream);
         } catch (IOException e) {
             client.Close();
             throw e;
         }
     }
     ThreadPool.QueueUserWorkItem((object o) => { AssignHostName(); });
 }
开发者ID:samrg472,项目名称:GcpD,代码行数:26,代码来源:ClientHandler.cs

示例11: ExtendConnection

        public Stream ExtendConnection(Stream stream)
        {
            var ssl = new SslStream(stream, false, _validation);
#if (UAP10_0 || DOTNET5_4 || NETSTANDARD || NETSTANDARDAPP1_5)
            ssl.AuthenticateAsServerAsync(_certificate, _validation != null, SslProtocols.Tls12, false).Wait();
#else
            ssl.AuthenticateAsServer(_certificate, _validation != null, SslProtocols.Tls12, false);
#endif
            return ssl;
        }
开发者ID:papci,项目名称:WebSocketListener,代码行数:10,代码来源:WebSocketSecureConnectionExtension.cs

示例12: OneSsl

        //サーバ接続
        public OneSsl(Socket socket, X509Certificate2 x509Certificate2)
        {
            _stream = new SslStream(new NetworkStream(socket));
            try{
                _stream.AuthenticateAsServer(x509Certificate2);
            } catch (Exception){

            }
            _stream.ReadTimeout = 5000;
            _stream.WriteTimeout = 5000;
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:12,代码来源:OneSsl.cs

示例13: Client

        public Client(TcpClient clientSocket)
        {
            _clientSocket = clientSocket;

            var sslStream = new SslStream(clientSocket.GetStream(), false);
            sslStream.AuthenticateAsServer(Server.GetServer().Certificate, false, SslProtocols.Tls, true);
            Stream = new BinaryStream(sslStream);

            BetterConsole.WriteLog("Connection secured.");

            StartClientThread();
        }
开发者ID:jterweeme,项目名称:spchat,代码行数:12,代码来源:Client.cs

示例14: DesktopNetworkStream

        /// <summary>
        /// Initializes a server instance of <see cref="DesktopNetworkStream"/>.
        /// </summary>
        /// <param name="tcpClient">TCP client.</param>
        /// <param name="certificate">Certificate for authenticated connection.</param>
        /// <remarks>Ownership of <paramref name="tcpClient"/> remains with the caller, including responsibility for
        /// disposal. Therefore, a handle to <paramref name="tcpClient"/> is <em>not</em> stored when <see cref="DesktopNetworkStream"/>
        /// is initialized with this server-side constructor.</remarks>
        internal DesktopNetworkStream(TcpClient tcpClient, X509Certificate certificate)
        {
            Stream stream = tcpClient.GetStream();
            if (certificate != null)
            {
                var ssl = new SslStream(stream, false);
                ssl.AuthenticateAsServer(certificate, false, SslProtocols.Tls, false);
                stream = ssl;
            }

            this.networkStream = stream;
        }
开发者ID:gustavosaita,项目名称:fo-dicom,代码行数:20,代码来源:DesktopNetworkStream.cs

示例15: Authenticate

        /// <summary>
        /// Authenticates as server
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        protected SslStream Authenticate(SslStream stream)
        {
            try {
                stream.AuthenticateAsServer(this.Certificate);

                this.ConnectionState = ConnectionState.ConnectionReady;
            }
            catch (AuthenticationException e) {
                this.Shutdown(e);
            }

            return stream;
        }
开发者ID:EBassie,项目名称:Potato,代码行数:18,代码来源:CommandServerClient.cs


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