コード例 #1
0
ファイル: PKIServiceToNode.cs プロジェクト: archie/sesun
        public bool ChallengeResponse(CipheredChallenge response)
        {
            Console.WriteLine("Got ciphered challenge (" + response.Signature
                + ") response from " + response.Sender);

            UserEntry pendingUser = null;

            foreach (UserEntry e in waitingChallenge.Keys)
            {
                if (e.NodeId.Equals(response.Sender))
                {
                    pendingUser = e;
                    break;
                }
            }

            if (pendingUser == null)
                return false;

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            rsa.FromXmlString(pendingUser.PubKey); // load pending user's pubkey

            try
            {
                if (rsa.VerifyData(waitingChallenge[pendingUser].Challenge, "SHA1", response.Signature))
                {
                    Console.WriteLine("Received response matched challenge. " +
                        "(Verified with " + response.Sender + " public key)");

                    if (!IsRegistered(pendingUser.NodeId))
                        userDB.AddFirst(pendingUser);
                    else
                        // update timeout of user ( not implemented )
                        userDB.AddFirst(pendingUser);

                    waitingChallenge.Remove(pendingUser);
                    return true;
                }
            }
            catch (CryptographicException ce)
            {
                Console.WriteLine("Could not confirm challenge for user: "******"\n"
                    + ce.Message);
                waitingChallenge.Remove(pendingUser);
                return false;
            }

            return false;
        }
コード例 #2
0
ファイル: NodePKIHelper.cs プロジェクト: archie/sesun
        public bool Register(UserEntry entryData)
        {
            RemoteAsyncUserRegisterDelegate registerDelegate =
                new RemoteAsyncUserRegisterDelegate(pki.Register);
            byte[] challenge = registerDelegate(entryData);

            if (challenge == null)
                return false; // wasn't allowed to register

            // cipher challenge with private key
            CipheredChallenge cc = new CipheredChallenge();
            cc.Signature = rsa.SignData(challenge, "SHA1");
            cc.Sender = entryData.NodeId;

            // send to pki
            RemoteAsyncUserRegisterChallengeResponseDelegate responseDelegate =
                new RemoteAsyncUserRegisterChallengeResponseDelegate(pki.ChallengeResponse);
            bool result = responseDelegate(cc);

            return result;
        }