Search in sources :

Example 91 with CertPathValidatorException

use of java.security.cert.CertPathValidatorException in project jdk8u_jdk by JetBrains.

the class PKIXExtendedTM method main.

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        throw new Exception("Incorrect number of arguments");
    }
    Test test = tests[Integer.parseInt(args[0])];
    Security.setProperty("jdk.tls.disabledAlgorithms", test.tlsDisAlgs);
    Security.setProperty("jdk.certpath.disabledAlgorithms", test.certPathDisAlgs);
    if (debug) {
        System.setProperty("javax.net.debug", "all");
    }
    /*
         * Start the tests.
         */
    try {
        new PKIXExtendedTM();
        if (test.fail) {
            throw new Exception("Expected MD5 certificate to be blocked");
        }
    } catch (Exception e) {
        if (test.fail) {
            // find expected cause
            boolean correctReason = false;
            Throwable cause = e.getCause();
            while (cause != null) {
                if (cause instanceof CertPathValidatorException) {
                    CertPathValidatorException cpve = (CertPathValidatorException) cause;
                    if (cpve.getReason() == CertPathValidatorException.BasicReason.ALGORITHM_CONSTRAINED) {
                        correctReason = true;
                        break;
                    }
                }
                cause = cause.getCause();
            }
            if (!correctReason) {
                throw new Exception("Unexpected exception", e);
            }
        } else {
            throw e;
        }
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) CertPathValidatorException(java.security.cert.CertPathValidatorException)

Example 92 with CertPathValidatorException

use of java.security.cert.CertPathValidatorException in project jdk8u_jdk by JetBrains.

the class CPValidatorEndEntity method main.

public static void main(String[] args) throws Exception {
    // reset the security property to make sure that the algorithms
    // and keys used in this test are not disabled.
    Security.setProperty("jdk.certpath.disabledAlgorithms", "MD2");
    try {
        validate(endentiry_SHA1withRSA_1024_1024, intermediate_SHA1withRSA_1024_1024);
        validate(endentiry_SHA1withRSA_1024_512, intermediate_SHA1withRSA_512_1024);
        validate(endentiry_SHA1withRSA_512_1024, intermediate_SHA1withRSA_1024_1024);
        validate(endentiry_SHA1withRSA_512_512, intermediate_SHA1withRSA_512_1024);
    } catch (CertPathValidatorException cpve) {
        throw new Exception("unexpect exception, it is valid cert", cpve);
    }
    try {
        validate(endentiry_MD2withRSA_1024_1024, intermediate_SHA1withRSA_1024_1024);
        throw new Exception("expected algorithm disabled exception");
    } catch (CertPathValidatorException cpve) {
        // we may get ClassCastException here
        BasicReason reason = (BasicReason) cpve.getReason();
        if (reason != BasicReason.ALGORITHM_CONSTRAINED) {
            throw new Exception("Expect to get ALGORITHM_CONSTRAINED CPVE", cpve);
        }
        System.out.println("Get the expected exception " + cpve);
    }
    try {
        validate(endentiry_MD2withRSA_1024_512, intermediate_SHA1withRSA_512_1024);
        throw new Exception("expected algorithm disabled exception");
    } catch (CertPathValidatorException cpve) {
        // we may get ClassCastException here
        BasicReason reason = (BasicReason) cpve.getReason();
        if (reason != BasicReason.ALGORITHM_CONSTRAINED) {
            throw new Exception("Expect to get ALGORITHM_CONSTRAINED CPVE", cpve);
        }
        System.out.println("Get the expected exception " + cpve);
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) SocketException(java.net.SocketException) CertPathValidatorException(java.security.cert.CertPathValidatorException)

Aggregations

CertPathValidatorException (java.security.cert.CertPathValidatorException)92 IOException (java.io.IOException)45 X509Certificate (java.security.cert.X509Certificate)43 ExtCertPathValidatorException (org.bouncycastle.jce.exception.ExtCertPathValidatorException)36 ArrayList (java.util.ArrayList)35 GeneralSecurityException (java.security.GeneralSecurityException)32 List (java.util.List)30 CertPathBuilderException (java.security.cert.CertPathBuilderException)24 CertificateExpiredException (java.security.cert.CertificateExpiredException)24 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)24 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)23 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)23 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)21 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)18 Enumeration (java.util.Enumeration)15 Iterator (java.util.Iterator)15 CertificateException (java.security.cert.CertificateException)13 CertPath (java.security.cert.CertPath)12 HashSet (java.util.HashSet)12 Set (java.util.Set)10