Ejemplo n.º 1
0
        internal void Receive(ICertificateProvider certProvider, INetState ns, HttpsReader reader)
        {
            RecordHandshake(reader.Buffer, reader.Length, !reader.IsDecrypted);
            EHandshake handshakeType      = (EHandshake)reader.ReadByte();
            int        handshakeMsgLength = reader.Read24BitInt();

            HttpsReader.VerifyLengthRemaining(reader, handshakeMsgLength, "Ssl handshake");
            switch (handshakeType)
            {
            case EHandshake.ClientHello:
                ReceiveClientHello(certProvider, ns, reader);
                break;

            case EHandshake.ClientKeyExchange:
                ReceiveClientKeyExchange(certProvider, ns, reader);
                break;

            case EHandshake.Finished:
                ReceiveClientFinished(ns, reader);
                break;

            default:
                ns.Send(new HttpsSmsgAlert(ns.Https, 2, 10));
                throw new HttpsException($"sent unknown handshake 0x{handshakeType:X}", reader);
            }
        }
Ejemplo n.º 2
0
        // --- Https Change Cipher Spec ---

        internal void ReceiveChangeCipherSpec(INetState ns, HttpsReader reader)
        {
            byte payload = reader.ReadByte();

            HttpsReader.VerifyLengthRemaining(reader, 0, "ChangeClientSpec");
            if (payload != 0x01)
            {
                throw new HttpsException($"sent ChangeCipherSpec with wrong payload.", reader);
            }
            SessionIdentifier      = _Handshake.SessionIdentifier;
            SequenceNumberReceived = 0;
            SequenceNumberSent     = 0;
            CipherSuite            = _Handshake.CipherSuite;
            _KeyBlock = _Handshake.GetKeyBlock();
            Decryptor = CipherSuite.GetTransform(_KeyBlock.ClientWriteKey);
            Encryptor = CipherSuite.GetTransform(_KeyBlock.ServerWriteKey);
            // DeMAC = CipherSuite.GetMAC(_KeyBlock.ClientWriteMACKey);
            // EnMAC = CipherSuite.GetMAC(_KeyBlock.ServerWriteMACKey);
            IsClientEncrypting = true;
        }