Search in sources :

Example 1 with Selector

use of org.bouncycastle.util.Selector in project robovm by robovm.

the class ExtendedPKIXParameters method setParams.

/**
     * Method to support <code>clone()</code> under J2ME.
     * <code>super.clone()</code> does not exist and fields are not copied.
     * 
     * @param params Parameters to set. If this are
     *            <code>ExtendedPKIXParameters</code> they are copied to.
     */
protected void setParams(PKIXParameters params) {
    setDate(params.getDate());
    setCertPathCheckers(params.getCertPathCheckers());
    setCertStores(params.getCertStores());
    setAnyPolicyInhibited(params.isAnyPolicyInhibited());
    setExplicitPolicyRequired(params.isExplicitPolicyRequired());
    setPolicyMappingInhibited(params.isPolicyMappingInhibited());
    setRevocationEnabled(params.isRevocationEnabled());
    setInitialPolicies(params.getInitialPolicies());
    setPolicyQualifiersRejected(params.getPolicyQualifiersRejected());
    setSigProvider(params.getSigProvider());
    setTargetCertConstraints(params.getTargetCertConstraints());
    try {
        setTrustAnchors(params.getTrustAnchors());
    } catch (Exception e) {
        // cannot happen
        throw new RuntimeException(e.getMessage());
    }
    if (params instanceof ExtendedPKIXParameters) {
        ExtendedPKIXParameters _params = (ExtendedPKIXParameters) params;
        validityModel = _params.validityModel;
        useDeltas = _params.useDeltas;
        additionalLocationsEnabled = _params.additionalLocationsEnabled;
        selector = _params.selector == null ? null : (Selector) _params.selector.clone();
        stores = new ArrayList(_params.stores);
        additionalStores = new ArrayList(_params.additionalStores);
        trustedACIssuers = new HashSet(_params.trustedACIssuers);
        prohibitedACAttributes = new HashSet(_params.prohibitedACAttributes);
        necessaryACAttributes = new HashSet(_params.necessaryACAttributes);
        attrCertCheckers = new HashSet(_params.attrCertCheckers);
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) Selector(org.bouncycastle.util.Selector) X509CertSelector(java.security.cert.X509CertSelector) CertSelector(java.security.cert.CertSelector) HashSet(java.util.HashSet)

Example 2 with Selector

use of org.bouncycastle.util.Selector 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 3 with Selector

use of org.bouncycastle.util.Selector in project XobotOS by xamarin.

the class ExtendedPKIXParameters method setParams.

/**
     * Method to support <code>clone()</code> under J2ME.
     * <code>super.clone()</code> does not exist and fields are not copied.
     * 
     * @param params Parameters to set. If this are
     *            <code>ExtendedPKIXParameters</code> they are copied to.
     */
protected void setParams(PKIXParameters params) {
    setDate(params.getDate());
    setCertPathCheckers(params.getCertPathCheckers());
    setCertStores(params.getCertStores());
    setAnyPolicyInhibited(params.isAnyPolicyInhibited());
    setExplicitPolicyRequired(params.isExplicitPolicyRequired());
    setPolicyMappingInhibited(params.isPolicyMappingInhibited());
    setRevocationEnabled(params.isRevocationEnabled());
    setInitialPolicies(params.getInitialPolicies());
    setPolicyQualifiersRejected(params.getPolicyQualifiersRejected());
    setSigProvider(params.getSigProvider());
    setTargetCertConstraints(params.getTargetCertConstraints());
    try {
        setTrustAnchors(params.getTrustAnchors());
    } catch (Exception e) {
        // cannot happen
        throw new RuntimeException(e.getMessage());
    }
    if (params instanceof ExtendedPKIXParameters) {
        ExtendedPKIXParameters _params = (ExtendedPKIXParameters) params;
        validityModel = _params.validityModel;
        useDeltas = _params.useDeltas;
        additionalLocationsEnabled = _params.additionalLocationsEnabled;
        selector = _params.selector == null ? null : (Selector) _params.selector.clone();
        stores = new ArrayList(_params.stores);
        additionalStores = new ArrayList(_params.additionalStores);
        trustedACIssuers = new HashSet(_params.trustedACIssuers);
        prohibitedACAttributes = new HashSet(_params.prohibitedACAttributes);
        necessaryACAttributes = new HashSet(_params.necessaryACAttributes);
        attrCertCheckers = new HashSet(_params.attrCertCheckers);
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) Selector(org.bouncycastle.util.Selector) X509CertSelector(java.security.cert.X509CertSelector) CertSelector(java.security.cert.CertSelector) HashSet(java.util.HashSet)

Example 4 with Selector

use of org.bouncycastle.util.Selector in project robovm by robovm.

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)

Aggregations

InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 ArrayList (java.util.ArrayList)4 Selector (org.bouncycastle.util.Selector)4 CertPathBuilderException (java.security.cert.CertPathBuilderException)2 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)2 CertSelector (java.security.cert.CertSelector)2 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)2 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)2 X509CertSelector (java.security.cert.X509CertSelector)2 X509Certificate (java.security.cert.X509Certificate)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ExtCertPathBuilderException (org.bouncycastle.jce.exception.ExtCertPathBuilderException)2 ExtendedPKIXBuilderParameters (org.bouncycastle.x509.ExtendedPKIXBuilderParameters)2 X509CertStoreSelector (org.bouncycastle.x509.X509CertStoreSelector)2