예제 #1
0
        public void EnrollIdemixUser(SampleStore sampleStore)
        {
            foreach (SampleOrg sampleOrg in testSampleOrgs)
            {
                HFCAClient ca = sampleOrg.CAClient;

                string orgName = sampleOrg.Name;
                string mspid   = sampleOrg.MSPID;
                ca.CryptoSuite = Factory.GetCryptoSuite();

                if (testConfig.IsRunningFabricTLS())
                {
                    //This shows how to get a client TLS certificate from Fabric CA
                    // we will use one client TLS certificate for orderer peers etc.
                    EnrollmentRequest enrollmentRequestTLS = new EnrollmentRequest();
                    enrollmentRequestTLS.AddHost("localhost");
                    enrollmentRequestTLS.Profile = "tls";
                    IEnrollment enroll     = ca.Enroll("admin", "adminpw", enrollmentRequestTLS);
                    string      tlsCertPEM = enroll.Cert;
                    string      tlsKeyPEM  = enroll.Key;

                    Properties tlsProperties = new Properties();

                    tlsProperties["clientKeyBytes"]  = tlsKeyPEM;
                    tlsProperties["clientCertBytes"] = tlsCertPEM;

                    clientTLSProperties[sampleOrg.Name] = tlsProperties;
                    //Save in samplestore for follow on tests.
                    sampleStore.StoreClientPEMTLCertificate(sampleOrg, tlsCertPEM);
                    sampleStore.StoreClientPEMTLSKey(sampleOrg, tlsKeyPEM);
                }

                HFCAInfo info = ca.Info(); //just check if we connect at all.
                Assert.IsNotNull(info);
                string infoName = info.CAName;
                if (infoName != null && infoName.Length > 0)
                {
                    Assert.AreEqual(ca.CAName, infoName);
                }

                SampleUser admin      = sampleStore.GetMember(TEST_ADMIN_NAME, orgName);
                SampleUser idemixUser = sampleStore.GetMember(testUser1, sampleOrg.Name);



                EnrollIdemixUser(sampleOrg, idemixUser, admin);
                sampleOrg.AddUser(idemixUser);
            }
        }
        public void TestEnrollReqToJsonAttrNotThere()
        {
            EnrollmentRequest testEnrollReq = new EnrollmentRequest();

            testEnrollReq.AddHost("d.com");
            testEnrollReq.CSR     = csr;
            testEnrollReq.Profile = profile;
            testEnrollReq.Label   = label;
            testEnrollReq.KeyPair = null;
            testEnrollReq.CAName  = caName;

            string s = testEnrollReq.ToJson();

            Assert.IsNotNull(s);
            Assert.IsFalse(s.Contains("\"attr_reqs\":["));
        }
        public void TestEnrollReqToJsonAttrEmpty()
        {
            EnrollmentRequest testEnrollReq = new EnrollmentRequest();

            testEnrollReq.AddHost("d.com");
            testEnrollReq.CSR     = csr;
            testEnrollReq.Profile = profile;
            testEnrollReq.Label   = label;
            testEnrollReq.KeyPair = null;
            testEnrollReq.CAName  = caName;
            testEnrollReq.AddAttrReq(); // means empty. force no attributes.

            string s = testEnrollReq.ToJson();

            Assert.IsNotNull(s);
            Assert.IsTrue(s.Contains("\"attr_reqs\":[]") || !s.Contains("\"attr_reqs\""));
        }
        public void TestEnrollReqToJson()
        {
            try
            {
                EnrollmentRequest testEnrollReq = new EnrollmentRequest();
                testEnrollReq.AddHost("d.com");
                testEnrollReq.CSR     = csr;
                testEnrollReq.Profile = profile;
                testEnrollReq.Label   = label;
                testEnrollReq.KeyPair = null;
                testEnrollReq.CAName  = caName;

                Assert.IsTrue(testEnrollReq.ToJson().Contains(csr));
            }
            catch (System.Exception e)
            {
                Assert.Fail($"Unexpected Exception {e.Message}");
            }
        }
        public void TestEnrollReqToJsonAttr()
        {
            EnrollmentRequest testEnrollReq = new EnrollmentRequest();

            testEnrollReq.AddHost("d.com");
            testEnrollReq.CSR     = csr;
            testEnrollReq.Profile = profile;
            testEnrollReq.Label   = label;
            testEnrollReq.KeyPair = null;
            testEnrollReq.CAName  = caName;
            testEnrollReq.AddAttrReq("foo");
            testEnrollReq.AddAttrReq("foorequired").SetOptional(false);
            testEnrollReq.AddAttrReq("foofalse").SetOptional(true);

            string s = testEnrollReq.ToJson();

            Assert.IsNotNull(s);
            Console.WriteLine(s);
            Assert.IsTrue(s.Contains("\"attr_reqs\":["));
            Assert.IsTrue(s.Contains("\"name\":\"foorequired\",\"optional\":false"));
            Assert.IsTrue(s.Contains("\"name\":\"foofalse\",\"optional\":true"));
        }
 public void TestEnrollReqSetGet()
 {
     try
     {
         EnrollmentRequest testEnrollReq = new EnrollmentRequest();
         testEnrollReq.AddHost("d.com");
         // set csr
         testEnrollReq.CSR     = csr;
         testEnrollReq.Profile = profile;
         testEnrollReq.Label   = label;
         testEnrollReq.KeyPair = null;
         testEnrollReq.CAName  = caName;
         Assert.AreEqual(testEnrollReq.CSR, csr);
         Assert.IsTrue(testEnrollReq.Hosts.Contains("d.com"));
         Assert.AreEqual(testEnrollReq.Profile, profile);
         Assert.AreEqual(testEnrollReq.Label, label);
         Assert.IsNull(testEnrollReq.KeyPair);
     }
     catch (System.Exception e)
     {
         Assert.Fail($"Unexpected Exception {e.Message}");
     }
 }