public void ProcessServerHello(SessionID sid, byte[] serverRandom, ProtocolVersion serverVersion, TlsCipherSuite chosenSuite, TlsCompressionMethod chosenCompMethod) { if (m_HandshakePhase != HandshakeDataType.ClientHello) { throw new SslAlertException(AlertLevel.Fatal, AlertDescription.UnexpectedMessage); } m_Session.Id = sid; m_Session.CompressionMethod = chosenCompMethod; m_Session.IsResumable = false; if (CipherSuites.IsSupported(chosenSuite)) { m_Session.CipherSuite = chosenSuite; m_SecurityParameters.CipherSuite = chosenSuite; } else { throw new SslAlertException(AlertLevel.Fatal, AlertDescription.HandshakeFailure); } /* TODO: Check for wrong version */ if (serverVersion.Major != 3 || serverVersion.Minor != 1) { throw new SslAlertException(AlertLevel.Fatal, AlertDescription.HandshakeFailure); } m_SecurityParameters.ServerRandom = serverRandom; m_HandshakePhase = HandshakeDataType.ServerHello; }
internal static bool IsPresent(TlsCompressionMethod cMethod) { foreach (TlsCompressionMethod method in m_SupportedCompressionMethods) { if (method == cMethod) { return(true); } } return(false); }
public void FillPendingStates(ProtocolVersion chosenVersion, TlsCompressionMethod compMethod, ICryptoTransform encryptor, ICryptoTransform decryptor, KeyedHashAlgorithm clientHasher, KeyedHashAlgorithm serverHasher) { m_PendingReadState.ChosenVersion = chosenVersion; m_PendingWriteState.ChosenVersion = chosenVersion; m_PendingReadState.CryptoTransform = decryptor; m_PendingWriteState.CryptoTransform = encryptor; m_PendingReadState.Hasher = serverHasher; m_PendingWriteState.Hasher = clientHasher; m_PendingReadState.CompressionMethod = m_PendingWriteState.CompressionMethod = compMethod; }
public ServerHello(byte[] buffer) { messageLength = buffer.Length; if (data == null) { data = new byte[messageLength]; Array.Copy(buffer, data, messageLength); } int offset = 0; int length = buffer.Length; version = new ProtocolVersion(buffer, offset); offset += version.Length; length -= version.Length; serverRandom = new byte[RandomUnit.Length]; System.Buffer.BlockCopy(buffer, offset, serverRandom, 0, serverRandom.Length); offset += RandomUnit.Length; length -= RandomUnit.Length; /* Increment 1 byte for length and rt.Data[offset] bytes for size of sid */ int sidLength = (ushort)(buffer[offset]); if (sidLength != 0) { sid = new SessionID(buffer, offset + 1, (ushort)(buffer[offset])); } offset += sidLength + 1; length -= (sidLength + 1); if (BitConverter.IsLittleEndian) { Array.Reverse(buffer, offset, 2); } chosenCipherSuite = (TlsCipherSuite)BitConverter.ToUInt16(buffer, offset); offset += 2; length -= 2; chosenCompressionMethod = (TlsCompressionMethod)buffer[offset]; offset += 1; length -= 1; //TODO: Check for extensions offset += length; }