Beispiel #1
0
        /**
         * Helper function to create IdemixSigningIdentity from a file generated by idemixgen go tool
         *
         * @param mspId
         * @return IdemixSigningIdentity object
         * @throws IOException
         * @throws InvalidProtocolBufferException
         */
        private IdemixSigningIdentity CreateIdemixSigningIdentity(string mspId)
        {
            IdemixMSPSignerConfig signerConfig;

            signerConfig = ReadIdemixMSPConfig(Path.Combine(TEST_PATH, mspId, USER_PATH).Locate(), SIGNER_CONFIG);
            Assert.IsNotNull(signerConfig);

            IssuerPublicKey       ipkProto = ReadIdemixIssuerPublicKey(Path.Combine(TEST_PATH, mspId, VERIFIER_PATH).Locate(), IPK_CONFIG);
            IdemixIssuerPublicKey ipkt     = new IdemixIssuerPublicKey(ipkProto);

            Assert.IsTrue(ipkt.Check());

            KeyPair revPk = ReadIdemixRevocationPublicKey(Path.Combine(TEST_PATH, mspId, VERIFIER_PATH).Locate(), REVOCATION_PUBLIC_KEY);

            BIG skt = BIG.FromBytes(signerConfig.Sk.ToByteArray());

            Credential credProto = Credential.Parser.ParseFrom(signerConfig.Cred);

            Assert.IsNotNull(credProto);

            IdemixCredential credt = new IdemixCredential(credProto);

            CredentialRevocationInformation crit = CredentialRevocationInformation.Parser.ParseFrom(signerConfig.CredentialRevocationInformation);

            return(new IdemixSigningIdentity(ipkt, revPk, mspId, skt, credt, crit, signerConfig.OrganizationalUnitIdentifier, (IdemixRoles)signerConfig.Role));
        }
        public IdemixUserStore(string storePath, string mspId)
        {
            this.storePath = storePath;
            this.mspId     = mspId;
            IssuerPublicKey ipkProto = ReadIdemixIssuerPublicKey(Path.Combine(mspId, VERIFIER_PATH + IPK_CONFIG));

            ipk = new IdemixIssuerPublicKey(ipkProto);
            if (!ipk.Check())
            {
                throw new CryptoException("Failed verifying issuer public key.");
            }
        }
        /**
         * Construct an IdemixIssuerPublicKey from a serialized issuer public key
         *
         * @param proto a protobuf representation of an issuer public key
         */
        public IdemixIssuerPublicKey(IssuerPublicKey proto)
        {
            // check for bad input
            if (proto == null)
            {
                throw new ArgumentException("Cannot create IdemixIssuerPublicKey from null input");
            }

            if (proto.HAttrs.Count < proto.AttributeNames.Count)
            {
                throw new ArgumentException("Serialized IPk does not contain enough HAttr values");
            }

            AttributeNames = new string[proto.AttributeNames.Count];
            for (int i = 0; i < proto.AttributeNames.Count; i++)
            {
                AttributeNames[i] = proto.AttributeNames[i];
            }

            HAttrs = new ECP[proto.HAttrs.Count];
            for (int i = 0; i < proto.HAttrs.Count; i++)
            {
                HAttrs[i] = proto.HAttrs[i].ToECP();
            }

            BarG1  = proto.BarG1.ToECP();
            BarG2  = proto.BarG2.ToECP();
            HRand  = proto.HRand.ToECP();
            Hsk    = proto.HSk.ToECP();
            ProofC = BIG.FromBytes(proto.ProofC.ToByteArray());
            ProofS = BIG.FromBytes(proto.ProofS.ToByteArray());
            W      = proto.W.ToECP2();

            // Compute Hash of IdemixIssuerPublicKey
            byte[] serializedIpk = ToProto().ToByteArray();
            Hash = serializedIpk.HashModOrder().ToBytes();
        }
        /**
         * @return A proto version of this issuer public key
         */
        public IssuerPublicKey ToProto()
        {
            IssuerPublicKey ipc = new IssuerPublicKey
            {
                ProofC = ByteString.CopyFrom(ProofC.ToBytes()),
                ProofS = ByteString.CopyFrom(ProofS.ToBytes()),
                W      = W.ToProto(),
                HSk    = Hsk.ToProto(),
                HRand  = HRand.ToProto(),
                Hash   = ByteString.CopyFrom(Hash),
                BarG1  = BarG1.ToProto(),
                BarG2  = BarG2.ToProto()
            };

            foreach (string attributeName in AttributeNames)
            {
                ipc.AttributeNames.Add(attributeName);
            }
            foreach (ECP ecp in HAttrs)
            {
                ipc.HAttrs.Add(ecp.ToProto());
            }
            return(ipc);
        }
Beispiel #5
0
        public static void Setup(TestContext context)
        {
            // Parse crypto material from files
            IdemixMSPSignerConfig signerConfig = null;

            try
            {
                signerConfig = ReadIdemixMSPConfig(Path.Combine(TEST_PATH, MSP1OU1, USER_PATH).Locate(), SIGNER_CONFIG);
            }
            catch (System.Exception e)
            {
                Assert.Fail("Unexpected exception while reading signerconfig: " + e.Message);
            }

            Assert.IsNotNull(signerConfig);

            try
            {
                revocationPk = ReadIdemixRevocationPublicKey(Path.Combine(TEST_PATH, MSP1OU1, VERIFIER_PATH).Locate(), REVOCATION_PUBLIC_KEY);
            }
            catch (System.Exception e)
            {
                Assert.Fail("Unexpected exception while reading revocation public key: " + e.Message);
            }

            Assert.IsNotNull(revocationPk);

            IssuerPublicKey ipkProto = null;

            try
            {
                ipkProto = ReadIdemixIssuerPublicKey(Path.Combine(TEST_PATH, MSP1OU1, VERIFIER_PATH).Locate(), IPK_CONFIG);
            }
            catch (IOException e1)
            {
                Assert.Fail("Unexpected exception while reading revocation public key" + e1.Message);
            }

            ipk = new IdemixIssuerPublicKey(ipkProto);
            Assert.IsTrue(ipk.Check());

            sk = BIG.FromBytes(signerConfig.Sk.ToByteArray());

            Credential credProto = null;

            try
            {
                credProto = Credential.Parser.ParseFrom(signerConfig.Cred);
            }
            catch (InvalidProtocolBufferException)
            {
                Assert.Fail("Could not parse a credential");
            }

            Assert.IsNotNull(credProto);

            cred = new IdemixCredential(credProto);

            try
            {
                cri = CredentialRevocationInformation.Parser.ParseFrom(signerConfig.CredentialRevocationInformation);
            }
            catch (InvalidProtocolBufferException e)
            {
                Assert.Fail("failed to extract cri from signer config: " + e.Message);
            }

            Assert.IsNotNull(cri);

            try
            {
                signingIdentity = new IdemixSigningIdentity(ipk, revocationPk, MSP1OU1, sk, cred, cri, OU1, IdemixRoles.MEMBER);
            }
            catch (System.Exception e) when(e is CryptoException || e is ArgumentException)
            {
                Assert.Fail("Could not create Idemix Signing Identity" + e.Message);
            }

            Assert.IsNotNull(signingIdentity);

            nym = signingIdentity.Pseudonym;

            nymPublic = nym.Nym;

            proof = signingIdentity.Proof;
        }