Beispiel #1
0
        private void HandleSendEncryptionKey(byte[] requester, byte[] requestContent, RouterSocket router,
                                             Guid requesterIdentity)
        {
            if (_encryptionKeys.ContainsKey(requesterIdentity))
            {
                ErrorMessageSender.SendError(requester, router, ErrorCode.EncryptionKeyAlreadySent);
            }

            var encryptionKey = _decryptor.Decrypt(requestContent);

            StoreEncryptionKey(requesterIdentity, JsonConvert.DeserializeObject <EncryptionKey>(encryptionKey));
            var challenge = ChallengeGenerator.Generate(requesterIdentity);
            var solution  = ChallengeSolver.Solve(challenge);

            SaveSolutionForRequester(requesterIdentity, solution);
            SendChallenge(requester, requesterIdentity, router, challenge);
        }
        public bool Negotiate(RequestSocket requestSocket)
        {
            var success = false;

            RequestPublicKey(requestSocket)
            .Just(publicKey =>
            {
                SendEncryptionKey(requestSocket, publicKey);

                GetChallenge(requestSocket)
                .Just(challenge =>
                {
                    var solution = ChallengeSolver.Solve(challenge);
                    SendChallengeResponse(requestSocket, solution);

                    success = GetAcknowledge(requestSocket);
                });
            });

            return(success);
        }