use of org.hyperledger.fabric.sdk.security.CryptoPrimitives in project fabric-sdk-java by hyperledger.
the class HFCAClientTest method testSetCryptoSuite.
@Test
public void testSetCryptoSuite() throws Exception {
HFCAClient client = HFCAClient.createNewInstance("client", "http://localhost:99", null);
CryptoPrimitives testcrypt = new CryptoPrimitives();
client.setCryptoSuite(testcrypt);
Assert.assertEquals(testcrypt, client.getCryptoSuite());
}
use of org.hyperledger.fabric.sdk.security.CryptoPrimitives in project fabric-sdk-java by hyperledger.
the class HFCAClientTest method testRegisterNoServerResponse.
@Test
public void testRegisterNoServerResponse() throws Exception {
thrown.expect(RegistrationException.class);
thrown.expectMessage("Error while registering the user");
Properties testProps = new Properties();
HFCAClient client = HFCAClient.createNewInstance("client", "https://localhost:99", testProps);
CryptoPrimitives testcrypt = new CryptoPrimitives();
client.setCryptoSuite(testcrypt);
RegistrationRequest regreq = new RegistrationRequest("name", "affiliation");
client.register(regreq, admin);
}
use of org.hyperledger.fabric.sdk.security.CryptoPrimitives in project fabric-sdk-java by hyperledger.
the class HFCAClient method setUpSSL.
private void setUpSSL() throws InvalidArgumentException {
if (cryptoPrimitives == null) {
try {
cryptoPrimitives = new CryptoPrimitives();
cryptoPrimitives.init();
} catch (Exception e) {
throw new InvalidArgumentException(e);
}
}
if (isSSL && null == registry) {
if (properties.containsKey("pemBytes") && properties.containsKey("pemFile")) {
throw new InvalidArgumentException("Properties can not have both \"pemBytes\" and \"pemFile\" specified. ");
}
try {
if (properties.containsKey("pemBytes")) {
byte[] pemBytes = (byte[]) properties.get("pemBytes");
cryptoPrimitives.addCACertificateToTrustStore(pemBytes, pemBytes.toString());
} else {
String pemFile = properties.getProperty("pemFile");
if (pemFile != null) {
cryptoPrimitives.addCACertificateToTrustStore(new File(pemFile), pemFile);
}
}
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(cryptoPrimitives.getTrustStore(), null).build();
ConnectionSocketFactory sf;
if (null != properties && "true".equals(properties.getProperty("allowAllHostNames"))) {
AllHostsSSLSocketFactory msf = new AllHostsSSLSocketFactory(cryptoPrimitives.getTrustStore());
msf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
sf = msf;
} else {
sf = new SSLConnectionSocketFactory(sslContext);
}
registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", sf).register("http", new PlainConnectionSocketFactory()).build();
} catch (Exception e) {
logger.error(e);
throw new InvalidArgumentException(e);
}
}
}
use of org.hyperledger.fabric.sdk.security.CryptoPrimitives in project fabric-sdk-java by hyperledger.
the class ProtoUtils method getSignatureHeaderAsByteString.
public static ByteString getSignatureHeaderAsByteString(User user, TransactionContext transactionContext) {
final Identities.SerializedIdentity identity = ProtoUtils.createSerializedIdentity(user);
if (isDebugLevel) {
String cert = user.getEnrollment().getCert();
if (null == suite) {
try {
suite = CryptoSuite.Factory.getCryptoSuite();
} catch (Exception e) {
// best try.
}
}
if (null != suite && suite instanceof CryptoPrimitives) {
CryptoPrimitives cp = (CryptoPrimitives) suite;
byte[] der = cp.certificateToDER(cert);
if (null != der && der.length > 0) {
cert = toHexString(suite.hash(der));
}
}
logger.debug(format("SignatureHeader: nonce: %s, User:%s, MSPID: %s, idBytes: %s", toHexString(transactionContext.getNonce()), user.getName(), identity.getMspid(), cert));
}
return SignatureHeader.newBuilder().setCreator(identity.toByteString()).setNonce(transactionContext.getNonce()).build().toByteString();
}
use of org.hyperledger.fabric.sdk.security.CryptoPrimitives in project fabric-sdk-java by hyperledger.
the class HFCAAffiliationTest method setupBeforeClass.
@BeforeClass
public static void setupBeforeClass() {
try {
crypto = new CryptoPrimitives();
crypto.init();
} catch (Exception e) {
throw new RuntimeException("HFCAAffiliationTest.setupBeforeClass failed!", e);
}
}
Aggregations