Java Code Examples for java.security.cert.CertPathValidatorException#getMessage()

The following examples show how to use java.security.cert.CertPathValidatorException#getMessage() . 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: GetMessage.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 2
Source File: RFC3280CertPathUtilities.java    From ripple-lib-java with ISC License 5 votes vote down vote up
protected static void prepareNextCertO(
    CertPath certPath,
    int index,
    Set criticalExtensions,
    List pathCheckers)
    throws CertPathValidatorException
{
    List certs = certPath.getCertificates();
    X509Certificate cert = (X509Certificate)certs.get(index);
    //
    // (o)
    //

    Iterator tmpIter;
    tmpIter = pathCheckers.iterator();
    while (tmpIter.hasNext())
    {
        try
        {
            ((PKIXCertPathChecker)tmpIter.next()).check(cert, criticalExtensions);
        }
        catch (CertPathValidatorException e)
        {
            throw new CertPathValidatorException(e.getMessage(), e.getCause(), certPath, index);
        }
    }
    if (!criticalExtensions.isEmpty())
    {
        throw new ExtCertPathValidatorException("Certificate has unsupported critical extension: " + criticalExtensions, null, certPath,
            index);
    }
}
 
Example 3
Source File: RFC3280CertPathUtilities.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected static void prepareNextCertO(
    CertPath certPath,
    int index,
    Set criticalExtensions,
    List pathCheckers)
    throws CertPathValidatorException
{
    List certs = certPath.getCertificates();
    X509Certificate cert = (X509Certificate)certs.get(index);
    //
    // (o)
    //

    Iterator tmpIter;
    tmpIter = pathCheckers.iterator();
    while (tmpIter.hasNext())
    {
        try
        {
            ((PKIXCertPathChecker)tmpIter.next()).check(cert, criticalExtensions);
        }
        catch (CertPathValidatorException e)
        {
            throw new CertPathValidatorException(e.getMessage(), e.getCause(), certPath, index);
        }
    }
    if (!criticalExtensions.isEmpty())
    {
        throw new ExtCertPathValidatorException("Certificate has unsupported critical extension: " + criticalExtensions, null, certPath,
            index);
    }
}
 
Example 4
Source File: GetMessage.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 5
Source File: GetMessage.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 6
Source File: GetMessage.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 7
Source File: GetMessage.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 8
Source File: GetMessage.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 9
Source File: GetMessage.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 10
Source File: GetMessage.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 11
Source File: GetMessage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 12
Source File: GetMessage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 13
Source File: GetMessage.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 14
Source File: GetMessage.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 15
Source File: GetMessage.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Throwable[] causes = {
                new Throwable(),
                new Throwable("message"),
                new Throwable("message", new Throwable()) };

        for (Throwable cause: causes) {
            CertPathValidatorException cpve =
                new CertPathValidatorException(cause);

            // from CertPathValidatorException(Throwable cause) spec:
            // The detail message is set to (cause==null ? null : cause.toString() )
            // (which typically contains the class and detail message of cause).
            String expMsg = (cause == null ? null : cause.toString());
            String actualMsg = cpve.getMessage();

            boolean msgsEqual =
                (expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
            if (!msgsEqual) {
                System.out.println("expected message:" + expMsg);
                System.out.println("getMessage():" + actualMsg);
                failed = true;
            }
        }
        if (failed) {
            throw new Exception("Some tests FAILED");
        }
    }
 
Example 16
Source File: PKIXMasterCertPathValidator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Validates a certification path consisting exclusively of
 * <code>X509Certificate</code>s using the specified
 * <code>PKIXCertPathChecker</code>s. It is assumed that the
 * <code>PKIXCertPathChecker</code>s
 * have been initialized with any input parameters they may need.
 *
 * @param cpOriginal the original X509 CertPath passed in by the user
 * @param reversedCertList the reversed X509 CertPath (as a List)
 * @param certPathCheckers the PKIXCertPathCheckers
 * @throws CertPathValidatorException if cert path does not validate
 */
static void validate(CertPath cpOriginal,
                     List<X509Certificate> reversedCertList,
                     List<PKIXCertPathChecker> certPathCheckers)
    throws CertPathValidatorException
{
    // we actually process reversedCertList, but we keep cpOriginal because
    // we need to return the original certPath when we throw an exception.
    // we will also need to modify the index appropriately when we
    // throw an exception.

    int cpSize = reversedCertList.size();

    if (debug != null) {
        debug.println("--------------------------------------------------"
              + "------------");
        debug.println("Executing PKIX certification path validation "
              + "algorithm.");
    }

    for (int i = 0; i < cpSize; i++) {

        /* The basic loop algorithm is that we get the
         * current certificate, we verify the current certificate using
         * information from the previous certificate and from the state,
         * and we modify the state for the next loop by setting the
         * current certificate of this loop to be the previous certificate
         * of the next loop. The state is initialized during first loop.
         */
        if (debug != null)
            debug.println("Checking cert" + (i+1) + " ...");

        X509Certificate currCert = reversedCertList.get(i);
        Set<String> unresCritExts = currCert.getCriticalExtensionOIDs();
        if (unresCritExts == null) {
            unresCritExts = Collections.<String>emptySet();
        }

        if (debug != null && !unresCritExts.isEmpty()) {
            debug.println("Set of critical extensions:");
            for (String oid : unresCritExts) {
                debug.println(oid);
            }
        }

        for (int j = 0; j < certPathCheckers.size(); j++) {

            PKIXCertPathChecker currChecker = certPathCheckers.get(j);
            if (debug != null) {
                debug.println("-Using checker" + (j + 1) + " ... [" +
                    currChecker.getClass().getName() + "]");
            }

            if (i == 0)
                currChecker.init(false);

            try {
                currChecker.check(currCert, unresCritExts);

                if (debug != null) {
                    debug.println("-checker" + (j + 1) +
                        " validation succeeded");
                }

            } catch (CertPathValidatorException cpve) {
                throw new CertPathValidatorException(cpve.getMessage(),
                    cpve.getCause(), cpOriginal, cpSize - (i + 1),
                    cpve.getReason());
            }
        }

        if (!unresCritExts.isEmpty()) {
            throw new CertPathValidatorException("unrecognized " +
                "critical extension(s)", null, cpOriginal, cpSize-(i+1),
                PKIXReason.UNRECOGNIZED_CRIT_EXT);
        }

        if (debug != null)
            debug.println("\ncert" + (i+1) + " validation succeeded.\n");
    }

    if (debug != null) {
        debug.println("Cert path validation succeeded. (PKIX validation "
                      + "algorithm)");
        debug.println("-------------------------------------------------"
                      + "-------------");
    }
}
 
Example 17
Source File: PKIXMasterCertPathValidator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Validates a certification path consisting exclusively of
 * <code>X509Certificate</code>s using the specified
 * <code>PKIXCertPathChecker</code>s. It is assumed that the
 * <code>PKIXCertPathChecker</code>s
 * have been initialized with any input parameters they may need.
 *
 * @param cpOriginal the original X509 CertPath passed in by the user
 * @param reversedCertList the reversed X509 CertPath (as a List)
 * @param certPathCheckers the PKIXCertPathCheckers
 * @throws CertPathValidatorException if cert path does not validate
 */
static void validate(CertPath cpOriginal,
                     List<X509Certificate> reversedCertList,
                     List<PKIXCertPathChecker> certPathCheckers)
    throws CertPathValidatorException
{
    // we actually process reversedCertList, but we keep cpOriginal because
    // we need to return the original certPath when we throw an exception.
    // we will also need to modify the index appropriately when we
    // throw an exception.

    int cpSize = reversedCertList.size();

    if (debug != null) {
        debug.println("--------------------------------------------------"
              + "------------");
        debug.println("Executing PKIX certification path validation "
              + "algorithm.");
    }

    for (int i = 0; i < cpSize; i++) {

        /* The basic loop algorithm is that we get the
         * current certificate, we verify the current certificate using
         * information from the previous certificate and from the state,
         * and we modify the state for the next loop by setting the
         * current certificate of this loop to be the previous certificate
         * of the next loop. The state is initialized during first loop.
         */
        if (debug != null)
            debug.println("Checking cert" + (i+1) + " ...");

        X509Certificate currCert = reversedCertList.get(i);
        Set<String> unresCritExts = currCert.getCriticalExtensionOIDs();
        if (unresCritExts == null) {
            unresCritExts = Collections.<String>emptySet();
        }

        if (debug != null && !unresCritExts.isEmpty()) {
            debug.println("Set of critical extensions:");
            for (String oid : unresCritExts) {
                debug.println(oid);
            }
        }

        for (int j = 0; j < certPathCheckers.size(); j++) {

            PKIXCertPathChecker currChecker = certPathCheckers.get(j);
            if (debug != null) {
                debug.println("-Using checker" + (j + 1) + " ... [" +
                    currChecker.getClass().getName() + "]");
            }

            if (i == 0)
                currChecker.init(false);

            try {
                currChecker.check(currCert, unresCritExts);

                if (debug != null) {
                    debug.println("-checker" + (j + 1) +
                        " validation succeeded");
                }

            } catch (CertPathValidatorException cpve) {
                throw new CertPathValidatorException(cpve.getMessage(),
                    cpve.getCause(), cpOriginal, cpSize - (i + 1),
                    cpve.getReason());
            }
        }

        if (!unresCritExts.isEmpty()) {
            throw new CertPathValidatorException("unrecognized " +
                "critical extension(s)", null, cpOriginal, cpSize-(i+1),
                PKIXReason.UNRECOGNIZED_CRIT_EXT);
        }

        if (debug != null)
            debug.println("\ncert" + (i+1) + " validation succeeded.\n");
    }

    if (debug != null) {
        debug.println("Cert path validation succeeded. (PKIX validation "
                      + "algorithm)");
        debug.println("-------------------------------------------------"
                      + "-------------");
    }
}