Exemplo n.º 1
0
        protected virtual void HandleServerHello(TlsServerHello message)
        {
            Context.VerifyServerProtocol(message.ServerProtocol);

            // Server random
            HandshakeParameters.ServerRandom = message.ServerRandom;

            // Session ID
            HandshakeParameters.SessionId = message.SessionID;

            HandshakeParameters.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(Context.NegotiatedProtocol);

            // Cipher suite
            if (!HandshakeParameters.SupportedCiphers.Contains(message.SelectedCipher))
            {
                // The server has sent an invalid ciphersuite
                throw new TlsException(AlertDescription.InsuficientSecurity, "Invalid cipher suite received from server");
            }

            var cipher = CipherSuiteFactory.CreateCipherSuite(Context.NegotiatedProtocol, message.SelectedCipher);

                        #if DEBUG_FULL
            if (Context.EnableDebugging)
            {
                cipher.EnableDebugging = true;
            }
                        #endif
            Session.PendingCrypto = cipher.Initialize(false, Context.NegotiatedProtocol);
        }
Exemplo n.º 2
0
 protected void WriteHandshake(MemoryStream ms)
 {
     Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(SecurityProtocolType.Tls);
     ms.WriteByte(0x16);           // Handshake
     ms.WriteByte(3);              // version-major
     ms.WriteByte(1);              // version-minor
 }
Exemplo n.º 3
0
 public byte [] ProcessClientHello()
 {
     Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(Context.SecurityProtocol);
     Context.HandshakeState   = HandshakeState.Started;
     Protocol.SendRecord(HandshakeType.ClientHello);
     stream.Flush();
     return(stream.ToArray());
 }
Exemplo n.º 4
0
        public void ProcessClientHello(byte [] raw)
        {
            Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(Context.SecurityProtocol);
            Context.HandshakeState   = HandshakeState.Started;

            stream.Write(raw, 0, raw.Length);
            stream.Seek(0, SeekOrigin.Begin);

            Protocol.ReceiveRecord(stream);
        }
Exemplo n.º 5
0
        private void processProtocol(short protocol)
        {
            SecurityProtocolType protocol1 = this.Context.DecodeProtocolCode(protocol);

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

            if ((securityProtocolType & base.Context.SecurityProtocolFlags) == securityProtocolType || (base.Context.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
            {
                base.Context.SecurityProtocol = securityProtocolType;
                base.Context.SupportedCiphers.Clear();
                base.Context.SupportedCiphers = null;
                base.Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(securityProtocolType);
                return;
            }
            throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
        }
Exemplo n.º 7
0
 public byte [] ProcessClientKeyExchange()
 {
     stream.SetLength(0);
     if (mutual)
     {
         Protocol.SendRecord(HandshakeType.Certificate);
     }
     Protocol.SendRecord(HandshakeType.ClientKeyExchange);
     Context.Negotiating.Cipher.ComputeKeys();
     Context.Negotiating.Cipher.InitializeCipher();
     Protocol.SendChangeCipherSpec();
     Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(SecurityProtocolType.Tls);
     Protocol.SendRecord(HandshakeType.Finished);
     stream.Flush();
     return(stream.ToArray());
 }
Exemplo n.º 8
0
        private void processProtocol(short protocol)
        {
            SecurityProtocolType clientProtocol = this.Context.DecodeProtocolCode(protocol);

            if ((clientProtocol & this.Context.SecurityProtocolFlags) == clientProtocol ||
                (this.Context.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
            {
                this.Context.SecurityProtocol = clientProtocol;
                this.Context.SupportedCiphers.Clear();
                this.Context.SupportedCiphers = null;
                this.Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(clientProtocol);
            }
            else
            {
                throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
            }
        }
Exemplo n.º 9
0
        private void processProtocol(short protocol)
        {
            // a server MUST reply with the hight version supported (`true` for fallback)
            // so a TLS 1.2 client (like Google Chrome) will be returned that the server uses TLS 1.0
            // instead of an alert about the protocol
            SecurityProtocolType clientProtocol = Context.DecodeProtocolCode(protocol, true);

            if ((clientProtocol & this.Context.SecurityProtocolFlags) == clientProtocol ||
                (this.Context.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
            {
                this.Context.SecurityProtocol = clientProtocol;
                this.Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(true, clientProtocol);
            }
            else
            {
                throw new TlsException(AlertDescription.ProtocolVersion, "Incorrect protocol version received from server");
            }
        }
Exemplo n.º 10
0
        private void processProtocol(short protocol)
        {
            var serverProtocol = Context.DecodeProtocolCode(protocol);

            if ((serverProtocol & Context.SecurityProtocolFlags) == serverProtocol ||
                (Context.SecurityProtocolFlags & SecurityProtocolType.Default) == SecurityProtocolType.Default)
            {
                Context.SecurityProtocol = serverProtocol;
                Context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(false, serverProtocol);

                DebugHelper.WriteLine("Selected protocol {0}", serverProtocol);
            }
            else
            {
                throw new TlsException(
                          AlertDescription.ProtocolVersion,
                          "Incorrect protocol version received from server");
            }
        }