示例#1
0
        /// <summary>
        /// Processes an InfoRequestSynAck containing requested attributes and fires an event
        /// </summary>
        private async Task ProcessInfoRequestSynAck(string encryptedInfoRequestToken)
        {
            InfoRequestSynAck infoRequestSynAck = await base.DecryptAndInstantiateHandshakeToken <InfoRequestSynAck>(encryptedInfoRequestToken, _syn.Id);

            if (infoRequestSynAck.PublicKey != _syn.PublicKey)
            {
                throw new TokenPublicKeyMismatch();
            }

            if (_tokenCryptoService.VerifySignature(infoRequestSynAck))
            {
                _infoRequestSynAck = infoRequestSynAck;

                //this event is fired to display an activity showing the requested attributes
                InfoRequestReceivedEvent e = new InfoRequestReceivedEvent()
                {
                    InfoRequestSynAck = _infoRequestSynAck
                };
                InfoRequestReceived.Invoke(this, e);
            }
            else
            {
                throw new SignatureDoesntMatchException("The signature was not " +
                                                        "generated by the given " +
                                                        "public Key");
            }
        }
        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 };

            string[] reqAttr = new string[] { "firstname", "lastname" };

            IContent name = new StringContent("Olivier");

            _payload.Add("name", JsonConvert.SerializeObject(name));
            _token = new InfoRequestSynAck(_header, _payload)
            {
                Id = _id,
                AccessibleAttributes = AccessibleAttr,
                RequestedAttributes  = reqAttr
            };
        }
        protected override void GenerateAndSendSynAck(Ack ack)
        {
            InfoRequestSynAck infoRequestSynAck = new InfoRequestSynAck()
            {
                Id                   = _id,
                PublicKey            = _accountService.PublicKey,
                Encrypted            = true,
                AccessibleAttributes = _accessibleAttributes,
                RequestedAttributes  = _requestedAttributes
            };

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

            _session.Send(encryptedToken);
        }
示例#4
0
 public override void Prepare(IReceiver parameter)
 {
     _receiver            = parameter;
     _infoRequestSynAck   = parameter.InfoRequestSynAck;
     _requestedAttributes = new List <string>(_infoRequestSynAck.RequestedAttributes);
 }