use of java.security.cert.CertPathBuilderException in project oxAuth by GluuFederation.
the class PathCertificateVerifier method verifyCertificate.
public PKIXCertPathBuilderResult verifyCertificate(X509Certificate certificate, List<X509Certificate> additionalCerts) {
try {
// Check for self-signed certificate
if (!verifySelfSignedCertificate && isSelfSigned(certificate)) {
log.error("The certificate is self-signed!");
return null;
}
// Prepare a set of trusted root CA certificates and a set of
// intermediate certificates
Set<X509Certificate> trustedRootCerts = new HashSet<X509Certificate>();
Set<X509Certificate> intermediateCerts = new HashSet<X509Certificate>();
for (X509Certificate additionalCert : additionalCerts) {
if (isSelfSigned(additionalCert)) {
trustedRootCerts.add(additionalCert);
} else {
intermediateCerts.add(additionalCert);
}
}
// Attempt to build the certification chain and verify it
PKIXCertPathBuilderResult certPathBuilderResult = verifyCertificate(certificate, trustedRootCerts, intermediateCerts);
// Check that first certificate is an EE certificate
CertPath certPath = certPathBuilderResult.getCertPath();
List<? extends Certificate> certList = certPath.getCertificates();
X509Certificate cert = (X509Certificate) certList.get(0);
if (cert.getBasicConstraints() != -1) {
log.error("Target certificate is not an EE certificate!");
return null;
}
// The chain is verified. Return it as a result
return certPathBuilderResult;
} catch (CertPathBuilderException ex) {
log.error("Failed to build certificate path", ex);
} catch (GeneralSecurityException ex) {
log.error("Failed to build certificate path", ex);
}
return null;
}
use of java.security.cert.CertPathBuilderException in project j2objc by google.
the class CertPathBuilderSpiTest method testCertPathBuilderSpi01.
/**
* Test for <code>CertPathBuilderSpi</code> constructor Assertion:
* constructs CertPathBuilderSpi
*/
public void testCertPathBuilderSpi01() throws CertPathBuilderException, InvalidAlgorithmParameterException {
CertPathBuilderSpi certPathBuilder = new MyCertPathBuilderSpi();
CertPathParameters cpp = null;
try {
certPathBuilder.engineBuild(cpp);
fail("CertPathBuilderException must be thrown");
} catch (CertPathBuilderException e) {
}
CertPathBuilderResult cpbResult = certPathBuilder.engineBuild(cpp);
assertNull("Not null CertPathBuilderResult", cpbResult);
}
use of java.security.cert.CertPathBuilderException in project j2objc by google.
the class CertPathBuilderExceptionTest method testCertPathBuilderException04.
/**
* Test for <code>CertPathBuilderException(Throwable)</code> constructor
* Assertion: constructs CertPathBuilderException when <code>cause</code>
* is null
*/
public void testCertPathBuilderException04() {
Throwable cause = null;
CertPathBuilderException tE = new CertPathBuilderException(cause);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.cert.CertPathBuilderException in project j2objc by google.
the class CertPathBuilderExceptionTest method testCertPathBuilderException02.
/**
* Test for <code>CertPathBuilderException(String)</code> constructor
* Assertion: constructs CertPathBuilderException with detail message msg.
* Parameter <code>msg</code> is not null.
*/
public void testCertPathBuilderException02() {
CertPathBuilderException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new CertPathBuilderException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
use of java.security.cert.CertPathBuilderException in project jackrabbit by apache.
the class ConnectionTest method testObtainWithTLSSelfSignedCertNotAllowed.
public void testObtainWithTLSSelfSignedCertNotAllowed() throws RepositoryException, URISyntaxException {
RepositoryService repositoryService = createRepositoryService(true, null);
try {
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
fail("should have failed with CertPathBuilderException!");
} catch (RepositoryException e) {
Throwable cause = ExceptionUtils.getRootCause(e);
if (!(cause instanceof CertPathBuilderException)) {
fail("should have failed with CertPathBuilderException but got " + e.getCause());
}
}
}
Aggregations