use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project zaproxy by zaproxy.
the class DynamicSSLPanel method setRootca.
private void setRootca(KeyStore rootca) {
this.rootca = rootca;
final StringWriter sw = new StringWriter();
if (rootca != null) {
try {
final Certificate cert = rootca.getCertificate(org.parosproxy.paros.security.SslCertificateService.ZAPROXY_JKS_ALIAS);
try (final PemWriter pw = new PemWriter(sw)) {
pw.writeObject(new JcaMiscPEMGenerator(cert));
pw.flush();
}
} catch (final Exception e) {
logger.error("Error while extracting public part from generated Root CA certificate.", e);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Certificate defined.\n" + sw.toString());
}
txt_PubCert.setText(sw.toString());
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project zaproxy by zaproxy.
the class ExtensionDynSSL method writeRootFullCaCertificateToFile.
/**
* Writes the Root CA full certificate to the specified file in pem format, suitable for
* importing into ZAP
*
* @param path the path the Root CA certificate will be written to
* @throws IOException
* @throws KeyStoreException
* @throws NoSuchAlgorithmException
* @throws CertificateException
* @throws UnrecoverableKeyException
* @since 2.8.0
*/
public void writeRootFullCaCertificateToFile(Path path) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException {
KeyStore ks = this.getParams().getRootca();
if (ks != null) {
final Certificate cert = ks.getCertificate(org.parosproxy.paros.security.SslCertificateService.ZAPROXY_JKS_ALIAS);
try (final Writer w = Files.newBufferedWriter(path, StandardCharsets.US_ASCII);
final PemWriter pw = new PemWriter(w)) {
pw.writeObject(new JcaMiscPEMGenerator(cert));
pw.flush();
w.write(SslCertificateUtils.BEGIN_PRIVATE_KEY_TOKEN + "\n");
Key key = ks.getKey(org.parosproxy.paros.security.SslCertificateService.ZAPROXY_JKS_ALIAS, org.parosproxy.paros.security.SslCertificateService.PASSPHRASE);
PrivateKey pk = (PrivateKey) key;
w.write(Base64.getMimeEncoder().encodeToString(pk.getEncoded()));
w.write("\n" + SslCertificateUtils.END_PRIVATE_KEY_TOKEN + "\n");
}
}
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project Openfire by igniterealtime.
the class CertificateManager method toPemRepresentation.
/**
* Generates a PEM representation of the input argument.
*
* @param object the input argument (cannot be null).
* @return PEM representation of the input argument.
* @throws IOException When a PEM representation of the input could not be created.
*/
public static String toPemRepresentation(Object object) throws IOException {
final StringWriter result = new StringWriter();
try (final PemWriter pemWriter = new PemWriter(result)) {
final PemObjectGenerator objGen = new JcaMiscPEMGenerator(object);
pemWriter.writeObject(objGen);
}
return result.toString();
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project java by kubernetes-client.
the class SSLUtils method dumpKey.
public static byte[] dumpKey(PrivateKey privateKey) throws IOException {
StringWriter writer = new StringWriter();
PemWriter pemWriter = new PemWriter(writer);
pemWriter.writeObject(new JcaMiscPEMGenerator(privateKey));
pemWriter.flush();
return writer.toString().getBytes();
}
use of org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator in project nifi by apache.
the class TlsClientManager method write.
@Override
public void write(OutputStreamFactory outputStreamFactory) throws IOException, GeneralSecurityException {
super.write(outputStreamFactory);
String trustStorePassword = tlsClientConfig.getTrustStorePassword();
boolean trustStorePasswordGenerated = false;
if (StringUtils.isEmpty(trustStorePassword)) {
trustStorePassword = getPasswordUtil().generatePassword();
trustStorePasswordGenerated = true;
}
trustStorePassword = TlsHelper.writeKeyStore(trustStore, outputStreamFactory, new File(tlsClientConfig.getTrustStore()), trustStorePassword, trustStorePasswordGenerated);
tlsClientConfig.setTrustStorePassword(trustStorePassword);
for (ConfigurationWriter<TlsClientConfig> configurationWriter : configurationWriters) {
configurationWriter.write(tlsClientConfig, outputStreamFactory);
}
if (certificateAuthorityDirectory != null) {
// Write out all trusted certificates from truststore
for (String alias : Collections.list(trustStore.aliases())) {
try {
KeyStore.Entry trustStoreEntry = trustStore.getEntry(alias, null);
if (trustStoreEntry instanceof KeyStore.TrustedCertificateEntry) {
Certificate trustedCertificate = ((KeyStore.TrustedCertificateEntry) trustStoreEntry).getTrustedCertificate();
try (OutputStream outputStream = outputStreamFactory.create(new File(certificateAuthorityDirectory, alias + ".pem"));
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
PemWriter pemWriter = new PemWriter(outputStreamWriter)) {
pemWriter.writeObject(new JcaMiscPEMGenerator(trustedCertificate));
}
}
} catch (UnrecoverableEntryException e) {
// Ignore, not a trusted cert
}
}
}
}
Aggregations