Search in sources :

Example 1 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testRevokeNotAuthorized.

@Test
public void testRevokeNotAuthorized() throws Exception {
    thrown.expect(RevocationException.class);
    thrown.expectMessage("Error while revoking the user");
    // See if a normal user can revoke the admin...
    SampleUser user = getEnrolledUser(TEST_ADMIN_ORG);
    client.revoke(user, admin.getName(), "revoke admin");
}
Also used : SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 2 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testMockEnrollNoCert.

@Ignore
@Test
public void testMockEnrollNoCert() throws Exception {
    thrown.expect(EnrollmentException.class);
    thrown.expectMessage("failed enrollment for user");
    MockHFCAClient mockClient = MockHFCAClient.createNewInstance(testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG).getCAProperties());
    mockClient.setCryptoSuite(crypto);
    SampleUser user = getEnrolledUser(TEST_ADMIN_ORG);
    mockClient.setHttpPostResponse("{\"success\":true}");
    mockClient.enroll(user.getName(), user.getEnrollmentSecret());
}
Also used : MockHFCAClient(org.hyperledger.fabric_ca.sdk.MockHFCAClient) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testEnrollSameUser.

@Test
public void testEnrollSameUser() throws Exception {
    // thrown.expect(RevocationException.class);
    // thrown.expectMessage("does not have attribute 'hf.Revoker'");
    // See if a normal user can revoke the admin...
    SampleUser user1 = getEnrolledUser(TEST_ADMIN_ORG);
    File sampleStoreFile = new File(System.getProperty("java.io.tmpdir") + "/HFCSampletest.properties");
    if (sampleStoreFile.exists()) {
        // For testing start fresh
        sampleStoreFile.delete();
    }
    sampleStore = new SampleStore(sampleStoreFile);
    sampleStoreFile.deleteOnExit();
    SampleUser user2 = getEnrolledUser(TEST_ADMIN_ORG);
    // client.revoke(user, admin.getName(), "revoke admin");
    client.enroll(user1.getName(), user2.getEnrollmentSecret());
}
Also used : SampleStore(org.hyperledger.fabric.sdkintegration.SampleStore) File(java.io.File) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 4 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser 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()));
}
Also used : HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) MockHFCAClient(org.hyperledger.fabric_ca.sdk.MockHFCAClient) HFCAClient(org.hyperledger.fabric_ca.sdk.HFCAClient) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 5 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testCertificateRevoke.

// Tests revoking a certificate
@Test
public void testCertificateRevoke() throws Exception {
    SampleUser user = getTestUser(TEST_USER1_ORG);
    if (!user.isRegistered()) {
        RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
        String password = "testUserRevoke";
        rr.setSecret(password);
        rr.addAttribute(new Attribute("user.role", "department lead"));
        rr.addAttribute(new Attribute(HFCAClient.HFCA_ATTRIBUTE_HFREVOKER, "true"));
        // Admin can register other users.
        user.setEnrollmentSecret(client.register(rr, admin));
        if (!user.getEnrollmentSecret().equals(password)) {
            fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
        }
    }
    if (!user.isEnrolled()) {
        EnrollmentRequest req = new EnrollmentRequest(DEFAULT_PROFILE_NAME, "label 2", null);
        req.addHost("example3.ibm.com");
        user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret(), req));
    }
    // verify
    String cert = user.getEnrollment().getCert();
    BufferedInputStream pem = new BufferedInputStream(new ByteArrayInputStream(cert.getBytes()));
    CertificateFactory certFactory = CertificateFactory.getInstance(Config.getConfig().getCertificateFormat());
    X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(pem);
    // get its serial number
    String serial = DatatypeConverter.printHexBinary(certificate.getSerialNumber().toByteArray());
    // get its aki
    // 2.5.29.35 : AuthorityKeyIdentifier
    byte[] extensionValue = certificate.getExtensionValue(Extension.authorityKeyIdentifier.getId());
    ASN1OctetString akiOc = ASN1OctetString.getInstance(extensionValue);
    String aki = DatatypeConverter.printHexBinary(AuthorityKeyIdentifier.getInstance(akiOc.getOctets()).getKeyIdentifier());
    int startedWithRevokes = -1;
    if (!testConfig.isRunningAgainstFabric10()) {
        // prevent clock skewing. make sure we request started with revokes.
        Thread.sleep(1000);
        // one more after we do this revoke.
        startedWithRevokes = getRevokes(null).length;
        // prevent clock skewing. make sure we request started with revokes.
        Thread.sleep(1000);
    }
    // revoke all enrollment of this user
    client.revoke(admin, serial, aki, "revoke certificate");
    if (!testConfig.isRunningAgainstFabric10()) {
        final int newRevokes = getRevokes(null).length;
        assertEquals(format("Expected one more revocation %d, but got %d", startedWithRevokes + 1, newRevokes), startedWithRevokes + 1, newRevokes);
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) EnrollmentRequest(org.hyperledger.fabric_ca.sdk.EnrollmentRequest) Attribute(org.hyperledger.fabric_ca.sdk.Attribute) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) RegistrationRequest(org.hyperledger.fabric_ca.sdk.RegistrationRequest) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Aggregations

SampleUser (org.hyperledger.fabric.sdkintegration.SampleUser)22 Test (org.junit.Test)20 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)9 RegistrationRequest (org.hyperledger.fabric_ca.sdk.RegistrationRequest)9 EnrollmentRequest (org.hyperledger.fabric_ca.sdk.EnrollmentRequest)8 MockHFCAClient (org.hyperledger.fabric_ca.sdk.MockHFCAClient)8 Attribute (org.hyperledger.fabric_ca.sdk.Attribute)7 Enrollment (org.hyperledger.fabric.sdk.Enrollment)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 File (java.io.File)2 SampleStore (org.hyperledger.fabric.sdkintegration.SampleStore)2 HFCAClient (org.hyperledger.fabric_ca.sdk.HFCAClient)2 HFCAIdentity (org.hyperledger.fabric_ca.sdk.HFCAIdentity)2 Ignore (org.junit.Ignore)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 HFCAAffiliation (org.hyperledger.fabric_ca.sdk.HFCAAffiliation)1