Exemplo n.º 1
0
        public void TestBadAffiliationNameMultipleDots()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.NewHFCAAffiliation("foo...bar");
        }
Exemplo n.º 2
0
        public void TestReenrollNullUser()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.Reenroll(null);
        }
Exemplo n.º 3
0
        public void TestHFCAIdentityCryptoNull()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = null;
            client.NewHFCAIdentity("testid");
        }
Exemplo n.º 4
0
        public void TestNewInstanceWithName()
        {
            HFCAClient memberServices = HFCAClient.Create("name", "http://localhost:99", null);

            Assert.IsNotNull(memberServices);
            Assert.AreSame(typeof(HFCAClient), memberServices.GetType());
        }
Exemplo n.º 5
0
        public void TestIdemixNullEnrollment()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.IdemixEnroll(null, "idemixMSP");
        }
Exemplo n.º 6
0
        public void TestHFCAIdentityCryptoNull()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = null;
            client.NewHFCAAffiliation("org1");
        }
Exemplo n.º 7
0
        public void TestBadAffiliationNameEndingDot()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.NewHFCAAffiliation("foo.");
        }
Exemplo n.º 8
0
        public void TestHFCAIdentityIDNull()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.NewHFCAAffiliation(null);
        }
Exemplo n.º 9
0
        public void TestRevoke2NullUser()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.Revoke(null, admin.Name, "keyCompromise");
        }
Exemplo n.º 10
0
        public void TestRevoke2NullEnrollment()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.Revoke(admin, (string)null, "keyCompromise");
        }
Exemplo n.º 11
0
        public void TestReenrollNullEnrollment()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            admin.Enrollment   = null;
            client.Reenroll(admin);
        }
Exemplo n.º 12
0
        public void TestNewInstanceWithNameAndProperties()
        {
            Properties testProps      = new Properties();
            HFCAClient memberServices = HFCAClient.Create("name", "http://localhost:99", testProps);

            Assert.IsNotNull(memberServices);
            Assert.AreSame(typeof(HFCAClient), memberServices.GetType());
        }
Exemplo n.º 13
0
        public void DeleteAffiliationNoServer()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            HFCAAffiliation aff = client.NewHFCAAffiliation("neworg1");

            aff.Delete(admin);
        }
Exemplo n.º 14
0
        public void TestSetCryptoSuite()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            CryptoPrimitives testcrypt = new CryptoPrimitives();

            client.CryptoSuite = testcrypt;
            Assert.AreEqual(testcrypt, client.CryptoSuite);
        }
Exemplo n.º 15
0
        public void GetAffiliationNoServerResponse()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            HFCAAffiliation aff = client.NewHFCAAffiliation("neworg1");

            aff.Read(admin);
        }
Exemplo n.º 16
0
        public void TestIdemixWrongEnrollment()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            IEnrollment enrollment = new IdemixEnrollment(null, null, "mspid", null, null, null, "ou", IdemixRoles.MEMBER);

            client.IdemixEnroll(enrollment, "mspid");
        }
Exemplo n.º 17
0
        public void TestAddCAToURL()
        {
            string     url    = "http://localhost:99";
            HFCAClient client = HFCAClient.Create("ca1", url, null);

            client.CryptoSuite = crypto;
            string url2 = client.AddCAToURL(url);

            Assert.AreEqual(url + "?ca=ca1", url2);
        }
Exemplo n.º 18
0
        public void DeleteIdentityNoServerResponse()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;

            HFCAIdentity ident = client.NewHFCAIdentity("testuser1");

            ident.Delete(admin);
        }
Exemplo n.º 19
0
        public void TestRegisterNullRegistrar()
        {
            RegistrationRequest regreq = new RegistrationRequest("name", "affiliation");

            regreq.EnrollmentID = "abc";
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            client.Register(regreq, null);
        }
Exemplo n.º 20
0
        public void TestRevoke1NullUser()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            KeyPair     keypair    = crypto.KeyGen();
            IEnrollment enrollment = new X509Enrollment(keypair, "abc");

            client.Revoke(null, enrollment, "keyCompromise");
        }
Exemplo n.º 21
0
        public void GetCertificateNoServerResponse()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;

            HFCACertificateRequest certReq = client.NewHFCACertificateRequest();

            client.GetHFCACertificates(admin, certReq);
        }
Exemplo n.º 22
0
        public void TestHFCACertificateNewInstance()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            HFCACertificateRequest certReq = client.NewHFCACertificateRequest();

            Assert.IsNotNull(certReq);
            Assert.AreEqual(typeof(HFCACertificateRequest).Name, certReq.GetType().Name);
        }
Exemplo n.º 23
0
        public void TestHFCAIdentityNewInstance()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            HFCAAffiliation aff = client.NewHFCAAffiliation("org1");

            Assert.IsNotNull(aff);
            Assert.AreSame(typeof(HFCAAffiliation), aff.GetType());
        }
Exemplo n.º 24
0
        public void TestHFCAIdentityNewInstance()
        {
            HFCAClient client = HFCAClient.Create("http://localhost:99", null);

            client.CryptoSuite = crypto;
            HFCAIdentity ident = client.NewHFCAIdentity("testid");

            Assert.IsNotNull(ident);
            Assert.AreSame(typeof(HFCAIdentity), ident.GetType());
            Assert.AreEqual(ident.EnrollmentId, "testid");
        }
Exemplo n.º 25
0
        public void TestEnrollmentNoServerResponse()
        {
            ICryptoSuite cryptoSuite = Factory.Instance.GetCryptoSuite();

            EnrollmentRequest req    = new EnrollmentRequest("profile 1", "label 1", null);
            HFCAClient        client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = cryptoSuite;

            client.Enroll(TEST_ADMIN_NAME, TEST_ADMIN_NAME, req);
        }
Exemplo n.º 26
0
        public void TestRegisterNoServerResponse()
        {
            Properties testProps = new Properties();
            HFCAClient client    = HFCAClient.Create("client", "https://localhost:99", testProps);

            CryptoPrimitives testcrypt = new CryptoPrimitives();

            client.CryptoSuite = testcrypt;

            RegistrationRequest regreq = new RegistrationRequest("name", "affiliation");

            client.Register(regreq, admin);
        }
Exemplo n.º 27
0
        public void TestIdemixMissingMSPID()
        {
            HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null);

            client.CryptoSuite = crypto;
            var gen         = new ECKeyPairGenerator();
            var keyGenParam = new KeyGenerationParameters(new SecureRandom(), 256);

            gen.Init(keyGenParam);
            KeyPair     pair       = KeyPair.Create(gen.GenerateKeyPair());
            IEnrollment enrollment = new X509Enrollment(pair, "");

            client.IdemixEnroll(enrollment, null);
        }
        public virtual void CheckConfig()
        {
            Util.COut("\n\n\nRUNNING: {0}.\n", testName);

            //      configHelper.clearConfig();
            TestUtils.TestUtils.ResetConfig();
            configHelper.CustomizeConfig();
            //      Assert.AreEqual(256, Config.getConfig().getSecurityLevel());

            testSampleOrgs = testConfig.GetIntegrationTestsSampleOrgs();
            //Set up hfca for each sample org

            foreach (SampleOrg sampleOrg in testSampleOrgs)
            {
                string caURL = sampleOrg.CALocation;
                sampleOrg.CAClient = HFCAClient.Create(caURL, null);
            }
        }
Exemplo n.º 29
0
        public void TestTLSTrustedCertProperites()
        {
            Properties testprops = new Properties();

            testprops.Set("pemFile", "fixture/testPems/caBundled.pems".Locate() + "," + // has 3 certs
                          "fixture/testPems/Org1MSP_CA.pem".Locate());                  // has 1

            testprops.Set("pemBytes", File.ReadAllText("fixture/testPems/Org2MSP_CA.pem".Locate()));

            CryptoPrimitives cpto = new CryptoPrimitives();

            cpto.Init();

            HFCAClient client = HFCAClient.Create("client", "https://localhost:99", testprops);

            client.CryptoSuite = cpto;
            client.SetUpSSL();
            int               count      = 0;
            KeyStore          trustStore = client.CryptoSuite.Store;
            List <BigInteger> expected   = new List <BigInteger>
            {
                new BigInteger("4804555946196630157804911090140692961"),
                new BigInteger("127556113420528788056877188419421545986539833585"),
                new BigInteger("704500179517916368023344392810322275871763581896"),
                new BigInteger("70307443136265237483967001545015671922421894552"),
                new BigInteger("276393268186007733552859577416965113792")
            };

            foreach (X509Certificate2 cert in trustStore.Certificates.Select(a => a.X509Certificate2))
            {
                BigInteger serialNumber = new BigInteger(cert.SerialNumber.FromHexString());
                Assert.IsTrue(expected.Contains(serialNumber), $"Missing certifiate with serial no. {serialNumber}");
                ++count;
            }

            Assert.AreEqual(expected.Count, count, "Number of CA certificates mismatch");
        }
Exemplo n.º 30
0
        public static void doMainSetup(TestContext context)
        {
            Util.COut("\n\n\nRUNNING: NetworkConfigIT.\n");

            TestUtils.TestUtils.ResetConfig();
            configHelper.CustomizeConfig();

            // Use the appropriate TLS/non-TLS network config file
            networkConfig = NetworkConfig.FromYamlFile(testConfig.GetTestNetworkConfigFileYAML());

            networkConfig.OrdererNames.ForEach(ordererName =>
            {
                try
                {
                    Properties ordererProperties = networkConfig.GetOrdererProperties(ordererName);
                    Properties testProp          = testConfig.GetEndPointProperties("orderer", ordererName);
                    ordererProperties.Set("clientCertFile", testProp.Get("clientCertFile"));
                    ordererProperties.Set("clientKeyFile", testProp.Get("clientKeyFile"));
                    networkConfig.SetOrdererProperties(ordererName, ordererProperties);
                }
                catch (ArgumentException e)
                {
                    throw new System.Exception(e.Message, e);
                }
            });

            networkConfig.PeerNames.ForEach(peerName =>
            {
                try
                {
                    Properties peerProperties = networkConfig.GetPeerProperties(peerName);
                    Properties testProp       = testConfig.GetEndPointProperties("peer", peerName);
                    peerProperties.Set("clientCertFile", testProp.Get("clientCertFile"));
                    peerProperties.Set("clientKeyFile", testProp.Get("clientKeyFile"));
                    networkConfig.SetPeerProperties(peerName, peerProperties);
                }
                catch (ArgumentException e)
                {
                    throw new System.Exception(e.Message, e);
                }
            });

            networkConfig.EventHubNames.ForEach(eventhubName =>
            {
                try
                {
                    Properties eventHubsProperties = networkConfig.GetEventHubsProperties(eventhubName);
                    Properties testProp            = testConfig.GetEndPointProperties("peer", eventhubName);
                    eventHubsProperties.Set("clientCertFile", testProp.Get("clientCertFile"));
                    eventHubsProperties.Set("clientKeyFile", testProp.Get("clientKeyFile"));
                    networkConfig.SetEventHubProperties(eventhubName, eventHubsProperties);
                }
                catch (ArgumentException e)
                {
                    throw new System.Exception(e.Message, e);
                }
            });

            //Check if we get access to defined CAs!
            NetworkConfig.OrgInfo org    = networkConfig.GetOrganizationInfo("Org1");
            NetworkConfig.CAInfo  caInfo = org.CertificateAuthorities[0];

            HFCAClient hfcaClient = HFCAClient.Create(caInfo);

            Assert.AreEqual(hfcaClient.CAName, caInfo.CAName);
            HFCAInfo info = hfcaClient.Info(); //makes actual REST call.

            Assert.AreEqual(caInfo.CAName, info.CAName);

            List <NetworkConfig.UserInfo> registrars = caInfo.Registrars;

            Assert.IsTrue(registrars.Count > 0);
            NetworkConfig.UserInfo registrar = registrars.First();
            registrar.Enrollment = hfcaClient.Enroll(registrar.Name, registrar.EnrollSecret);
            TestUtils.TestUtils.MockUser mockuser = TestUtils.TestUtils.GetMockUser(org.Name + "_mock_" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), registrar.MspId);
            RegistrationRequest          rr       = new RegistrationRequest(mockuser.Name, "org1.department1");

            mockuser.EnrollmentSecret = hfcaClient.Register(rr, registrar);
            mockuser.Enrollment       = hfcaClient.Enroll(mockuser.Name, mockuser.EnrollmentSecret);
            orgRegisteredUsers.Add(org.Name, mockuser);

            org    = networkConfig.GetOrganizationInfo("Org2");
            caInfo = org.CertificateAuthorities[0];

            hfcaClient = HFCAClient.Create(caInfo);
            Assert.AreEqual(hfcaClient.CAName, caInfo.CAName);
            info = hfcaClient.Info(); //makes actual REST call.
            Assert.AreEqual(info.CAName, "");

            registrars = caInfo.Registrars;
            Assert.IsTrue(registrars.Count > 0);
            registrar            = registrars.First();
            registrar.Enrollment = hfcaClient.Enroll(registrar.Name, registrar.EnrollSecret);
            mockuser             = TestUtils.TestUtils.GetMockUser(org.Name + "_mock_" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), registrar.MspId);
            rr = new RegistrationRequest(mockuser.Name, "org1.department1");
            mockuser.EnrollmentSecret = hfcaClient.Register(rr, registrar);
            mockuser.Enrollment       = hfcaClient.Enroll(mockuser.Name, mockuser.EnrollmentSecret);
            orgRegisteredUsers.Add(org.Name, mockuser);

            DeployChaincodeIfRequired();
        }