Exemplo n.º 1
0
        /*
         *      Client											Server
         *
         *      ClientHello                 -------->
         *                                                                                                      ServerHello
         *                                                                                                      Certificate*
         *                                                                                                      ServerKeyExchange*
         *                                                                                                      CertificateRequest*
         *                                                              <--------			ServerHelloDone
         *      Certificate*
         *      ClientKeyExchange
         *      CertificateVerify*
         *      [ChangeCipherSpec]
         *      Finished                    -------->
         *                                                                                                      [ChangeCipherSpec]
         *                                                              <--------           Finished
         *      Application Data            <------->			Application Data
         *
         *                      Fig. 1 - Message flow for a full handshake
         */

        internal override IAsyncResult OnBeginNegotiateHandshake(AsyncCallback callback, object state)
        {
            try
            {
                if (this.context.HandshakeState != HandshakeState.None)
                {
                    this.context.Clear();
                }

                // Obtain supported cipher suites
                this.context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol);

                // Set handshake state
                this.context.HandshakeState = HandshakeState.Started;

                // Send client hello
                return(this.protocol.BeginSendRecord(HandshakeType.ClientHello, callback, state));
            }
            catch (TlsException ex)
            {
                this.protocol.SendAlert(ex.Alert);

                throw new IOException("The authentication or decryption has failed.", ex);
            }
            catch (Exception ex)
            {
                this.protocol.SendAlert(AlertDescription.InternalError);

                throw new IOException("The authentication or decryption has failed.", ex);
            }
        }
Exemplo n.º 2
0
        internal override IAsyncResult OnBeginNegotiateHandshake(AsyncCallback callback, object state)
        {
            try
            {
                if (context.HandshakeState != 0)
                {
                    context.Clear();
                }
                context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(context.SecurityProtocol);
                context.HandshakeState   = HandshakeState.Started;
                return(protocol.BeginSendRecord(HandshakeType.ClientHello, callback, state));

IL_0056:
                IAsyncResult result;
                return(result);
            }
            catch (TlsException ex)
            {
                protocol.SendAlert(ex.Alert);
                throw new IOException("The authentication or decryption has failed.", ex);
IL_0079:
                IAsyncResult result;
                return(result);
            }
            catch (Exception innerException)
            {
                protocol.SendAlert(AlertDescription.InternalError);
                throw new IOException("The authentication or decryption has failed.", innerException);
IL_0098:
                IAsyncResult result;
                return(result);
            }
        }
 internal override IAsyncResult OnBeginNegotiateHandshake(AsyncCallback callback, object state)
 {
     if (this.context.HandshakeState != HandshakeState.None)
     {
         this.context.Clear();
     }
     this.context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol);
     this.context.HandshakeState   = HandshakeState.Started;
     return(this.protocol.BeginReceiveRecord(this.innerStream, callback, state));
 }
Exemplo n.º 4
0
        public void ChangeProtocol(short protocol)
        {
            SecurityProtocolType protocol1 = this.DecodeProtocolCode(protocol);

            if ((protocol1 & this.SecurityProtocolFlags) != protocol1 && (this.SecurityProtocolFlags & SecurityProtocolType.Default) != SecurityProtocolType.Default)
            {
                throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
            }
            this.SecurityProtocol = protocol1;
            this.SupportedCiphers.Clear();
            this.SupportedCiphers = (CipherSuiteCollection)null;
            this.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(protocol1);
        }
Exemplo n.º 5
0
        public void ChangeProtocol(short protocol)
        {
            SecurityProtocolType securityProtocolType = DecodeProtocolCode(protocol);

            if ((securityProtocolType & SecurityProtocolFlags) == securityProtocolType || (SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
            {
                SecurityProtocol = securityProtocolType;
                SupportedCiphers.Clear();
                SupportedCiphers = null;
                SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(securityProtocolType);
                return;
            }
            throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
        }
Exemplo n.º 6
0
        public void ChangeProtocol(short protocol)
        {
            SecurityProtocolType protocolType = this.DecodeProtocolCode(protocol);

            if ((protocolType & this.SecurityProtocolFlags) == protocolType ||
                (this.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
            {
                this.SecurityProtocol = protocolType;
                this.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers((this is ServerContext), protocolType);
            }
            else
            {
                throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
            }
        }
Exemplo n.º 7
0
        /*
         *      Client											Server
         *
         *      ClientHello                 -------->
         *                                                                                                      ServerHello
         *                                                                                                      Certificate*
         *                                                                                                      ServerKeyExchange*
         *                                                                                                      CertificateRequest*
         *                                                              <--------			ServerHelloDone
         *      Certificate*
         *      ClientKeyExchange
         *      CertificateVerify*
         *      [ChangeCipherSpec]
         *      Finished                    -------->
         *                                                                                                      [ChangeCipherSpec]
         *                                                              <--------           Finished
         *      Application Data            <------->			Application Data
         *
         *                      Fig. 1 - Message flow for a full handshake
         */

        internal override IAsyncResult OnBeginNegotiateHandshake(AsyncCallback callback, object state)
        {
            // Reset the context if needed
            if (this.context.HandshakeState != HandshakeState.None)
            {
                this.context.Clear();
            }

            // Obtain supported cipher suites
            this.context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol);

            // Set handshake state
            this.context.HandshakeState = HandshakeState.Started;

            // Receive Client Hello message
            return(this.protocol.BeginReceiveRecord(this.innerStream, callback, state));
        }
Exemplo n.º 8
0
        internal override IAsyncResult BeginNegotiateHandshake(AsyncCallback callback, object state)
        {
            if (this.context.HandshakeState != HandshakeState.None)
            {
                this.context.Clear();
            }

            // Obtain supported cipher suites
            this.context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(false, context.SecurityProtocol);

            // Set handshake state
            this.context.HandshakeState = HandshakeState.Started;

            NegotiateAsyncResult result = new NegotiateAsyncResult(callback, state, NegotiateState.SentClientHello);

            // Begin sending the client hello
            this.protocol.BeginSendRecord(HandshakeType.ClientHello, NegotiateAsyncWorker, result);

            return(result);
        }