use of org.mozilla.jss.netscape.security.x509.SubjectAlternativeNameExtension in project scout.rt by eclipse-scout.
the class SunSecurityProvider method createSelfSignedCertificate.
@Override
public void createSelfSignedCertificate(String certificateAlias, String x500Name, String storePass, String keyPass, int keyBits, int validDays, OutputStream out) {
try {
sun.security.tools.keytool.CertAndKeyGen certGen = new sun.security.tools.keytool.CertAndKeyGen("RSA", "SHA256WithRSA", null);
certGen.generate(keyBits);
sun.security.x509.X500Name name = new sun.security.x509.X500Name(x500Name);
long validSecs = (long) validDays * 24L * 3600L;
GeneralNames generalNames = new GeneralNames().add(new GeneralName(new DNSName("localhost"))).add(new GeneralName(new IPAddressName("127.0.0.1")));
if (!StringUtility.isNullOrEmpty(name.getCommonName())) {
generalNames.add(new GeneralName(new DNSName(name.getCommonName())));
}
CertificateExtensions extensions = new CertificateExtensions();
extensions.set(SubjectAlternativeNameExtension.NAME, new SubjectAlternativeNameExtension(generalNames));
X509Certificate cert = certGen.getSelfCertificate(name, new Date(), validSecs, extensions);
PrivateKey privateKey = certGen.getPrivateKey();
KeyStore ks = KeyStore.getInstance("jks");
ks.load(null, storePass.toCharArray());
ks.setKeyEntry(certificateAlias, privateKey, keyPass.toCharArray(), new X509Certificate[] { cert });
ks.store(out, storePass.toCharArray());
} catch (GeneralSecurityException e) {
throw new ProcessingException("Security issue", e);
} catch (IOException e) {
throw new ProcessingException("IO issue", e);
}
}
Aggregations