Search in sources :

Example 1 with HFCAInfo

use of org.hyperledger.fabric_ca.sdk.HFCAInfo in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testGetInfo.

// Tests getting server/ca information
@Test
public void testGetInfo() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        HFCAInfo info = client.info();
        assertNull(info.getVersion());
    }
    if (!testConfig.isRunningAgainstFabric10()) {
        HFCAInfo info = client.info();
        assertNotNull("client.info returned null.", info);
        String version = info.getVersion();
        assertNotNull("client.info.getVersion returned null.", version);
        assertTrue(format("Version '%s' didn't match expected pattern", version), version.matches("^\\d+\\.\\d+\\.\\d+($|-.*)"));
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) HFCAInfo(org.hyperledger.fabric_ca.sdk.HFCAInfo) Test(org.junit.Test)

Example 2 with HFCAInfo

use of org.hyperledger.fabric_ca.sdk.HFCAInfo 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);
    }
}
Also used : EnrollmentRequest(org.hyperledger.fabric_ca.sdk.EnrollmentRequest) Enrollment(org.hyperledger.fabric.sdk.Enrollment) Properties(java.util.Properties) RegistrationRequest(org.hyperledger.fabric_ca.sdk.RegistrationRequest) HFCAClient(org.hyperledger.fabric_ca.sdk.HFCAClient) HFCAInfo(org.hyperledger.fabric_ca.sdk.HFCAInfo)

Example 3 with HFCAInfo

use of org.hyperledger.fabric_ca.sdk.HFCAInfo 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();
}
Also used : HFCAInfo(org.hyperledger.fabric_ca.sdk.HFCAInfo) CAInfo(org.hyperledger.fabric.sdk.NetworkConfig.CAInfo) HFCAClient(org.hyperledger.fabric_ca.sdk.HFCAClient) HFCAInfo(org.hyperledger.fabric_ca.sdk.HFCAInfo) BeforeClass(org.junit.BeforeClass)

Aggregations

HFCAInfo (org.hyperledger.fabric_ca.sdk.HFCAInfo)3 HFCAClient (org.hyperledger.fabric_ca.sdk.HFCAClient)2 Properties (java.util.Properties)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 Enrollment (org.hyperledger.fabric.sdk.Enrollment)1 CAInfo (org.hyperledger.fabric.sdk.NetworkConfig.CAInfo)1 EnrollmentRequest (org.hyperledger.fabric_ca.sdk.EnrollmentRequest)1 RegistrationRequest (org.hyperledger.fabric_ca.sdk.RegistrationRequest)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1