Skip to content

Commit

Permalink
[ELY-2060] Also add a method for generation of independent self signe…
Browse files Browse the repository at this point in the history
…d certificates.
  • Loading branch information
darranl committed Dec 18, 2020
1 parent e9ac9f1 commit 366d762
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ public X509Certificate createIdentity(final String alias, final X500Principal pr
}
}

public X509Certificate createSelfSignedIdentity(final String alias, final X500Principal principal, final String keyStoreName) {
SelfSignedX509CertificateAndSigningKey selfSignedIdentity = SelfSignedX509CertificateAndSigningKey.builder()
.setDn(principal)
.setKeyAlgorithmName(KEY_ALGORITHM)
.setSignatureAlgorithmName(SIGNATURE_ALGORTHM)
.build();

X509Certificate selfSignedCertificate = selfSignedIdentity.getSelfSignedCertificate();
File keyStoreFile = new File(workingDir, keyStoreName);
KeyStore keyStore = createEmptyKeyStore();
try {
keyStore.setKeyEntry(alias, selfSignedIdentity.getSigningKey(), PASSWORD,
new X509Certificate[] { selfSignedIdentity.getSelfSignedCertificate() });
try (OutputStream out = new FileOutputStream(keyStoreFile)) {
keyStore.store(out, PASSWORD);
}
} catch (IOException | KeyStoreException | CertificateException | NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}

return selfSignedCertificate;
}

private X509Certificate createIdentity(final Identity identity) {
Identity caIdentity = identity.getSignedBy();
if (caIdentity == null) {
Expand Down

0 comments on commit 366d762

Please sign in to comment.