use of java.security.KeyStore in project zaproxy by zaproxy.
the class DynamicSSLPanel method doImport.
/**
* Import Root CA certificate from other ZAP configuration files.
*/
private void doImport() {
if (checkExistingCertificate()) {
// prevent overwriting
return;
}
final JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setSelectedFile(new File(CONFIGURATION_FILENAME));
fc.setFileFilter(new FileFilter() {
@Override
public String getDescription() {
// config.xml or *.pem files
return Constant.messages.getString("dynssl.filter.file");
}
@Override
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(CONFIGURATION_FILENAME) || f.getName().toLowerCase().endsWith("pem") || f.isDirectory();
}
});
final int result = fc.showOpenDialog(this);
final File f = fc.getSelectedFile();
if (result == JFileChooser.APPROVE_OPTION && f.exists()) {
if (logger.isInfoEnabled()) {
logger.info("Loading Root CA certificate from " + f);
}
KeyStore ks = null;
if (f.getName().toLowerCase().endsWith("pem")) {
ks = convertPemFileToKeyStore(f.toPath());
} else {
try {
final ZapXmlConfiguration conf = new ZapXmlConfiguration(f);
final String rootcastr = conf.getString(DynSSLParam.PARAM_ROOT_CA);
ks = SslCertificateUtils.string2Keystore(rootcastr);
} catch (final Exception e) {
logger.error("Error importing Root CA cert from config file:", e);
JOptionPane.showMessageDialog(this, Constant.messages.getString("dynssl.message1.filecouldntloaded"), Constant.messages.getString("dynssl.message1.title"), JOptionPane.ERROR_MESSAGE);
}
}
if (ks != null) {
setRootca(ks);
}
}
}
use of java.security.KeyStore in project zaproxy by zaproxy.
the class ExtensionDynSSL method createNewRootCa.
public void createNewRootCa() throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException {
logger.info("Creating new root CA certificate");
KeyStore newrootca = SslCertificateUtils.createRootCA();
setRootCa(newrootca);
getParams().setRootca(newrootca);
logger.info("New root CA certificate created");
}
use of java.security.KeyStore in project zaproxy by zaproxy.
the class SslCertificateUtils method pem2KeyStore.
public static KeyStore pem2KeyStore(byte[] certBytes, byte[] keyBytes) throws IOException, CertificateException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException {
X509Certificate cert = generateCertificateFromDER(certBytes);
RSAPrivateKey key = generatePrivateKeyFromDER(keyBytes);
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(null);
keystore.setCertificateEntry("cert-alias", cert);
keystore.setKeyEntry(SslCertificateService.ZAPROXY_JKS_ALIAS, key, SslCertificateService.PASSPHRASE, new Certificate[] { cert });
return keystore;
}
use of java.security.KeyStore in project zaproxy by zaproxy.
the class SslCertificateUtils method string2Keystore.
/**
* @param str
* @return
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws NoSuchAlgorithmException
*/
public static final KeyStore string2Keystore(String str) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
final byte[] bytes = Base64.decodeBase64(str);
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(bais, SslCertificateService.PASSPHRASE);
bais.close();
return ks;
}
use of java.security.KeyStore in project spring-boot by spring-projects.
the class UndertowServletWebServerFactory method loadKeyStore.
private KeyStore loadKeyStore(String type, String resource, String password) throws Exception {
type = (type == null ? "JKS" : type);
if (resource == null) {
return null;
}
KeyStore store = KeyStore.getInstance(type);
URL url = ResourceUtils.getURL(resource);
store.load(url.openStream(), password == null ? null : password.toCharArray());
return store;
}
Aggregations