Search in sources :

Example 1 with JcaMiscPEMGenerator

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();
}
Also used : PEMEncryptor(org.bouncycastle.openssl.PEMEncryptor) JcaMiscPEMGenerator(org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator) PemWriter(org.bouncycastle.util.io.pem.PemWriter) OutputStreamWriter(java.io.OutputStreamWriter) JcePEMEncryptorBuilder(org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder) PemWriter(org.bouncycastle.util.io.pem.PemWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with JcaMiscPEMGenerator

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();
}
Also used : JcaMiscPEMGenerator(org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator) PemWriter(org.bouncycastle.util.io.pem.PemWriter) OutputStreamWriter(java.io.OutputStreamWriter) PemWriter(org.bouncycastle.util.io.pem.PemWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 3 with JcaMiscPEMGenerator

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();
}
Also used : JcaMiscPEMGenerator(org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator) PemWriter(org.bouncycastle.util.io.pem.PemWriter) InputStream(java.io.InputStream) OutputStreamWriter(java.io.OutputStreamWriter) KeyStore(java.security.KeyStore) Certificate(java.security.cert.Certificate) BeforeClass(org.junit.BeforeClass)

Example 4 with JcaMiscPEMGenerator

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();
}
Also used : JcaMiscPEMGenerator(org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator) PemWriter(org.bouncycastle.util.io.pem.PemWriter) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with JcaMiscPEMGenerator

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();
}
Also used : JcaMiscPEMGenerator(org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator) StringWriter(java.io.StringWriter) PemWriter(org.bouncycastle.util.io.pem.PemWriter)

Aggregations

JcaMiscPEMGenerator (org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator)14 PemWriter (org.bouncycastle.util.io.pem.PemWriter)14 OutputStreamWriter (java.io.OutputStreamWriter)7 Writer (java.io.Writer)5 KeyStore (java.security.KeyStore)5 Certificate (java.security.cert.Certificate)5 StringWriter (java.io.StringWriter)4 X509Certificate (java.security.cert.X509Certificate)3 File (java.io.File)2 IOException (java.io.IOException)2 TlsClientConfig (org.apache.nifi.toolkit.tls.configuration.TlsClientConfig)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1