Example #1
0
        private async Task <Certificate[]> IssueCertificates(string[] attributeKeys)
        {
            Certificate[] certificates = new Certificate[attributeKeys.Length];

            int i = 0;

            foreach (string key in attributeKeys)
            {
                Attribute   attr = SynAck.Id.Attributes[key];
                Certificate cert = new Certificate()
                {
                    OwningAttribute = attr,
                    Revoked         = false,
                    Location        = "CertFor" + attr.Description,
                    Hash            = "HashFor" + attr.Description
                };

                await _certificateFacade.DeployAsync(cert);

                certificates[i] = cert;
                i++;
            }

            return(certificates);
        }
Example #2
0
        /// <summary>
        /// Get object T given the UID.
        /// </summary>
        /// <returns>The object T.</returns>
        /// <param name="UID">UID.</param>
        public override async Task <ID> GetAsync(int UID)
        {
            ID id = await base.GetAsync(UID);

            //if we have a non-empty collection of certificates, then we return
            //because it means that the Attribute was loaded from the identity
            //map
            if (id.Attributes.Count > 0)
            {
                return(id);
            }

            SQLiteConnection conn = await ConnectToTableAsync <IDAttribute>();

            TableQuery <IDAttribute> query = null;
            await Task.Run(() =>
            {
                query = conn
                        .Table <IDAttribute>()
                        .Where(mapping => mapping.IDUID == UID);
            });

            foreach (IDAttribute mapping in query)
            {
                Attribute attr = await _attrMapper.GetAsync(mapping.AttrUID);

                id.AddAttribute(attr);
            }
            conn.Close();
            return(id);
        }
Example #3
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
            };
        }
        public override async Task TestGetAsync()
        {
            await base.TestGetAsync();

            foreach (KeyValuePair <string, Attribute> kV in t.Attributes)
            {
                Assert.True(tRecovered.Attributes.ContainsKey(kV.Key));

                Attribute newAttribute      = tRecovered.GetAttribute(kV.Key);
                Attribute originalAttribute = kV.Value;

                Assert.AreEqual(originalAttribute.UID, newAttribute.UID);
                Assert.AreEqual(originalAttribute.Location, newAttribute.Location);
                Assert.AreEqual(originalAttribute.Hash, newAttribute.Hash);
                Assert.AreEqual(originalAttribute.Description, newAttribute.Description);
                Assert.AreEqual(originalAttribute.Content.ToString(), newAttribute.Content.ToString());

                foreach (KeyValuePair <string, Certificate> kV2 in originalAttribute.Certificates)
                {
                    Assert.True(newAttribute.Certificates.ContainsKey(kV2.Key));

                    Certificate newCertificate      = newAttribute.Certificates[kV2.Key];
                    Certificate originalCertificate = kV2.Value;

                    Assert.AreEqual(originalCertificate.UID, newCertificate.UID);
                    Assert.AreEqual(originalCertificate.Hash, newCertificate.Hash);
                    Assert.AreEqual(originalCertificate.Location, newCertificate.Location);
                    Assert.AreEqual(originalCertificate.OwningAttribute.UID, newCertificate.OwningAttribute.UID);
                    Assert.AreEqual(originalCertificate.Content.ToString(), newCertificate.Content.ToString());
                }
            }
        }
Example #5
0
        public async Task <ID> DeployAsync(ID id)
        {
            FactoryService factory = new FactoryService(Web3, AccountService.PrivateKey, _factoryAddress);

            //Use the provided Factory address to create an ID + IDController
            Event         idCreationEvent   = factory.GetEventReturnIDController();
            HexBigInteger filterAddressFrom =
                await idCreationEvent.CreateFilterAsync(AccountService.GetAccountAddress());

            await factory.CreateIDAsync();

            List <EventLog <ReturnIDControllerEventDTO> > log =
                await idCreationEvent.GetFilterChanges <ReturnIDControllerEventDTO>(filterAddressFrom);

            string controllerAddress       = log[0].Event._controllerAddress;
            IDControllerService idcService =
                new IDControllerService(Web3, AccountService.PrivateKey, controllerAddress);

            id.ControllerAddress = controllerAddress;
            id.Address           = await idcService.GetIDAsyncCall();

            id.Owner = await idcService.OwnerAsyncCall();


            //Add each attribute from the ID model to the ID smart contract
            foreach (string key in id.Attributes.Keys)
            {
                Attribute attribute = id.GetAttribute(key);
                await AddAttributeAsync(id, attribute);
            }
            return(id);
        }
Example #6
0
        private async Task <Attribute> GetAttributeByKey(IDControllerService idcService, byte[] attributeKey)
        {
            string ethAttributeAddress = await idcService.GetAttributeAsyncCall(attributeKey);

            //Get the attribute and add it to the dict
            Attribute attribute = await _attributeFacade.GetAttributeAsync(ethAttributeAddress);

            return(attribute);
        }
        public override void Setup()
        {
            base.Setup();
            /////////////////////
            //Create a dummy ID//
            /////////////////////

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

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

            Attribute age = new Attribute()
            {
                Location    = "3",
                Hash        = "3",
                Content     = new IntContent(24),
                Description = "age"
            };

            _id = new ID();
            _id.AddAttribute(firstname);
            _id.AddAttribute(lastname);
            _id.AddAttribute(age);

            /////////////////////////
            //Create an eth account//
            /////////////////////////
            _privateKey     = "9e6a6bf412ce4e3a91a33c7c0f6d94b3127b8d4f5ed336210a672fe595bf1769";
            _accountService = new AccountService(_privateKey);

            //////////////////////////////////////////////
            //Add to the header and footers dictionaries//
            //////////////////////////////////////////////

            _header.Add("pubkey", _accountService.PublicKey);
            _header.Add("encrypted", "False");
            _payload.Add("idAddr", _id.Address);
        }
Example #8
0
        private async Task SeedID(IServiceProvider sp)
        {
            AccountService     accountService = new AccountService("9e6a6bf412ce4e3a91a33c7c0f6d94b3127b8d4f5ed336210a672fe595bf1769");
            IContentService    contServ       = sp.GetService <IContentService>();
            ICertificateFacade certFacade     = new CertificateFacade(sp.GetService <Web3>(), contServ, accountService);
            IAttributeFacade   attrFacade     = new AttributeFacade(sp.GetService <Web3>(), certFacade, contServ, accountService);
            IIDFacade          idFacade       = new IDFacade(StaticRessources.FactoryContractAddress, sp.GetService <Web3>(), attrFacade, accountService);

            //create some dummy attributes
            Attribute name = new Attribute()
            {
                Hash        = "hash" + "Ephemeris",
                Location    = "Location" + "Ephemeris",
                Content     = new StringContent("Ephemeris"),
                Description = "name"
            };

            Attribute address = new Attribute()
            {
                Location    = "Location" + "2",
                Hash        = "2",
                Content     = new StringContent("31 rue des Pommmiers"),
                Description = "address"
            };

            Attribute phone = new Attribute()
            {
                Location    = "Location" + "3",
                Hash        = "3",
                Content     = new StringContent("555-555-5555"),
                Description = "phone"
            };


            ID id = new ID();

            id.AddAttribute(name);
            id.AddAttribute(address);
            id.AddAttribute(phone);

            try
            {
                id = await idFacade.DeployAsync(id);
            }
            catch (Exception e)
            {
                var o = e;
            }

            await sp.GetService <IMapper <ID> >().SaveAsync(id);
        }
Example #9
0
        public async Task <Certificate> AddCertificateAsync(Attribute attribute, Certificate cert)
        {
            //If the certificate is not deployed, deploy it
            if (cert.Address == null)
            {
                cert = await _certificateFacade.DeployAsync(cert);
            }

            //Add the certificate to the attribute
            AttributeService ethAttribute = new AttributeService(Web3, AccountService.PrivateKey, attribute.Address);
            await ethAttribute.AddCertificateAsync(cert.Address);

            return(cert);
        }
Example #10
0
        public async Task <Attribute> AddAttributeAsync(ID id, Attribute attribute)
        {
            IDControllerService idcService = new IDControllerService(Web3, AccountService.PrivateKey, id.ControllerAddress);

            //If the attribute to be added is not yet deployed, deploy it
            if (attribute.Address == null)
            {
                attribute = await _attributeFacade.DeployAsync(attribute, id.Address);
            }


            await idcService.AddAttributeAsync(attribute.Address);

            return(attribute);
        }
Example #11
0
        public async Task <Attribute> DeployAsync(Attribute attribute, string owner)
        {
            Bytes32TypeEncoder encoder         = new Bytes32TypeEncoder();
            string             transactionHash = await AttributeService.DeployContractAsync(Web3, AccountService.PrivateKey, attribute.Location, encoder.Encode(attribute.Description), attribute.Hash, owner);

            TransactionReceipt receipt = await Web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);

            //Populating the attribute model with the new address
            attribute.Address = receipt.ContractAddress;
            attribute.Owner   = owner;

            //Iterating over certificates and deploying each one
            foreach (string key in attribute.Certificates.Keys)
            {
                Certificate cert = await _certificateFacade.DeployAsync(attribute.Certificates[key]);
                await AddCertificateAsync(attribute, cert);
            }

            return(attribute);
        }
Example #12
0
        public async Task <Dictionary <string, Attribute> > GetAttributesAsync(ID id)
        {
            IDControllerService            idcService = new IDControllerService(Web3, AccountService.PrivateKey, id.ControllerAddress);
            Dictionary <string, Attribute> dict       = new Dictionary <string, Attribute>();

            BigInteger attributes = await idcService.AttributeCountAsyncCall();

            for (BigInteger i = 0; i < attributes; i++)
            {
                //Get all attribute keys and addresses for the ID
                byte[] attributeKey = await idcService.GetAttributeKeyAsyncCall(i);

                //Get the attribute and add it to the dict
                Attribute newAttribute = await GetAttributeByKey(idcService, attributeKey);

                dict.Add(newAttribute.Description, newAttribute);
            }

            return(dict);
        }
Example #13
0
        public async Task <Dictionary <string, Certificate> > GetCertificatesAsync(Attribute attribute)
        {
            Dictionary <string, Certificate> certs = new Dictionary <string, Certificate>();
            AttributeService ethAttribute          = new AttributeService(Web3, AccountService.PrivateKey, attribute.Address);

            //Getting the number of certificates in the attribute
            BigInteger certCount = await ethAttribute.CertificateCountAsyncCall();

            //Getting each certificate and adding it to the returned dictionary
            for (BigInteger i = new BigInteger(0); i < certCount; i++)
            {
                string certKey = await ethAttribute.CertificateKeysAsyncCall(i);

                string certAddress = await ethAttribute.CertificatesAsyncCall(certKey);

                Certificate cert = await _certificateFacade.GetCertificateAsync(certAddress);

                certs.Add(certKey, cert);
            }
            return(certs);
        }
Example #14
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);
        }
Example #15
0
            public async Task <Dictionary <string, Attribute> > GetAttributesAsync(ID id, string[] accessibleAttributes)
            {
                if (accessibleAttributes == null)
                {
                    accessibleAttributes = new string[] { "firstname", "lastname", "cell", "address", "extra" }
                }
                ;

                foreach (string key in accessibleAttributes)
                {
                    Attribute attr = new Attribute()
                    {
                        Address     = "AddressOf" + key,
                        Description = key,
                        Location    = "Location of " + key,
                        Hash        = "Hash of" + key,
                        Content     = new StringContent(key + " content")
                    };

                    id.AddAttribute(attr);
                }

                return(id.Attributes);
            }
Example #16
0
        public async Task <Attribute> GetAttributeAsync(string address)
        {
            AttributeService ethAttribute = new AttributeService(Web3, AccountService.PrivateKey, address);

            byte[] descriptionArr = await ethAttribute.DescriptionAsyncCall();

            string description = Encoding.UTF8.GetString(descriptionArr, 0, descriptionArr.Length);

            description = description.TrimEnd('\0');//remove null characters at the end of string

            //Populating attribute object with values from the smart contract
            Attribute attributeModel = new Attribute
            {
                Address     = address,
                Hash        = await ethAttribute.HashAsyncCall(),
                Location    = await ethAttribute.LocationAsyncCall(),
                Owner       = await ethAttribute.OwnerAsyncCall(),
                Description = description
            };

            //Fetch the content of the attribute
            attributeModel.Content = _contentService.GetContent(attributeModel.Location, attributeModel.Hash);

            //Fetching each certificate and adding them to the attribute
            Dictionary <string, Certificate> certificates = await GetCertificatesAsync(attributeModel);

            foreach (Certificate cert in certificates.Values)
            {
                //replace the OwningAttribute placeholder with a complete instance
                cert.OwningAttribute = attributeModel;
                attributeModel.AddCertificate(cert);
            }


            return(attributeModel);
        }
Example #17
0
        public async Task <Dictionary <string, Attribute> > GetAttributesAsync(ID id, string[] accessibleAttributes)
        {
            IDControllerService            idcService = new IDControllerService(Web3, AccountService.PrivateKey, id.ControllerAddress);
            Dictionary <string, Attribute> dict       = new Dictionary <string, Attribute>();

            BigInteger attributes = await idcService.AttributeCountAsyncCall();

            for (BigInteger i = 0; i < attributes; i++)
            {
                //Get all attribute keys and addresses for the ID
                byte[] attributeKey = await idcService.GetAttributeKeyAsyncCall(i);

                string keyStr = Encoding.UTF8.GetString(attributeKey, 0, attributeKey.Length);
                keyStr = keyStr.TrimEnd('\0');//remove null characters at the end of string
                if (accessibleAttributes.Contains(keyStr))
                {
                    //Get the attribute and add it to the dict
                    Attribute newAttribute = await GetAttributeByKey(idcService, attributeKey);

                    dict.Add(newAttribute.Description, newAttribute);
                }
            }
            return(dict);
        }
Example #18
0
 public async void ViewCertificates(Attribute attrDTO)
 {
     await _navigationService.Navigate <CertificatesViewModel, Attribute>(ID.Attributes[attrDTO.Description]);
 }
Example #19
0
 public async Task <Attribute> DeployAsync(Attribute attribute, string owner)
 {
     throw new NotImplementedException();
 }
Example #20
0
 public async Task <Dictionary <string, Certificate> > GetCertificatesAsync(Attribute attribute)
 {
     throw new NotImplementedException();
 }
Example #21
0
        public virtual async Task Setup()
        {
            //create some dummy attributes
            Attribute firstname = new Attribute()
            {
                Location    = "1",
                Hash        = "1",
                Content     = new StringContent("Olivier"),
                Description = "firstname"
            };

            Certificate firstnameCert = new Certificate()
            {
                Hash            = "hash",
                Location        = "location",
                OwningAttribute = firstname,
                Content         = new StringContent("content"),
                Owner           = "0x123456778"
            };

            firstname.AddCertificate(firstnameCert);

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

            Certificate lastnameCert = new Certificate()
            {
                Hash            = "hash2",
                Location        = "location2",
                OwningAttribute = lastname,
                Content         = new StringContent("content"),
                Owner           = "0x123456778"
            };

            lastname.AddCertificate(lastnameCert);

            Attribute age = new Attribute()
            {
                Location    = "3",
                Hash        = "3",
                Content     = new IntContent(24),
                Description = "age"
            };

            t = new ID();
            t.AddAttribute(firstname);
            t.AddAttribute(lastname);
            t.AddAttribute(age);

            IFile file = await FileSystem.Current.LocalStorage.CreateFileAsync("mydata.db", CreationCollisionOption.ReplaceExisting);

            var path = file.Path;

            Mapper  = new IDMapper(path, new AttributeMapper(path, new ExternalElementMapper <Certificate>(path)));
            Mapper2 = new IDMapper(path, new AttributeMapper(path, new ExternalElementMapper <Certificate>(path)));
        }
Example #22
0
        public void Setup()
        {
            /////////////////////
            //Create a dummy ID//
            /////////////////////

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

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

            Attribute age = new Attribute()
            {
                Location    = "3",
                Hash        = "3",
                Content     = new IntContent(24),
                Description = "age"
            };

            Attribute cell = new Attribute()
            {
                Location    = "4",
                Hash        = "4",
                Content     = new StringContent("555-555-5555"),
                Description = "cell"
            };

            Attribute address = new Attribute()
            {
                Location    = "5",
                Hash        = "5",
                Content     = new StringContent("1 infinite loop, cupertino"),
                Description = "address"
            };

            _id = new ID();
            _id.AddAttribute(firstname);
            _id.AddAttribute(lastname);
            _id.AddAttribute(age);
            _id.AddAttribute(cell);
            _id.AddAttribute(address);
            _id.Address = "0x1234567";

            /////////////////////////
            //Create an eth account//
            /////////////////////////
            _privateKey     = "9e6a6bf412ce4e3a91a33c7c0f6d94b3127b8d4f5ed336210a672fe595bf1769";
            _accountService = new AccountService(_privateKey);

            ////////////////////////
            //Create the ID Facade//
            ////////////////////////
            initWeb3().Wait();
            _certFacade      = new CertificateFacade(_web3, new DummyContentService(), _accountService);
            _attributeFacade = new AttributeFacade(_web3, _certFacade, new DummyContentService(), _accountService);
            _idFacade        = new IDFacade("0x0", _web3, _attributeFacade, _accountService);

            _tokenCryptoService = new TokenCryptoService <IToken>(new SECP256K1CryptoService());
            _requester          = new Requester(_tokenCryptoService, _accountService, _id, _idFacade, _attributeFacade, _certFacade);
        }
Example #23
0
 public Task <Attribute> AddAttributeAsync(ID id, Attribute attribute)
 {
     throw new NotImplementedException();
 }
Example #24
0
 public async Task <Certificate> AddCertificateAsync(Attribute attribute, Certificate cert)
 {
     return(cert);
 }