private void SynchronizeCryptoHashMessage(NetworkIncomingMessage message)
        {
            byte[] synchronize = HandshakeCryptoHashMessage.GetHash(keys.Secret);
            int    offset      = Bytes.Find(message.ToBytes(), synchronize);

            byte[]         bytes = message.ToBytes(offset + 20, 20);
            HandshakeMatch match = new HandshakeMatch(keys.Secret, bytes);

            found = context.Hashes.Find(match);

            if (found == null)
            {
                context.OnRejected(new HandshakeRejection(match));
                connection.CallHandshakeRejected();
                connection.Terminate();

                return;
            }

            keys.Local  = new HandshakeKey(HandshakeKeyOwnership.Receiver, keys.Secret, found);
            keys.Remote = new HandshakeKey(HandshakeKeyOwnership.Initiator, keys.Secret, found);

            message.Acknowledge(offset + 40);
            connection.Receive(MeasureCryptoPayloadMessage, HandshakeCryptoPayload.MinimumSize);
        }
        private bool VerifyCryptoHashMessage(NetworkIncomingMessage message)
        {
            byte[] synchronize = HandshakeCryptoHashMessage.GetHash(keys.Secret);
            int    offset      = Bytes.Find(message.ToBytes(), synchronize);

            return(offset >= 0 && message.Length >= offset + 40);
        }
Esempio n. 3
0
 public bool Matches(FileHash hash)
 {
     return(Bytes.Equals(data, HandshakeCryptoHashMessage.GetXor(secret, hash.ToBytes())));
 }