Exemplo n.º 1
0
        protected override void ProcessAsTls1()
        {
            base.Write(base.Context.Protocol);
            TlsStream tlsStream = new TlsStream();

            tlsStream.Write(base.Context.GetUnixTime());
            tlsStream.Write(base.Context.GetSecureRandomBytes(28));
            this.random = tlsStream.ToArray();
            tlsStream.Reset();
            base.Write(this.random);
            base.Context.SessionId = ClientSessionCache.FromHost(base.Context.ClientSettings.TargetHost);
            if (base.Context.SessionId != null)
            {
                base.Write((byte)base.Context.SessionId.Length);
                if (base.Context.SessionId.Length > 0)
                {
                    base.Write(base.Context.SessionId);
                }
            }
            else
            {
                base.Write(0);
            }
            base.Write((short)(base.Context.SupportedCiphers.Count * 2));
            for (int i = 0; i < base.Context.SupportedCiphers.Count; i++)
            {
                base.Write(base.Context.SupportedCiphers[i].Code);
            }
            base.Write(1);
            base.Write((byte)base.Context.CompressionMethod);
        }
Exemplo n.º 2
0
        protected override void ProcessAsTls1()
        {
            processProtocol(ReadInt16());
            random = ReadBytes(32);
            int num = ReadByte();

            if (num > 0)
            {
                sessionId = ReadBytes(num);
                ClientSessionCache.Add(base.Context.ClientSettings.TargetHost, sessionId);
                base.Context.AbbreviatedHandshake = HandshakeMessage.Compare(sessionId, base.Context.SessionId);
            }
            else
            {
                base.Context.AbbreviatedHandshake = false;
            }
            short code = ReadInt16();

            if (base.Context.SupportedCiphers.IndexOf(code) == -1)
            {
                throw new TlsException(AlertDescription.InsuficientSecurity, "Invalid cipher suite received from server");
            }
            cipherSuite       = base.Context.SupportedCiphers[code];
            compressionMethod = (SecurityCompressionType)ReadByte();
        }
Exemplo n.º 3
0
        protected override void ProcessAsTls1()
        {
            this.processProtocol(this.ReadInt16());
            this.random = this.ReadBytes(32);
            int count = (int)this.ReadByte();

            if (count > 0)
            {
                this.sessionId = this.ReadBytes(count);
                ClientSessionCache.Add(this.Context.ClientSettings.TargetHost, this.sessionId);
                this.Context.AbbreviatedHandshake = HandshakeMessage.Compare(this.sessionId, this.Context.SessionId);
            }
            else
            {
                this.Context.AbbreviatedHandshake = false;
            }
            short code = this.ReadInt16();

            if (this.Context.SupportedCiphers.IndexOf(code) == -1)
            {
                throw new TlsException(AlertDescription.InsuficientSecurity, "Invalid cipher suite received from server");
            }
            this.cipherSuite       = this.Context.SupportedCiphers[code];
            this.compressionMethod = (SecurityCompressionType)this.ReadByte();
        }
Exemplo n.º 4
0
        protected override void ProcessAsTls1()
        {
            // Read protocol version
            this.processProtocol(this.ReadInt16());

            // Read random  - Unix time + Random bytes
            this.random = this.ReadBytes(32);

            // Read Session id
            int length = (int)ReadByte();

            if (length > 0)
            {
                this.sessionId = this.ReadBytes(length);
                ClientSessionCache.Add(this.Context.ClientSettings.TargetHost, this.sessionId);
                this.Context.AbbreviatedHandshake = Compare(this.sessionId, this.Context.SessionId);
            }
            else
            {
                this.Context.AbbreviatedHandshake = false;
            }

            // Read cipher suite
            short cipherCode = this.ReadInt16();

            if (this.Context.SupportedCiphers.IndexOf(cipherCode) == -1)
            {
                // The server has sent an invalid ciphersuite
                throw new TlsException(AlertDescription.InsuficientSecurity, "Invalid cipher suite received from server");
            }
            this.cipherSuite = this.Context.SupportedCiphers[cipherCode];

            // Read compression methods ( always 0 )
            this.compressionMethod = (SecurityCompressionType)this.ReadByte();
        }
Exemplo n.º 5
0
        protected override void ProcessAsTls1()
        {
            // Client Version
            this.Write(this.Context.Protocol);

            // Random bytes - Unix time + Radom bytes [28]
            TlsStream clientRandom = new TlsStream();

            clientRandom.Write(this.Context.GetUnixTime());
            clientRandom.Write(this.Context.GetSecureRandomBytes(28));
            this.random = clientRandom.ToArray();
            clientRandom.Reset();

            this.Write(this.random);

            // Session id
            // Check if we have a cache session we could reuse
            this.Context.SessionId = ClientSessionCache.FromHost(this.Context.ClientSettings.TargetHost);
            if (this.Context.SessionId != null)
            {
                this.Write((byte)this.Context.SessionId.Length);
                if (this.Context.SessionId.Length > 0)
                {
                    this.Write(this.Context.SessionId);
                }
            }
            else
            {
                this.Write((byte)0);
            }

            // Write length of Cipher suites
            this.Write((short)(this.Context.SupportedCiphers.Count * 2));

            // Write Supported Cipher suites
            for (int i = 0; i < this.Context.SupportedCiphers.Count; i++)
            {
                this.Write((short)this.Context.SupportedCiphers[i].Code);
            }

            // Compression methods length
            this.Write((byte)1);

            // Compression methods ( 0 = none )
            this.Write((byte)this.Context.CompressionMethod);

            // http://www.ietf.org/rfc/rfc3546.txt
            TlsStream extensions = new TlsStream();

            byte[] server_name = System.Text.Encoding.UTF8.GetBytes(Context.ClientSettings.TargetHost);
            extensions.Write((short)0x0000);                                    // ExtensionType: server_name (0)
            extensions.Write((short)(server_name.Length + 5));                  // ServerNameList (length)
            extensions.Write((short)(server_name.Length + 3));                  // ServerName (length)
            extensions.Write((byte)0x00);                                       // NameType: host_name (0)
            extensions.Write((short)server_name.Length);                        // HostName (length)
            extensions.Write(server_name);                                      // HostName (UTF8)
            this.Write((short)extensions.Length);
            this.Write(extensions.ToArray());
        }
Exemplo n.º 6
0
        protected override void ProcessAsTls1()
        {
            // Client Version
            this.Write(this.Context.Protocol);

            // Random bytes - Unix time + Radom bytes [28]
            TlsStream clientRandom = new TlsStream();

            clientRandom.Write(this.Context.GetUnixTime());
            clientRandom.Write(this.Context.GetSecureRandomBytes(28));
            this.random = clientRandom.ToArray();
            clientRandom.Reset();

            this.Write(this.random);

            // Session id
            // Check if we have a cache session we could reuse
            this.Context.SessionId = ClientSessionCache.FromHost(this.Context.ClientSettings.TargetHost);
            if (this.Context.SessionId != null)
            {
                this.Write((byte)this.Context.SessionId.Length);
                if (this.Context.SessionId.Length > 0)
                {
                    this.Write(this.Context.SessionId);
                }
            }
            else
            {
                this.Write((byte)0);
            }

            // Write length of Cipher suites
            this.Write((short)(this.Context.SupportedCiphers.Count * 2));

            // Write Supported Cipher suites
            for (int i = 0; i < this.Context.SupportedCiphers.Count; i++)
            {
                this.Write((short)this.Context.SupportedCiphers[i].Code);
            }

            // Compression methods length
            this.Write((byte)1);

            // Compression methods ( 0 = none )
            this.Write((byte)this.Context.CompressionMethod);
        }
Exemplo n.º 7
0
        protected override void ProcessAsSsl3()
        {
            // Client Version
            Write(Context.Protocol);

            // Random bytes - Unix time + Radom bytes [28]
            var clientRandom = new TlsStream();

            clientRandom.Write(Context.GetUnixTime());
            clientRandom.Write(Context.GetSecureRandomBytes(28));
            random = clientRandom.ToArray();
            clientRandom.Reset();

            Write(random);

            // Session id
            // Check if we have a cache session we could reuse
            Context.SessionId = ClientSessionCache.FromHost(Context.ClientSettings.TargetHost);
            if (Context.SessionId != null)
            {
                Write((byte)Context.SessionId.Length);
                if (Context.SessionId.Length > 0)
                {
                    Write(Context.SessionId);
                }
            }
            else
            {
                Write((byte)0);
            }

            // Write length of Cipher suites
            Write((short)(Context.SupportedCiphers.Count * 2));

            // Write Supported Cipher suites
            for (var i = 0; i < Context.SupportedCiphers.Count; i++)
            {
                Write(((IList <CipherSuite>)Context.SupportedCiphers)[i].Code);
            }

            // Compression methods length
            Write((byte)1);

            // Compression methods ( 0 = none )
            Write((byte)Context.CompressionMethod);
        }