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); }
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 Register(string userName) { var secret = fabric_ca_client.Register(new Hyperledger.Fabric_CA.SDK.Requests.RegistrationRequest(userName, "org1.department1") { EnrollmentID = userName, Type = "client" }, admin); Console.WriteLine("Successfully registered user1 - secret:" + secret); try { var enrollment = fabric_ca_client.Enroll(userName, secret); Console.WriteLine($"Successfully enrolled member user '{userName}' "); string mspid = "Org1MSP"; var newUser = new SampleUser(userName, mspid, new Enrollment() { identity = new Identity() { certificate = enrollment.Cert }, signingIdentity = secret }); string enrollmentFile = Path.Combine(keyStorePath, userName); string pkeyFile = Path.Combine(keyStorePath, secret + "-priv"); var content = Newtonsoft.Json.JsonConvert.SerializeObject(newUser); File.WriteAllText(enrollmentFile, content); File.WriteAllText(pkeyFile, enrollment.Key); var userFolder = Path.Combine(keyStorePath, userName + "_temp"); if (Directory.Exists(userFolder)) { Directory.Delete(userFolder, true); } Directory.CreateDirectory(userFolder); File.Copy(enrollmentFile, Path.Combine(userFolder, userName)); File.Copy(pkeyFile, Path.Combine(userFolder, secret + "-priv")); ZipFile.CreateFromDirectory(userFolder, userFolder.Replace("_temp", ".zip")); } catch (Exception ex) { } }
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(); }
public void TestEnrollmentNullSecret() { HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null); client.Enroll(TEST_ADMIN_NAME, null); }
public void TestEnrollmentNullUser() { HFCAClient client = HFCAClient.Create("client", "http://localhost:99", null); client.Enroll(null, TEST_ADMIN_PW); }