Search in sources :

Example 26 with CertPathBuilderException

use of java.security.cert.CertPathBuilderException in project XobotOS by xamarin.

the class PKIXCertPathBuilderSpi method engineBuild.

/**
     * Build and validate a CertPath using the given parameter.
     * 
     * @param params PKIXBuilderParameters object containing all information to
     *            build the CertPath
     */
public CertPathBuilderResult engineBuild(CertPathParameters params) throws CertPathBuilderException, InvalidAlgorithmParameterException {
    if (!(params instanceof PKIXBuilderParameters) && !(params instanceof ExtendedPKIXBuilderParameters)) {
        throw new InvalidAlgorithmParameterException("Parameters must be an instance of " + PKIXBuilderParameters.class.getName() + " or " + ExtendedPKIXBuilderParameters.class.getName() + ".");
    }
    ExtendedPKIXBuilderParameters pkixParams = null;
    if (params instanceof ExtendedPKIXBuilderParameters) {
        pkixParams = (ExtendedPKIXBuilderParameters) params;
    } else {
        pkixParams = (ExtendedPKIXBuilderParameters) ExtendedPKIXBuilderParameters.getInstance((PKIXBuilderParameters) params);
    }
    Collection targets;
    Iterator targetIter;
    List certPathList = new ArrayList();
    X509Certificate cert;
    // search target certificates
    Selector certSelect = pkixParams.getTargetConstraints();
    if (!(certSelect instanceof X509CertStoreSelector)) {
        throw new CertPathBuilderException("TargetConstraints must be an instance of " + X509CertStoreSelector.class.getName() + " for " + this.getClass().getName() + " class.");
    }
    try {
        targets = CertPathValidatorUtilities.findCertificates((X509CertStoreSelector) certSelect, pkixParams.getStores());
        targets.addAll(CertPathValidatorUtilities.findCertificates((X509CertStoreSelector) certSelect, pkixParams.getCertStores()));
    } catch (AnnotatedException e) {
        throw new ExtCertPathBuilderException("Error finding target certificate.", e);
    }
    if (targets.isEmpty()) {
        throw new CertPathBuilderException("No certificate found matching targetContraints.");
    }
    CertPathBuilderResult result = null;
    // check all potential target certificates
    targetIter = targets.iterator();
    while (targetIter.hasNext() && result == null) {
        cert = (X509Certificate) targetIter.next();
        result = build(cert, pkixParams, certPathList);
    }
    if (result == null && certPathException != null) {
        if (certPathException instanceof AnnotatedException) {
            throw new CertPathBuilderException(certPathException.getMessage(), certPathException.getCause());
        }
        throw new CertPathBuilderException("Possible certificate chain could not be validated.", certPathException);
    }
    if (result == null && certPathException == null) {
        throw new CertPathBuilderException("Unable to find certificate chain.");
    }
    return result;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ExtendedPKIXBuilderParameters(org.bouncycastle.x509.ExtendedPKIXBuilderParameters) ExtendedPKIXBuilderParameters(org.bouncycastle.x509.ExtendedPKIXBuilderParameters) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertStoreSelector(org.bouncycastle.x509.X509CertStoreSelector) CertPathBuilderResult(java.security.cert.CertPathBuilderResult) PKIXCertPathBuilderResult(java.security.cert.PKIXCertPathBuilderResult) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) ExtCertPathBuilderException(org.bouncycastle.jce.exception.ExtCertPathBuilderException) CertPathBuilderException(java.security.cert.CertPathBuilderException) Iterator(java.util.Iterator) ExtCertPathBuilderException(org.bouncycastle.jce.exception.ExtCertPathBuilderException) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Selector(org.bouncycastle.util.Selector) X509CertStoreSelector(org.bouncycastle.x509.X509CertStoreSelector)

Example 27 with CertPathBuilderException

use of java.security.cert.CertPathBuilderException in project robovm by robovm.

the class CertPathBuilderExceptionTest method testCertPathBuilderException07.

/**
     * Test for <code>CertPathBuilderException(String, Throwable)</code>
     * constructor Assertion: constructs CertPathBuilderException when
     * <code>cause</code> is null <code>msg</code> is not null
     */
public void testCertPathBuilderException07() {
    CertPathBuilderException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertPathBuilderException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : CertPathBuilderException(java.security.cert.CertPathBuilderException)

Example 28 with CertPathBuilderException

use of java.security.cert.CertPathBuilderException in project robovm by robovm.

the class CertPathBuilderExceptionTest method testCertPathBuilderException09.

/**
     * Test for <code>CertPathBuilderException(String, Throwable)</code>
     * constructor Assertion: constructs CertPathBuilderException when
     * <code>cause</code> is not null <code>msg</code> is not null
     */
public void testCertPathBuilderException09() {
    CertPathBuilderException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertPathBuilderException(msgs[i], tCause);
        String getM = tE.getMessage();
        String toS = tCause.toString();
        if (msgs[i].length() > 0) {
            assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
            if (!getM.equals(msgs[i])) {
                assertTrue("getMessage() should contain ".concat(toS), getM.indexOf(toS) != -1);
            }
        }
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
    }
}
Also used : CertPathBuilderException(java.security.cert.CertPathBuilderException)

Example 29 with CertPathBuilderException

use of java.security.cert.CertPathBuilderException in project robovm by robovm.

the class CertPathBuilderExceptionTest method testCertPathBuilderException03.

/**
     * Test for <code>CertPathBuilderException(String)</code> constructor
     * Assertion: constructs CertPathBuilderException when <code>msg</code> is
     * null
     */
public void testCertPathBuilderException03() {
    String msg = null;
    CertPathBuilderException tE = new CertPathBuilderException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertPathBuilderException(java.security.cert.CertPathBuilderException)

Example 30 with CertPathBuilderException

use of java.security.cert.CertPathBuilderException in project robovm by robovm.

the class CertPathBuilderExceptionTest method testCertPathBuilderException06.

/**
     * Test for <code>CertPathBuilderException(String, Throwable)</code>
     * constructor Assertion: constructs CertPathBuilderException when
     * <code>cause</code> is null <code>msg</code> is null
     */
public void testCertPathBuilderException06() {
    CertPathBuilderException tE = new CertPathBuilderException(null, null);
    assertNull("getMessage() must return null", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertPathBuilderException(java.security.cert.CertPathBuilderException)

Aggregations

CertPathBuilderException (java.security.cert.CertPathBuilderException)41 X509Certificate (java.security.cert.X509Certificate)17 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)12 CertPathBuilder (java.security.cert.CertPathBuilder)11 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)10 ArrayList (java.util.ArrayList)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 HashSet (java.util.HashSet)9 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)8 TrustAnchor (java.security.cert.TrustAnchor)8 X509CertSelector (java.security.cert.X509CertSelector)8 GeneralSecurityException (java.security.GeneralSecurityException)7 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)7 IOException (java.io.IOException)6 CertPath (java.security.cert.CertPath)6 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)6 NoSuchProviderException (java.security.NoSuchProviderException)5 CertPathValidatorException (java.security.cert.CertPathValidatorException)5 Certificate (java.security.cert.Certificate)5 List (java.util.List)5