use of java.security.KeyStoreException in project OpenAM by OpenRock.
the class STSCryptoProviderBase method loadKeystore.
private KeyStore loadKeystore() throws TokenCreationException {
InputStream inputStream;
try {
inputStream = getKeystoreInputStream();
} catch (FileNotFoundException e) {
throw new TokenCreationException(ResourceException.BAD_REQUEST, "Could not find keystore file at location " + keystoreLocation + " neither on the filesystem, nor on the classpath.");
}
KeyStore keyStore;
try {
keyStore = KeyStore.getInstance(keystoreType);
} catch (KeyStoreException e) {
throw new TokenCreationException(ResourceException.INTERNAL_ERROR, "Could not get JKS keystore: " + e.getMessage(), e);
}
try {
keyStore.load(inputStream, new String(keystorePassword, AMSTSConstants.UTF_8_CHARSET_ID).toCharArray());
return keyStore;
} catch (IOException | NoSuchAlgorithmException | CertificateException e) {
throw new TokenCreationException(ResourceException.CONFLICT, "Could not load keystore at location " + keystoreLocation + ": " + e.getMessage(), e);
}
}
use of java.security.KeyStoreException in project zaproxy by zaproxy.
the class SSLContextManager method getFingerPrint.
public String getFingerPrint(Certificate cert) throws KeyStoreException {
if (!(cert instanceof X509Certificate)) {
return null;
}
StringBuffer buff = new StringBuffer();
X509Certificate x509 = (X509Certificate) cert;
try {
String fingerprint = Encoding.hashMD5(cert.getEncoded());
for (int i = 0; i < fingerprint.length(); i += 2) {
buff.append(fingerprint.substring(i, i + 1)).append(":");
}
buff.deleteCharAt(buff.length() - 1);
} catch (CertificateEncodingException e) {
throw new KeyStoreException(e.getMessage());
}
String dn = x509.getSubjectDN().getName();
log.info("Fingerprint is " + buff.toString().toUpperCase());
return buff.toString().toUpperCase() + " " + dn;
}
use of java.security.KeyStoreException in project zaproxy by zaproxy.
the class SSLContextManager method initMSCAPI.
public int initMSCAPI() throws KeyStoreException, NoSuchProviderException, IOException, NoSuchAlgorithmException, CertificateException {
try {
if (!isProviderAvailable("msks")) {
return -1;
}
Provider mscapi = (Provider) Class.forName("se.assembla.jce.provider.ms.MSProvider").newInstance();
Security.addProvider(mscapi);
// init the key store
KeyStore ks = KeyStore.getInstance("msks", "assembla");
ks.load(null, null);
return addKeyStore(ks, "Microsoft CAPI Store", null);
} catch (Exception e) {
log.error("Error instantiating the MSCAPI provider: " + e.getMessage(), e);
return -1;
}
}
use of java.security.KeyStoreException in project OpenAM by OpenRock.
the class AMKeyProvider method getPublicKey.
/**
* Return java.security.PublicKey for the specified keyAlias.
* @param keyAlias Key alias name
* @return PublicKey which matches the keyAlias, return null if the PublicKey could not be found.
*/
public java.security.PublicKey getPublicKey(String keyAlias) {
if (keyAlias == null || keyAlias.length() == 0) {
return null;
}
java.security.PublicKey pkey = null;
try {
X509Certificate cert = (X509Certificate) ks.getCertificate(keyAlias);
if (cert == null) {
logger.error("Unable to retrieve certificate with alias '" + keyAlias + "' from keystore " + "'" + this.keystoreFile + "'");
return null;
}
pkey = cert.getPublicKey();
} catch (KeyStoreException e) {
logger.error("Unable to get public key:" + keyAlias, e);
}
return pkey;
}
use of java.security.KeyStoreException in project OpenAM by OpenRock.
the class AMKeyProvider method getPrivateKey.
/**
* Return the {@link java.security.PrivateKey} for the specified certAlias and encrypted private key password.
* @param certAlias Certificate alias name
* @param encryptedKeyPass The encrypted key password to use when getting the private certificate
* @return PrivateKey which matches the certAlias, return null if the private key could not be found.
*/
public PrivateKey getPrivateKey(String certAlias, String encryptedKeyPass) {
PrivateKey key = null;
String keyPass = decodePassword(encryptedKeyPass);
if (keyPass != null) {
try {
key = (PrivateKey) ks.getKey(certAlias, keyPass.toCharArray());
} catch (KeyStoreException e) {
logger.error(e.getMessage());
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
} catch (UnrecoverableKeyException e) {
logger.error(e.getMessage());
}
} else {
logger.error("AMKeyProvider.getPrivateKey: " + "null key password returned from decryption for certificate alias:" + certAlias + " The password maybe incorrect.");
}
return key;
}
Aggregations