public static void ServerServerFinish(TlsConnection connection) { Log.Success("ServerServerFinish", "Finished the transaction!"); var sha256 = SHA256.Create(); var handshakeHash = sha256.ComputeHash(connection.HandshakeMessages.ToArray()); var prfClient = new PseudoRandomFunction(connection.MasterSecretBytes, "server finished", handshakeHash); byte[] servVerData = prfClient.GenerateBytes(12); TlsResponse.Handshake(connection, 20, ref servVerData); }
public void InitCipher() { byte[] preMasterSecretBytes = PreMasterSecret.ToByteArrayUnsigned(); var prf = new PseudoRandomFunction(preMasterSecretBytes, "master secret", ClientRandom.Concat(ServerRandom)); MasterSecretBytes = prf.GenerateBytes(48); prf = new PseudoRandomFunction(MasterSecretBytes, "key expansion", ServerRandom.Concat(ClientRandom)); byte[] keyBlock = prf.GenerateBytes(72); using (var memoryStream = new MemoryStream(keyBlock)) { using (var reader = new BinaryReader(memoryStream)) { ClientWriteMacKey = reader.ReadBytes(20); ServerWriteMacKey = reader.ReadBytes(20); ClientWriteKey = reader.ReadBytes(16); ServerWriteKey = reader.ReadBytes(16); } } }
public static void ClientFinish(TlsConnection connection, int length) { Log.Success("ClientFinish", "Finished transaction!"); var sha256 = SHA256.Create(); var handshakeData = connection.HandshakeMessages.GetRange(0, connection.HandshakeMessages.Count - length - 4).ToArray(); var handshakeHash = sha256.ComputeHash(handshakeData); var prfClient = new PseudoRandomFunction(connection.MasterSecretBytes, "client finished", handshakeHash); byte[] clientVerifyData = prfClient.GenerateBytes(12); byte[] data = connection.Buffer.Read(12); for (uint i = 0; i < 12; i++) { if (clientVerifyData[i] != data[i]) { return; } } HandshakeResponse.ServerChangeCipherSpec(connection); connection.SendEncrypted = true; HandshakeResponse.ServerServerFinish(connection); }