use of java.security.GeneralSecurityException in project qpid-broker-j by apache.
the class SiteSpecificTrustStoreImpl method generateTrustManagers.
private void generateTrustManagers() {
try {
java.security.KeyStore inMemoryKeyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
inMemoryKeyStore.load(null, null);
inMemoryKeyStore.setCertificateEntry("1", _x509Certificate);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(inMemoryKeyStore);
_trustManagers = tmf.getTrustManagers();
} catch (IOException | GeneralSecurityException e) {
throw new IllegalConfigurationException("Cannot load certificate(s) :" + e, e);
}
}
use of java.security.GeneralSecurityException in project qpid-broker-j by apache.
the class TrustAnchorValidatingTrustManager method checkClientTrusted.
@Override
public void checkClientTrusted(final X509Certificate[] x509Certificates, final String authType) throws CertificateException {
_x509TrustManager.checkClientTrusted(x509Certificates, authType);
X509Certificate peerCertificate = x509Certificates[0];
PKIXCertPathBuilderResult pkixCertPathBuilderResult;
try {
pkixCertPathBuilderResult = getPkixCertPathBuilderResult(x509Certificates, _trustAnchors, _otherCerts);
} catch (GeneralSecurityException e) {
throw new CertificateException("Unexpected error whilst validating trust-anchor", e);
}
X509Certificate trustAnchorCert = pkixCertPathBuilderResult.getTrustAnchor().getTrustedCert();
try {
trustAnchorCert.checkValidity();
} catch (CertificateExpiredException | CertificateNotYetValidException e) {
LOGGER.warn("Authentication failed for peer bearing certificate (subject DN '{}') " + "as the trust anchor (subject DN '{}') within truststore '{}' " + "is either expired or not yet valid. Validity range {} - {}", peerCertificate.getSubjectDN(), trustAnchorCert.getSubjectDN(), _trustStoreName, trustAnchorCert.getNotBefore(), trustAnchorCert.getNotAfter());
throw e;
}
}
use of java.security.GeneralSecurityException in project ambry by linkedin.
the class RestTestUtils method getTestSSLFactory.
/**
* @return an {@link SSLFactory} for use in rest unit tests.
*/
static SSLFactory getTestSSLFactory() {
try {
File trustStoreFile = File.createTempFile("truststore", ".jks");
trustStoreFile.deleteOnExit();
return new SSLFactory(new SSLConfig(TestSSLUtils.createSslProps("", SSLFactory.Mode.SERVER, trustStoreFile, "frontend")));
} catch (IOException | GeneralSecurityException e) {
throw new IllegalStateException(e);
}
}
use of java.security.GeneralSecurityException in project ambry by linkedin.
the class GCMCryptoService method encrypt.
@Override
public ByteBuffer encrypt(ByteBuffer toEncrypt, SecretKeySpec key) throws GeneralSecurityException {
try {
Cipher encrypter = Cipher.getInstance(GCM_CRYPTO_INSTANCE, "BC");
byte[] iv = new byte[ivValSize];
random.nextBytes(iv);
encrypter.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
int outputSize = encrypter.getOutputSize(toEncrypt.remaining());
ByteBuffer encryptedContent = ByteBuffer.allocate(IVRecord_Format_V1.getIVRecordSize(iv) + outputSize);
IVRecord_Format_V1.serializeIVRecord(encryptedContent, iv);
encrypter.doFinal(toEncrypt, encryptedContent);
encryptedContent.flip();
return encryptedContent;
} catch (Exception e) {
throw new GeneralSecurityException("Exception thrown while encrypting data", e);
}
}
use of java.security.GeneralSecurityException in project ambry by linkedin.
the class GCMCryptoService method decrypt.
@Override
public ByteBuffer decrypt(ByteBuffer toDecrypt, SecretKeySpec key) throws GeneralSecurityException {
try {
Cipher decrypter = Cipher.getInstance(GCM_CRYPTO_INSTANCE, "BC");
byte[] iv = deserializeIV(new ByteBufferInputStream(toDecrypt));
decrypter.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
ByteBuffer decryptedContent = ByteBuffer.allocate(decrypter.getOutputSize(toDecrypt.remaining()));
decrypter.doFinal(toDecrypt, decryptedContent);
decryptedContent.flip();
return decryptedContent;
} catch (Exception e) {
throw new GeneralSecurityException("Exception thrown while decrypting data", e);
}
}
Aggregations