use of java.security.cert.CertificateExpiredException 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.cert.CertificateExpiredException in project qpid-broker-j by apache.
the class NonJavaTrustStoreTest method testUseOfExpiredTrustAnchorDenied.
@Test
public void testUseOfExpiredTrustAnchorDenied() throws Exception {
final KeyCertificatePair keyCertPair = createExpiredCertificate();
final Path certificatePath = TLS_RESOURCE.saveCertificateAsPem(keyCertPair.getCertificate());
Map<String, Object> attributes = new HashMap<>();
attributes.put(NonJavaTrustStore.NAME, NAME);
attributes.put(NonJavaTrustStore.TRUST_ANCHOR_VALIDITY_ENFORCED, true);
attributes.put(NonJavaTrustStore.CERTIFICATES_URL, certificatePath.toFile().getAbsolutePath());
attributes.put(NonJavaTrustStore.TYPE, NON_JAVA_TRUST_STORE);
TrustStore<?> trustStore = createTestTrustStore(attributes);
TrustManager[] trustManagers = trustStore.getTrustManagers();
assertNotNull(trustManagers);
assertEquals("Unexpected number of trust managers", 1, trustManagers.length);
final boolean condition = trustManagers[0] instanceof X509TrustManager;
assertTrue("Unexpected trust manager type", condition);
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
try {
trustManager.checkClientTrusted(new X509Certificate[] { keyCertPair.getCertificate() }, "NULL");
fail("Exception not thrown");
} catch (CertificateException e) {
if (e instanceof CertificateExpiredException || "Certificate expired".equals(e.getMessage())) {
// IBMJSSE2 does not throw CertificateExpiredException, it throws a CertificateException
// PASS
} else {
throw e;
}
}
}
use of java.security.cert.CertificateExpiredException in project coprhd-controller by CoprHD.
the class ContextManagerImpl method registerVASACertificate.
/**
* vasaService interface
*/
@Override
public VasaProviderInfo registerVASACertificate(String username, String password, String certificateStr) throws InvalidCertificate, InvalidLogin, InvalidSession, StorageFault {
final String methodName = "registerVASACertificate() :";
log.debug(methodName + "Entry with inputs username[" + username + "] password[" + (password != null ? "****" : null) + "] certificateStr[" + (certificateStr != null ? "****" : null) + "]");
try {
_sosManager = new SOSManager();
/*
* Verify username/password before verifying certificate. This means
* that if both username/password and certificate are invalid
* InvalidLogin exception will be thrown.
*/
_sosManager.verifyLoginCredentials(username, password);
log.debug(methodName + "Valid username and password. User credentials accepted.");
String clientAddress = _sslUtil.checkHttpRequest(false, false);
X509Certificate x509Cert = (X509Certificate) _sslUtil.buildCertificate(certificateStr);
x509Cert.checkValidity();
if (!_sslUtil.certificateIsTrusted((Certificate) x509Cert)) {
_sslUtil.addCertificateToTrustStore(clientAddress, (Certificate) x509Cert);
log.trace(methodName + "new certificate added as trusted");
_sslUtil.refreshTrustStore();
invalidateSession();
} else {
log.trace(methodName + "certificate was already trusted");
}
log.trace(methodName + "vpInfo: defaultNameSpace[" + _vpInfo.getDefaultNamespace() + "] name[" + _vpInfo.getName() + "] sessionId[" + _vpInfo.getSessionId() + " vasaApiVersion[" + _vpInfo.getVasaApiVersion() + "] vasaProviderVersion[" + _vpInfo.getVasaProviderVersion() + "]");
log.debug(methodName + "Exit returning vpInfo");
return _vpInfo;
} catch (InvalidSession is) {
// thrown by sslUtil.checkHttpRequest()
log.error(methodName + "Session is invalid", is);
throw is;
} catch (InvalidCertificate ic) {
// thrown by sslUtil.buildCertificate()
log.error(methodName + "Certificate is invalid", ic);
throw ic;
} catch (CertificateExpiredException e) {
// thrown by x509Cert.checkValidity()
log.error(methodName + "Certificate is expired", e);
throw FaultUtil.InvalidCertificate(e);
} catch (CertificateNotYetValidException e) {
// thrown by x509Cert.checkValidity()
log.error(methodName + "Certificate is not in validity period ", e);
throw FaultUtil.InvalidCertificate(e);
} catch (InvalidLogin il) {
// thrown by verifyPassword();
log.error(methodName + "Invalid login", il);
throw il;
} catch (Exception e) {
log.error(methodName + "registration failed: ", e);
throw FaultUtil.StorageFault(methodName + "registration failed: ", e);
}
}
use of java.security.cert.CertificateExpiredException in project robovm by robovm.
the class X509CertificateTest method checkValidity.
private void checkValidity(CertificateFactory f) throws Exception {
X509Certificate c = getCertificate(f, CERT_RSA);
Calendar cal = Calendar.getInstance();
Date[] dates = getRsaCertificateDates();
/*
* The certificate validity periods in the test certificate MUST lie
* within the tested period. The API doesn't appear to allow any other
* way to test this code path as an unprivileged user.
*/
Date now = new Date();
assertTrue(now.after(dates[0]));
assertTrue(now.before(dates[1]));
/* This assumes the script makes a long-lived cert. */
c.checkValidity();
/* A day after the start date. */
cal.setTime(dates[0]);
cal.add(Calendar.DAY_OF_MONTH, 1);
c.checkValidity(cal.getTime());
/* A second before the start date. */
cal.setTime(dates[1]);
cal.add(Calendar.SECOND, -1);
c.checkValidity(cal.getTime());
try {
cal.setTime(dates[0]);
cal.add(Calendar.SECOND, -1);
c.checkValidity(cal.getTime());
fail();
} catch (CertificateNotYetValidException expected) {
}
try {
cal.setTime(dates[0]);
cal.add(Calendar.MONTH, -6);
c.checkValidity(cal.getTime());
fail();
} catch (CertificateNotYetValidException expected) {
}
try {
cal.setTime(dates[1]);
cal.add(Calendar.SECOND, 1);
c.checkValidity(cal.getTime());
fail();
} catch (CertificateExpiredException expected) {
}
try {
cal.setTime(dates[1]);
cal.add(Calendar.YEAR, 1);
c.checkValidity(cal.getTime());
fail();
} catch (CertificateExpiredException expected) {
}
}
use of java.security.cert.CertificateExpiredException in project robovm by robovm.
the class CertificateExpiredExceptionTest method testCertificateExpiredException02.
/**
* Test for <code>CertificateExpiredException(String)</code> constructor
* Assertion: constructs CertificateExpiredException with detail message
* msg. Parameter <code>msg</code> is not null.
*/
public void testCertificateExpiredException02() {
CertificateExpiredException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new CertificateExpiredException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
Aggregations