private HandshakeMessage ReadFinished(byte[] body) { var prfDigest = _cipherSuitesProvider.ResolvePRFHash(_cipherSuiteConfig.CipherSuite); var hash = _handshakeConfig.ComputeVerification(prfDigest); return(FinishedMessage.Read(body, hash)); }
public bool Verify(FinishedMessage message) { if (_keyConfig.Master is null) { throw new InvalidOperationException("Key config is not initialized"); } var prfDigest = _cipherSuitesProvider.ResolvePRFHash(_cipherSuiteConfig.CipherSuite); var prf = new PRF(prfDigest); var label = _endConfig.End == ConnectionEnd.Server ? "client finished" : "server finished"; var expectedData = prf.Digest(_keyConfig.Master, label, message.VerifyExpectedHash) .Take(FinishedMessage.VerifyDataLength) .ToArray(); return(expectedData.SequenceEqual(message.VerifyActual)); }
public byte[] Compute(byte[] preMasterSecret) { if (_randomConfig.Client is null || _randomConfig.Server is null) { throw new InvalidOperationException("Random config is not initialized"); } var clientRandom = _randomConfig.Client; var serverRandom = _randomConfig.Server; var random = new byte[clientRandom.Length + serverRandom.Length]; Array.Copy(clientRandom, 0, random, 0, clientRandom.Length); Array.Copy(serverRandom, 0, random, clientRandom.Length, serverRandom.Length); var prfDigest = _cipherSuitesProvider.ResolvePRFHash(_cipherSuiteConfig.CipherSuite); var prf = new PRF(prfDigest); return(prf.Digest(preMasterSecret, "master secret", random).Take(48).ToArray()); }