Ejemplo n.º 1
0
 private ServerHello(HandshakeRandom random,
                     Cipher cipher,
                     SessionId sessionId,
                     MemoryBuffer payload)
 {
     Random    = random;
     Cipher    = cipher;
     SessionId = sessionId;
     Payload   = payload;
 }
Ejemplo n.º 2
0
 private ClientHello(HandshakeRandom random,
                     CipherSuite cipherSuite,
                     SessionId sessionId,
                     MemoryBuffer payload)
 {
     Random      = random;
     CipherSuite = cipherSuite;
     SessionId   = sessionId;
     Payload     = payload;
 }
Ejemplo n.º 3
0
        public static CursorHandshakeWritingContext StartWriting(MemoryCursor cursor,
                                                                 HandshakeRandom random,
                                                                 Cipher cipher,
                                                                 SessionId sessionId)
        {
            HandshakeType.ServerHello.WriteBytes(cursor);

            var payloadContext = HandshakeLength.StartWriting(cursor);

            ProtocolVersion.Tls12.WriteBytes(cursor);
            random.WriteBytes(cursor);
            sessionId.WriteBytes(cursor);
            cipher.WriteBytes(cursor);
            CompressionMethod.WriteEmptyValue(cursor);

            var extensionsContext = ByteVector.StartVectorWriting(cursor, 0..ushort.MaxValue);

            return(new CursorHandshakeWritingContext(payloadContext, extensionsContext));
        }
Ejemplo n.º 4
0
        public static CursorHandshakeWritingContext StartWriting(MemoryCursor cursor,
                                                                 HandshakeRandom random,
                                                                 ReadOnlyMemory <Cipher> ciphers,
                                                                 SessionId sessionId)
        {
            HandshakeType.ClientHello.WriteBytes(cursor);

            var payloadContext = HandshakeLength.StartWriting(cursor);

            ProtocolVersion.Tls12.WriteBytes(cursor);
            random.WriteBytes(cursor);
            sessionId.WriteBytes(cursor);
            CipherSuite.Write(cursor, ciphers);
            CompressionMethod.WriteEmptyList(cursor);

            var extensionsContext = ByteVector.StartVectorWriting(cursor, 0..ushort.MaxValue);

            return(new CursorHandshakeWritingContext(payloadContext, extensionsContext));
        }
Ejemplo n.º 5
0
        public static bool TryParse(MemoryCursor cursor, out ServerHello result)
        {
            result = new ServerHello();

            if (!HandshakeType.TrySlice(cursor, HandshakeType.ServerHello))
            {
                return(false);
            }

            using (HandshakeLength.SliceBytes(cursor).SetCursor(cursor))
            {
                if (!ProtocolVersion.TrySlice(cursor, ProtocolVersion.Tls12))
                {
                    throw new EncodingException();
                }

                var random    = HandshakeRandom.Parse(cursor);
                var sessionId = SessionId.Parse(cursor);
                var cipher    = Cipher.Parse(cursor);

                if (!CompressionMethod.TrySliceEmptyValue(cursor))
                {
                    throw new EncodingException();
                }

                var payload = ByteVector.SliceVectorBytes(cursor, 0..ushort.MaxValue);

                if (!cursor.IsEnd())
                {
                    throw new EncodingException();
                }

                result = new ServerHello(random, cipher, sessionId, payload);

                return(true);
            }
        }