Exemplo n.º 1
0
        protected virtual TlsServerHello GenerateServerHello()
        {
            var serverUnixTime = HandshakeParameters.GetUnixTime();

            HandshakeParameters.ServerRandom = Context.Session.GetSecureRandomBytes(32);
            TlsBuffer.WriteInt32(HandshakeParameters.ServerRandom.Buffer, 0, serverUnixTime);

            return(new TlsServerHello(
                       Context.NegotiatedProtocol, HandshakeParameters.ServerRandom,
                       HandshakeParameters.SessionId, PendingCrypto.Cipher.Code, HandshakeParameters.ActiveExtensions));
        }
Exemplo n.º 2
0
        protected virtual TlsClientHello GenerateClientHello()
        {
            var clientUnixTime = HandshakeParameters.GetUnixTime();

            HandshakeParameters.ClientRandom = Context.Session.GetSecureRandomBytes(32);
            TlsBuffer.WriteInt32(HandshakeParameters.ClientRandom.Buffer, 0, clientUnixTime);

            var requestedUserCiphers = Config.UserSettings != null ? Config.UserSettings.RequestedCiphers : null;
            CipherSuiteCollection requestedCiphers;

            if (requestedUserCiphers != null)
            {
                requestedCiphers = new CipherSuiteCollection(Config.RequestedProtocol, requestedUserCiphers);
            }
            else
            {
                requestedCiphers = CipherSuiteFactory.GetDefaultCiphers(Config.RequestedProtocol);
            }
            if (requestedCiphers.Protocol != Config.RequestedProtocol)
            {
                throw new TlsException(AlertDescription.ProtocolVersion);
            }

            HandshakeParameters.SupportedCiphers = requestedCiphers.Clone();

            if (Config.EnableSecureRenegotiation && !Session.SecureRenegotiation && ((Config.RenegotiationFlags & RenegotiationFlags.SendCipherSpecCode) != 0))
            {
                HandshakeParameters.SupportedCiphers.AddSCSV();
            }

            if (ServerNameExtension.IsLegalHostName(Config.TargetHost))
            {
                HandshakeParameters.RequestedExtensions.Add(new ServerNameExtension(Config.TargetHost));
            }
            if (Config.EnableSecureRenegotiation && (Session.SecureRenegotiation || ((Config.RenegotiationFlags & RenegotiationFlags.SendClientHelloExtension) != 0)))
            {
                HandshakeParameters.RequestedExtensions.Add(RenegotiationExtension.CreateClient(Context));
            }
            if (UserSettings.HasClientCertificateParameters)
            {
                HandshakeParameters.RequestedExtensions.Add(new SignatureAlgorithmsExtension(UserSettings.ClientCertificateParameters.SignatureAndHashAlgorithms));
            }

            return(new TlsClientHello(
                       Config.RequestedProtocol, HandshakeParameters.ClientRandom, HandshakeParameters.SessionId,
                       HandshakeParameters.SupportedCiphers.ToArray(), HandshakeParameters.RequestedExtensions));
        }
Exemplo n.º 3
0
        protected virtual TlsClientHello GenerateClientHello()
        {
            var clientUnixTime = HandshakeParameters.GetUnixTime();

            TlsBuffer.WriteInt32(HandshakeParameters.ClientRandom.Buffer, 0, clientUnixTime);

            if (ServerNameExtension.IsLegalHostName(Config.TargetHost))
            {
                HandshakeParameters.RequestedExtensions.Add(new ServerNameExtension(Config.TargetHost));
            }
            if (Config.EnableSecureRenegotiation && (Session.SecureRenegotiation || ((Config.RenegotiationFlags & RenegotiationFlags.SendClientHelloExtension) != 0)))
            {
                HandshakeParameters.RequestedExtensions.Add(RenegotiationExtension.CreateClient(Context));
            }

            if (Session.SignatureParameters != null)
            {
                HandshakeParameters.RequestedExtensions.Add(new SignatureAlgorithmsExtension(Session.SignatureParameters));
            }

            return(new TlsClientHello(
                       Config.RequestedProtocol, HandshakeParameters.ClientRandom, HandshakeParameters.SessionId,
                       HandshakeParameters.SupportedCiphers.ToArray(), HandshakeParameters.RequestedExtensions));
        }