private async Task ProcessInfoRequestResponse(string encryptedToken)
        {
            InfoRequestResponse infoRequestResponse = await DecryptAndInstantiateHandshakeToken <InfoRequestResponse>(encryptedToken, Ack.Id);

            VerifyHandshakeTokenIDOwnership(infoRequestResponse);

            ReceivedIDEvent e;

            if (_tokenCryptoService.VerifySignature(infoRequestResponse))
            {
                e = new ReceivedIDEvent()
                {
                    ReceivedID = infoRequestResponse.Id,
                };

                _session.Close();
                HandshakeComplete.Invoke(this, e);
            }
            else
            {
                throw new SignatureDoesntMatchException("The signature was not " +
                                                        "generated by the given " +
                                                        "public Key");
            }
        }
示例#2
0
        public override void Setup()
        {
            base.Setup();

            //create some dummy attributes
            Attribute firstname = new Attribute()
            {
                Location    = "1",
                Hash        = "1",
                Description = "firstname",
                Content     = new StringContent("Olivier")
            };

            Attribute lastname = new Attribute()
            {
                Location    = "2",
                Hash        = "2",
                Description = "lastname",
                Content     = new StringContent("Brochu Dufour")
            };

            Attribute[] AccessibleAttr = new Attribute[] { firstname, lastname };

            IContent name = new StringContent("Olivier");

            _payload.Add("name", JsonConvert.SerializeObject(name));
            _token = new InfoRequestResponse(_header, _payload)
            {
                Id = _id,
                AccessibleAttributes = AccessibleAttr
            };
        }
示例#3
0
        /// <summary>
        /// JSON-Encodes and sends attributes and attribute contents to the requesting service
        /// </summary>
        public void AuthorizeReadRequest(string[] keysOfAttributesToAuthorize)
        {
            Attribute[] authorizedAttr = new Attribute[keysOfAttributesToAuthorize.Length];
            for (int i = 0; i < keysOfAttributesToAuthorize.Length; i++)
            {
                authorizedAttr[i] = _id.Attributes[keysOfAttributesToAuthorize[i]];
            }

            InfoRequestResponse response = new InfoRequestResponse()
            {
                Id                   = _id,
                PublicKey            = _accountService.PublicKey,
                Encrypted            = true,
                AccessibleAttributes = authorizedAttr
            };

            byte[] requesterPubKey = Nethereum.Hex.HexConvertors.Extensions.HexByteConvertorExtensions.HexToByteArray(_infoRequestSynAck.PublicKey);
            _tokenCryptoService.Sign(response, _accountService.GetPrivateKeyAsByteArray());
            string encryptedToken = _tokenCryptoService.Encrypt(response, requesterPubKey, _accountService.GetPrivateKeyAsByteArray());

            _session.Send(encryptedToken);
        }