use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project groovity by disney.
the class KeyPairValueHandler method doStore.
@Override
protected void doStore(OutputStream stream, String contentType, Object value, @SuppressWarnings("rawtypes") Map config) throws Exception {
Writer writer = new OutputStreamWriter(stream, getCharset(contentType));
PemWriter pemWriter = new PemWriter(writer);
if (config != null && config.containsKey(PASSWORD)) {
PEMEncryptor penc = (new JcePEMEncryptorBuilder(PEM_ENCRYPTION_ALGORITHM)).build(config.get(PASSWORD).toString().toCharArray());
pemWriter.writeObject(new JcaMiscPEMGenerator(value, penc));
} else {
pemWriter.writeObject(new JcaMiscPEMGenerator(value));
}
pemWriter.close();
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project groovity by disney.
the class PublicKeyValueHandler method doStore.
@Override
protected void doStore(OutputStream stream, String contentType, Object value, @SuppressWarnings("rawtypes") Map config) throws Exception {
Writer writer = new OutputStreamWriter(stream, getCharset(contentType));
PemWriter pemWriter = new PemWriter(writer);
pemWriter.writeObject(new JcaMiscPEMGenerator(value));
pemWriter.close();
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project nifi-minifi by apache.
the class NiFiRestConfigurationProviderSecureTest method initCertificates.
/**
* Generates certificates with the tls-toolkit and then starts up the docker compose file
*/
@BeforeClass
public static void initCertificates() throws Exception {
certificatesDirectory = Paths.get(NiFiRestConfigurationProviderSecureTest.class.getClassLoader().getResource("docker-compose-NiFiRestConfigurationProviderSecureTest.yml").getFile()).getParent().toAbsolutePath().resolve("certificates-NiFiRestConfigurationProviderSecureTest");
trustSslContext = initCertificates(certificatesDirectory, Arrays.asList("c2", "mocknifi"));
healthCheckSocketFactory = trustSslContext.getSocketFactory();
KeyStore mockNiFiKeyStore = KeyStore.getInstance("JKS");
try (InputStream inputStream = Files.newInputStream(certificatesDirectory.resolve("mocknifi").resolve("keystore.jks"))) {
mockNiFiKeyStore.load(inputStream, "badKeystorePass".toCharArray());
}
try (PemWriter pemWriter = new PemWriter(new OutputStreamWriter(Files.newOutputStream(certificatesDirectory.resolve("mocknifi").resolve("cert.pem"))))) {
pemWriter.writeObject(new JcaMiscPEMGenerator(mockNiFiKeyStore.getKey(TlsToolkitStandalone.NIFI_KEY, "badKeyPass".toCharArray())));
for (Certificate certificate : mockNiFiKeyStore.getCertificateChain(TlsToolkitStandalone.NIFI_KEY)) {
pemWriter.writeObject(new JcaMiscPEMGenerator(certificate));
}
}
KeyStore mockNiFiTrustStore = KeyStore.getInstance("JKS");
try (InputStream inputStream = Files.newInputStream(certificatesDirectory.resolve("mocknifi").resolve("truststore.jks"))) {
mockNiFiTrustStore.load(inputStream, "badTrustPass".toCharArray());
}
try (PemWriter pemWriter = new PemWriter(new OutputStreamWriter(Files.newOutputStream(certificatesDirectory.resolve("mocknifi").resolve("ca.pem"))))) {
pemWriter.writeObject(new JcaMiscPEMGenerator(mockNiFiTrustStore.getCertificate(TlsToolkitStandalone.NIFI_CERT)));
}
docker.before();
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project dcos-commons by mesosphere.
the class PEMUtils method toPEM.
public static byte[] toPEM(PKCS10CertificationRequest csr) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
PemWriter pemWriter = new PemWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
try {
pemWriter.writeObject(new JcaMiscPEMGenerator(csr));
pemWriter.flush();
} finally {
pemWriter.close();
}
return os.toByteArray();
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project dcos-commons by mesosphere.
the class PEMUtils method toPEM.
public static String toPEM(PrivateKey privateKey) throws IOException {
StringWriter stringWriter = new StringWriter();
PemWriter pemWriter = new PemWriter(stringWriter);
try {
pemWriter.writeObject(new JcaMiscPEMGenerator(privateKey));
pemWriter.flush();
} finally {
pemWriter.close();
}
return stringWriter.toString();
}
Aggregations