use of org.hyperledger.fabric_ca.sdk.HFCAClient in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testEnrollUnknownClient.
// Tests enrolling a user to an unknown CA client
@Test
public void testEnrollUnknownClient() throws Exception {
thrown.expect(EnrollmentException.class);
thrown.expectMessage("Failed to enroll user");
CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
// This client does not exist
String clientName = "test CA client";
HFCAClient clientWithName = HFCAClient.createNewInstance(clientName, testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG).getCAProperties());
clientWithName.setCryptoSuite(cryptoSuite);
clientWithName.enroll(admin.getName(), TEST_ADMIN_PW);
}
use of org.hyperledger.fabric_ca.sdk.HFCAClient in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testDeleteAffiliationNotAllowed.
// Tests deleting an affiliation on CA that does not allow affiliation removal
@Test
public void testDeleteAffiliationNotAllowed() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
thrown.expectMessage("Authorization failure");
HFCAClient client2 = HFCAClient.createNewInstance(testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCAProperties());
client2.setCryptoSuite(crypto);
// SampleUser can be any implementation that implements org.hyperledger.fabric.sdk.User Interface
SampleUser admin2 = sampleStore.getMember(TEST_ADMIN_NAME, "org2");
if (!admin2.isEnrolled()) {
// Preregistered admin only needs to be enrolled with Fabric CA.
admin2.setEnrollment(client2.enroll(admin2.getName(), TEST_ADMIN_PW));
}
HFCAAffiliation aff = client2.newHFCAAffiliation("org6");
HFCAAffiliationResp resp = aff.delete(admin2);
assertEquals("Incorrect status code", new Integer(400), new Integer(resp.getStatusCode()));
}
use of org.hyperledger.fabric_ca.sdk.HFCAClient in project fabric-sdk-java by hyperledger.
the class End2endIT method enrollUsersSetup.
/**
* Will register and enroll users persisting them to samplestore.
*
* @param sampleStore
* @throws Exception
*/
public void enrollUsersSetup(SampleStore sampleStore) throws Exception {
for (SampleOrg sampleOrg : testSampleOrgs) {
HFCAClient ca = sampleOrg.getCAClient();
final String orgName = sampleOrg.getName();
final String mspid = sampleOrg.getMSPID();
ca.setCryptoSuite(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.
final EnrollmentRequest enrollmentRequestTLS = new EnrollmentRequest();
enrollmentRequestTLS.addHost("localhost");
enrollmentRequestTLS.setProfile("tls");
final Enrollment enroll = ca.enroll("admin", "adminpw", enrollmentRequestTLS);
final String tlsCertPEM = enroll.getCert();
final String tlsKeyPEM = getPEMStringFromPrivateKey(enroll.getKey());
final Properties tlsProperties = new Properties();
tlsProperties.put("clientKeyBytes", tlsKeyPEM.getBytes(UTF_8));
tlsProperties.put("clientCertBytes", tlsCertPEM.getBytes(UTF_8));
clientTLSProperties.put(sampleOrg.getName(), tlsProperties);
// Save in samplestore for follow on tests.
sampleStore.storeClientPEMTLCertificate(sampleOrg, tlsCertPEM);
sampleStore.storeClientPEMTLSKey(sampleOrg, tlsKeyPEM);
}
// just check if we connect at all.
HFCAInfo info = ca.info();
assertNotNull(info);
String infoName = info.getCAName();
if (infoName != null && !infoName.isEmpty()) {
assertEquals(ca.getCAName(), infoName);
}
SampleUser admin = sampleStore.getMember(TEST_ADMIN_NAME, orgName);
if (!admin.isEnrolled()) {
// Preregistered admin only needs to be enrolled with Fabric caClient.
admin.setEnrollment(ca.enroll(admin.getName(), "adminpw"));
admin.setMspId(mspid);
}
// The admin of this org --
sampleOrg.setAdmin(admin);
SampleUser user = sampleStore.getMember(TESTUSER_1_NAME, sampleOrg.getName());
if (!user.isRegistered()) {
// users need to be registered AND enrolled
RegistrationRequest rr = new RegistrationRequest(user.getName(), "org1.department1");
user.setEnrollmentSecret(ca.register(rr, admin));
}
if (!user.isEnrolled()) {
user.setEnrollment(ca.enroll(user.getName(), user.getEnrollmentSecret()));
user.setMspId(mspid);
}
// Remember user belongs to this Org
sampleOrg.addUser(user);
final String sampleOrgName = sampleOrg.getName();
final String sampleOrgDomainName = sampleOrg.getDomainName();
// src/test/fixture/sdkintegration/e2e-2Orgs/channel/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/
SampleUser peerOrgAdmin = sampleStore.getMember(sampleOrgName + "Admin", sampleOrgName, sampleOrg.getMSPID(), Util.findFileSk(Paths.get(testConfig.getTestChannelPath(), "crypto-config/peerOrganizations/", sampleOrgDomainName, format("/users/Admin@%s/msp/keystore", sampleOrgDomainName)).toFile()), Paths.get(testConfig.getTestChannelPath(), "crypto-config/peerOrganizations/", sampleOrgDomainName, format("/users/Admin@%s/msp/signcerts/Admin@%s-cert.pem", sampleOrgDomainName, sampleOrgDomainName)).toFile());
// A special user that can create channels, join peers and install chaincode
sampleOrg.setPeerAdmin(peerOrgAdmin);
}
}
use of org.hyperledger.fabric_ca.sdk.HFCAClient in project fabric-sdk-java by hyperledger.
the class NetworkConfigIT method doMainSetup.
@BeforeClass
public static void doMainSetup() throws Exception {
out("\n\n\nRUNNING: NetworkConfigIT.\n");
resetConfig();
configHelper.customizeConfig();
// Use the appropriate TLS/non-TLS network config file
networkConfig = NetworkConfig.fromYamlFile(testConfig.getTestNetworkConfigFileYAML());
// Check if we get access to defined CAs!
CAInfo caInfo = networkConfig.getOrganizationInfo("Org1").getCertificateAuthorities().get(0);
HFCAClient hfcaClient = HFCAClient.createNewInstance(caInfo);
assertEquals(hfcaClient.getCAName(), caInfo.getCAName());
// makes actual REST call.
HFCAInfo info = hfcaClient.info();
assertEquals(caInfo.getCAName(), info.getCAName());
// with no caname or the default
caInfo = networkConfig.getOrganizationInfo("Org2").getCertificateAuthorities().get(0);
hfcaClient = HFCAClient.createNewInstance(caInfo);
assertEquals(hfcaClient.getCAName(), caInfo.getCAName());
assertNull(caInfo.getCAName());
// makes actual REST call.
info = hfcaClient.info();
// means default
assertEquals(info.getCAName(), "");
// Ensure the chaincode required for these tests is deployed
deployChaincodeIfRequired();
}
use of org.hyperledger.fabric_ca.sdk.HFCAClient in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testDeleteIdentityNotAllowed.
// Tests deleting an identity on CA that does not allow identity removal
@Test
public void testDeleteIdentityNotAllowed() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
thrown.expectMessage("Identity removal is disabled");
SampleUser user = new SampleUser("testuser5", "org2", sampleStore);
HFCAClient client2 = HFCAClient.createNewInstance(testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCAProperties());
client2.setCryptoSuite(crypto);
// SampleUser can be any implementation that implements org.hyperledger.fabric.sdk.User Interface
SampleUser admin2 = sampleStore.getMember(TEST_ADMIN_NAME, "org2");
if (!admin2.isEnrolled()) {
// Preregistered admin only needs to be enrolled with Fabric CA.
admin2.setEnrollment(client2.enroll(admin.getName(), TEST_ADMIN_PW));
}
HFCAIdentity ident = client2.newHFCAIdentity(user.getName());
ident.create(admin2);
ident.delete(admin2);
}
Aggregations