use of java.security.cert.CertificateException in project OpenAttestation by OpenAttestation.
the class TrustFirstCertificateTlsPolicy method addServerCertificatesToRepository.
private void addServerCertificatesToRepository(X509Certificate[] xcs) {
for (X509Certificate cert : xcs) {
System.out.println("server certificate: " + cert.getSubjectX500Principal().getName());
}
for (int i = 0; i < xcs.length; i++) {
try {
// CertificateExpiredException, CertificateNotYetValidEception
xcs[i].checkValidity();
log.info("Saving certificate {}", xcs[i].getSubjectX500Principal().getName());
// KeyManagementException
repository.addCertificate(xcs[i]);
} catch (Exception e) {
log.trace("TrustFirstCertificateTlsPolicy addServerCertificateToRepository cert was not valid. trying to save next cert");
// don't throw an exception because we may be able to save other certificates? throw new CertificateException("Unable to save server certificate", e);
}
}
}
use of java.security.cert.CertificateException in project OpenAttestation by OpenAttestation.
the class X509CertificateDerProvider method readFrom.
@Override
public X509Certificate readFrom(Class<X509Certificate> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
try {
// instead of using X509Util.decodeDerCertificate(byte[]) here we inline it because we have an inputstream instead
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(entityStream);
return cert;
} catch (CertificateException e) {
throw new IOException(e);
}
}
use of java.security.cert.CertificateException in project OpenAttestation by OpenAttestation.
the class X509CertificatePemProvider method readFrom.
@Override
public X509Certificate readFrom(Class<X509Certificate> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
try {
String pem = IOUtils.toString(entityStream);
X509Certificate cert = X509Util.decodePemCertificate(pem);
return cert;
} catch (CertificateException e) {
throw new IOException(e);
}
}
use of java.security.cert.CertificateException in project OpenAttestation by OpenAttestation.
the class X509Util method createX509TrustManagerWithKeystore.
/**
* @deprecated use TlsPolicy instead
* @param keystore
* @return
* @throws KeyManagementException
*/
public static X509TrustManager createX509TrustManagerWithKeystore(SimpleKeystore keystore) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(KeyStoreUtil.createTrustedSslKeystore(keystore));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of java.security.cert.CertificateException in project OpenAttestation by OpenAttestation.
the class X509Util method createX509TrustManagerWithCertificates.
/**
*
* @deprecated use TlsPolicy instead
* @param certificates
* @return
* @throws KeyManagementException
*/
public static X509TrustManager createX509TrustManagerWithCertificates(X509Certificate[] certificates) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(KeyStoreUtil.createTrustedSslKeystore(certificates));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
Aggregations