Java Code Examples for java.security.cert.CertPathValidatorException.BasicReason#ALGORITHM_CONSTRAINED

The following examples show how to use java.security.cert.CertPathValidatorException.BasicReason#ALGORITHM_CONSTRAINED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisabledAlgorithmConstraints.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    if (debug != null) {
        debug.println("jdkCAConstraints.permits(): " + algorithm);
    }

    // Check chain has a trust anchor in cacerts
    if (cp.isTrustedMatch()) {
        if (next(cp)) {
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on certificate " +
                "anchor limits. " + algorithm + extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 2
Source File: DisabledAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    Key key = null;
    if (cp.getKey() != null) {
        key = cp.getKey();
    } else if (cp.getCertificate() != null) {
        key = cp.getCertificate().getPublicKey();
    }
    if (key != null && !permitsImpl(key)) {
        if (nextConstraint != null) {
            nextConstraint.permits(cp);
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on keysize limits. " +
                algorithm + " " + KeyUtil.getKeySize(key) + "bit key" +
                extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 3
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    if (debug != null) {
        debug.println("jdkCAConstraints.permits(): " + algorithm);
    }

    // Check chain has a trust anchor in cacerts
    if (cp.isTrustedMatch()) {
        if (next(cp)) {
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on certificate " +
                "anchor limits. " + algorithm + extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 4
Source File: DisabledAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public final void permits(String algorithm, ConstraintsParameters cp)
        throws CertPathValidatorException {

    // Check if named curves in the ConstraintParameters are disabled.
    if (cp.getNamedCurve() != null) {
        for (String curve : cp.getNamedCurve()) {
            if (!checkAlgorithm(disabledAlgorithms, curve, decomposer)) {
                throw new CertPathValidatorException(
                        "Algorithm constraints check failed on disabled " +
                                "algorithm: " + curve,
                        null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
            }
        }
    }

    algorithmConstraints.permits(algorithm, cp);
}
 
Example 5
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    Key key = null;
    if (cp.getPublicKey() != null) {
        key = cp.getPublicKey();
    } else if (cp.getCertificate() != null) {
        key = cp.getCertificate().getPublicKey();
    }
    if (key != null && !permitsImpl(key)) {
        if (nextConstraint != null) {
            nextConstraint.permits(cp);
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on keysize limits. " +
                algorithm + " " + KeyUtil.getKeySize(key) + "bit key" +
                extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 6
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    if (debug != null) {
        debug.println("jdkCAConstraints.permits(): " + algorithm);
    }

    // Check chain has a trust anchor in cacerts
    if (cp.isTrustedMatch()) {
        if (next(cp)) {
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on certificate " +
                "anchor limits. " + algorithm + extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 7
Source File: DisabledAlgorithmConstraints.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void permits(CertConstraintParameters cp)
        throws CertPathValidatorException {
    if (debug != null) {
        debug.println("jdkCAConstraints.permits(): " + algorithm);
    }

    // Return false if the chain has a trust anchor in cacerts
    if (cp.isTrustedMatch()) {
        if (nextConstraint != null) {
            nextConstraint.permits(cp);
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on certificate " +
                        "anchor limits",
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 8
Source File: DisabledAlgorithmConstraints.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    if (debug != null) {
        debug.println("jdkCAConstraints.permits(): " + algorithm);
    }

    // Check chain has a trust anchor in cacerts
    if (cp.isTrustedMatch()) {
        if (next(cp)) {
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on certificate " +
                "anchor limits. " + algorithm + extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 9
Source File: DisabledAlgorithmConstraints.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    Key key = null;
    if (cp.getPublicKey() != null) {
        key = cp.getPublicKey();
    } else if (cp.getCertificate() != null) {
        key = cp.getCertificate().getPublicKey();
    }
    if (key != null && !permitsImpl(key)) {
        if (nextConstraint != null) {
            nextConstraint.permits(cp);
            return;
        }
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on keysize limits. " +
                algorithm + " " + KeyUtil.getKeySize(key) + "bit key" +
                extendedMsg(cp),
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 10
Source File: AlgorithmChecker.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "algorithm check failed: " + sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 11
Source File: DisabledAlgorithmConstraints.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    throw new CertPathValidatorException(
            "Algorithm constraints check failed on disabled " +
                    "algorithm: " + algorithm + extendedMsg(cp),
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
 
Example 12
Source File: AlgorithmChecker.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "algorithm check failed: " + sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 13
Source File: DisabledAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    throw new CertPathValidatorException(
            "Algorithm constraints check failed on disabled " +
                    "algorithm: " + algorithm + extendedMsg(cp),
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
 
Example 14
Source File: AlgorithmChecker.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "algorithm check failed: " + sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 15
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    throw new CertPathValidatorException(
            "Algorithm constraints check failed on disabled " +
                    "algorithm: " + algorithm + extendedMsg(cp),
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
 
Example 16
Source File: DisabledAlgorithmConstraints.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    for (String usage : usages) {

        String v = null;
        if (usage.compareToIgnoreCase("TLSServer") == 0) {
            v = Validator.VAR_TLS_SERVER;
        } else if (usage.compareToIgnoreCase("TLSClient") == 0) {
            v = Validator.VAR_TLS_CLIENT;
        } else if (usage.compareToIgnoreCase("SignedJAR") == 0) {
            v = Validator.VAR_PLUGIN_CODE_SIGNING;
        }

        if (debug != null) {
            debug.println("Checking if usage constraint \"" + v +
                    "\" matches \"" + cp.getVariant() + "\"");
            // Because usage checking can come from many places
            // a stack trace is very helpful.
            ByteArrayOutputStream ba = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(ba);
            (new Exception()).printStackTrace(ps);
            debug.println(ba.toString());
        }
        if (cp.getVariant().compareTo(v) == 0) {
            if (next(cp)) {
                return;
            }
            throw new CertPathValidatorException("Usage constraint " +
                    usage + " check failed: " + algorithm +
                    extendedMsg(cp),
                    null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
        }
    }
}
 
Example 17
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void permits(ConstraintsParameters cp)
        throws CertPathValidatorException {
    for (String usage : usages) {

        String v = null;
        if (usage.compareToIgnoreCase("TLSServer") == 0) {
            v = Validator.VAR_TLS_SERVER;
        } else if (usage.compareToIgnoreCase("TLSClient") == 0) {
            v = Validator.VAR_TLS_CLIENT;
        } else if (usage.compareToIgnoreCase("SignedJAR") == 0) {
            v = Validator.VAR_PLUGIN_CODE_SIGNING;
        }

        if (debug != null) {
            debug.println("Checking if usage constraint \"" + v +
                    "\" matches \"" + cp.getVariant() + "\"");
            // Because usage checking can come from many places
            // a stack trace is very helpful.
            ByteArrayOutputStream ba = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(ba);
            (new Exception()).printStackTrace(ps);
            debug.println(ba.toString());
        }
        if (cp.getVariant().compareTo(v) == 0) {
            if (next(cp)) {
                return;
            }
            throw new CertPathValidatorException("Usage constraint " +
                    usage + " check failed: " + algorithm +
                    extendedMsg(cp),
                    null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
        }
    }
}
 
Example 18
Source File: CertificateMessage.java    From openjsse with GNU General Public License v2.0 5 votes vote down vote up
/**
 * When a failure happens during certificate checking from an
 * {@link X509TrustManager}, determine what TLS alert description
 * to use.
 *
 * @param cexc The exception thrown by the {@link X509TrustManager}
 *
 * @return A byte value corresponding to a TLS alert description number.
 */
private static Alert getCertificateAlert(
        ClientHandshakeContext chc, CertificateException cexc) {
    // The specific reason for the failure will determine how to
    // set the alert description value
    Alert alert = Alert.CERTIFICATE_UNKNOWN;

    Throwable baseCause = cexc.getCause();
    if (baseCause instanceof CertPathValidatorException) {
        CertPathValidatorException cpve =
                (CertPathValidatorException)baseCause;
        Reason reason = cpve.getReason();
        if (reason == BasicReason.REVOKED) {
            alert = chc.staplingActive ?
                    Alert.BAD_CERT_STATUS_RESPONSE :
                    Alert.CERTIFICATE_REVOKED;
        } else if (
                reason == BasicReason.UNDETERMINED_REVOCATION_STATUS) {
            alert = chc.staplingActive ?
                    Alert.BAD_CERT_STATUS_RESPONSE :
                    Alert.CERTIFICATE_UNKNOWN;
        } else if (reason == BasicReason.ALGORITHM_CONSTRAINED) {
            alert = Alert.UNSUPPORTED_CERTIFICATE;
        } else if (reason == BasicReason.EXPIRED) {
            alert = Alert.CERTIFICATE_EXPIRED;
        } else if (reason == BasicReason.INVALID_SIGNATURE ||
                reason == BasicReason.NOT_YET_VALID) {
            alert = Alert.BAD_CERTIFICATE;
        }
    }

    return alert;
}
 
Example 19
Source File: AlgorithmChecker.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "Algorithm constraints check failed on signature algorithm: " +
            sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 20
Source File: CertificateMessage.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * When a failure happens during certificate checking from an
 * {@link X509TrustManager}, determine what TLS alert description
 * to use.
 *
 * @param cexc The exception thrown by the {@link X509TrustManager}
 *
 * @return A byte value corresponding to a TLS alert description number.
 */
private static Alert getCertificateAlert(
        ClientHandshakeContext chc, CertificateException cexc) {
    // The specific reason for the failure will determine how to
    // set the alert description value
    Alert alert = Alert.CERTIFICATE_UNKNOWN;

    Throwable baseCause = cexc.getCause();
    if (baseCause instanceof CertPathValidatorException) {
        CertPathValidatorException cpve =
                (CertPathValidatorException)baseCause;
        Reason reason = cpve.getReason();
        if (reason == BasicReason.REVOKED) {
            alert = chc.staplingActive ?
                    Alert.BAD_CERT_STATUS_RESPONSE :
                    Alert.CERTIFICATE_REVOKED;
        } else if (
                reason == BasicReason.UNDETERMINED_REVOCATION_STATUS) {
            alert = chc.staplingActive ?
                    Alert.BAD_CERT_STATUS_RESPONSE :
                    Alert.CERTIFICATE_UNKNOWN;
        } else if (reason == BasicReason.ALGORITHM_CONSTRAINED) {
            alert = Alert.UNSUPPORTED_CERTIFICATE;
        } else if (reason == BasicReason.EXPIRED) {
            alert = Alert.CERTIFICATE_EXPIRED;
        } else if (reason == BasicReason.INVALID_SIGNATURE ||
                reason == BasicReason.NOT_YET_VALID) {
            alert = Alert.BAD_CERTIFICATE;
        }
    }

    return alert;
}