예제 #1
0
        private void HandleHandshake(Record record)
        {
            var handshakeReader = new HandshakeReader(state);
            var handshakeWriter = new HandshakeWriter(state);

            var message = handshakeReader.Read(record);

            switch (message.Type)
            {
                case HandshakeType.ClientHello:
                    state.HandleClientHello((ClientHelloMessage)message);

                    var serverHellos = state.GenerateServerHello();
                    foreach (var hello in serverHellos)
                    {
                        handshakeWriter.Write(hello);
                    }

                    state.SentServerHello();

                    break;
                case HandshakeType.ClientKeyExchange:
                    state.HandleClientKeyExchange((ClientKeyExchangeMessage)message);
                    break;
                case HandshakeType.Finished:
                    HandleHandshakeFinished(message, handshakeWriter);
                    break;
                default:
                    throw new NotImplementedException();
            }
        }
예제 #2
0
        private void HandleHandshakeFinished(HandshakeMessage message, HandshakeWriter handshakeWriter)
        {
            state.VerifyFinished((FinishedHandshakeMessage)message);
            if (state.ConnectionEnd != ConnectionEnd.Server)
            {
                return;
            }

            // send ChangeCipherSpec & Finished

            state.RecordWriter.WriteRecord(new Record(RecordType.ChangeCipherSpec, state.Version, new byte[] { 1 }));
            state.SentChangeCipherSpec();

            handshakeWriter.Write(state.GenerateFinishedMessage());
        }