internal IProtocolMessage CreateClientHello() { ClientHello chm = new ClientHello(); m_SecurityParameters.ClientRandom = chm.GetClientRandom(); m_SecurityParameters.ChosenVersion = chm.GetClientVersion(); HandshakeProtocolMessage hpm = new HandshakeProtocolMessage(chm); m_ListOfHandshakeMsgs.Add(hpm); m_HandshakePhase = HandshakeDataType.ClientHello; return(hpm); }
internal IProtocolMessage CreateClientKeyExchange(byte[] encryptedData) { if (m_HandshakePhase != HandshakeDataType.ServerHelloDone) { throw new SslAlertException(AlertLevel.Fatal, AlertDescription.HandshakeFailure); } HandshakeProtocolMessage hpm = new HandshakeProtocolMessage(new ClientKeyExchange(encryptedData)); m_ListOfHandshakeMsgs.Add(hpm); m_HandshakePhase = HandshakeDataType.ClientKeyExchange; return(hpm); }
internal IProtocolMessage CreateFinishedMsg(byte[] masterSecret) { byte[] data = GetAllHandshakeInBytes(); byte[] md5data = (new MD5Managed()).ComputeHash(data); byte[] sha1data = (new SHA1Managed()).ComputeHash(data); PrfDeriveBytes prf = new PrfDeriveBytes(masterSecret, "client finished", ByteArray.Concat(md5data, sha1data)); byte[] result = prf.GetBytes(12); prf.Dispose(); HandshakeProtocolMessage hpm = new HandshakeProtocolMessage(new Finished(result)); m_ListOfHandshakeMsgs.Add(hpm); m_HandshakePhase = HandshakeDataType.Finished; return(hpm); }
private static void CreateHandshakeMessages(byte[] buffer, ExtractMessagesResult result) { int startOffset = 0; int endOffset = startOffset + buffer.Length; while (startOffset < endOffset) { HandshakeDataType type = (HandshakeDataType)buffer[startOffset++]; byte[] len = new byte[4]; System.Buffer.BlockCopy(buffer, startOffset, len, 1, 3); if (BitConverter.IsLittleEndian) { Array.Reverse(len); } int messageLength = (int)(BitConverter.ToUInt32(len, 0)); startOffset += 3; byte[] message = new byte[messageLength]; System.Buffer.BlockCopy(buffer, startOffset, message, 0, message.Length); startOffset += message.Length; HandshakeProtocolMessage hMsg = null; try { hMsg = new HandshakeProtocolMessage(type, message); } catch (Exception) { throw new SslAlertException(AlertLevel.Fatal, AlertDescription.DecodeError); } result.protocolMessages.Add(hMsg); if (type != HandshakeDataType.Finished) { result.handshakeMessages.Add(hMsg); } } }