Search in sources :

Example 1 with CryptoSuite

use of org.hyperledger.fabric.sdk.security.CryptoSuite 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);
}
Also used : CryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) MockHFCAClient(org.hyperledger.fabric_ca.sdk.MockHFCAClient) HFCAClient(org.hyperledger.fabric_ca.sdk.HFCAClient) Test(org.junit.Test)

Example 2 with CryptoSuite

use of org.hyperledger.fabric.sdk.security.CryptoSuite in project fabric-sdk-java by hyperledger.

the class TransactionContextTest method testGetters.

@Test
public void testGetters() throws Exception {
    Channel channel = createTestChannel("channel1");
    User user = hfclient.getUserContext();
    CryptoSuite cryptoSuite = hfclient.getCryptoSuite();
    TransactionContext context = new TransactionContext(channel, user, cryptoSuite);
    // ensure getCryptoPrimitives returns what we passed in to the constructor
    CryptoSuite cryptoPrimitives = context.getCryptoPrimitives();
    Assert.assertEquals(cryptoSuite, cryptoPrimitives);
}
Also used : User(org.hyperledger.fabric.sdk.User) Channel(org.hyperledger.fabric.sdk.Channel) CryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite) Test(org.junit.Test)

Example 3 with CryptoSuite

use of org.hyperledger.fabric.sdk.security.CryptoSuite in project fabric-sdk-java by hyperledger.

the class TransactionContextTest method createTestContext.

// ==========================================================================================
// Helper methods
// ==========================================================================================
private TransactionContext createTestContext() {
    Channel channel = createTestChannel("channel1");
    User user = hfclient.getUserContext();
    CryptoSuite cryptoSuite = hfclient.getCryptoSuite();
    return new TransactionContext(channel, user, cryptoSuite);
}
Also used : User(org.hyperledger.fabric.sdk.User) Channel(org.hyperledger.fabric.sdk.Channel) CryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite)

Example 4 with CryptoSuite

use of org.hyperledger.fabric.sdk.security.CryptoSuite in project fabric-sdk-java by hyperledger.

the class HFCAClientTest method testEnrollmentNoKeyPair.

@Test
public void testEnrollmentNoKeyPair() throws Exception {
    thrown.expect(EnrollmentException.class);
    thrown.expectMessage("Failed to enroll user admin");
    CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
    EnrollmentRequest req = new EnrollmentRequest("profile 1", "label 1", null);
    req.setCSR("abc");
    HFCAClient client = HFCAClient.createNewInstance("client", "http://localhost:99", null);
    client.setCryptoSuite(cryptoSuite);
    client.enroll(TEST_ADMIN_NAME, TEST_ADMIN_NAME, req);
}
Also used : CryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite) Test(org.junit.Test)

Example 5 with CryptoSuite

use of org.hyperledger.fabric.sdk.security.CryptoSuite in project fabric-sdk-java by hyperledger.

the class HFCAClientTest method testEnrollmentNoServerResponse.

// Tests enrollment when no server is available
@Test
public void testEnrollmentNoServerResponse() throws Exception {
    thrown.expect(EnrollmentException.class);
    thrown.expectMessage("Failed to enroll user admin");
    CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
    EnrollmentRequest req = new EnrollmentRequest("profile 1", "label 1", null);
    HFCAClient client = HFCAClient.createNewInstance("client", "http://localhost:99", null);
    client.setCryptoSuite(cryptoSuite);
    client.enroll(TEST_ADMIN_NAME, TEST_ADMIN_NAME, req);
}
Also used : CryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite) Test(org.junit.Test)

Aggregations

CryptoSuite (org.hyperledger.fabric.sdk.security.CryptoSuite)6 Test (org.junit.Test)4 Channel (org.hyperledger.fabric.sdk.Channel)2 User (org.hyperledger.fabric.sdk.User)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 DERSequenceGenerator (org.bouncycastle.asn1.DERSequenceGenerator)1 InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)1 HFCAClient (org.hyperledger.fabric_ca.sdk.HFCAClient)1 MockHFCAClient (org.hyperledger.fabric_ca.sdk.MockHFCAClient)1