Package java.security.cert

Examples of java.security.cert.CertPathValidatorException


       
        // common checks
        THROWABLE_COMPARATOR.assertDeserialized(oref, otest);
       
        // class specific checks
        CertPathValidatorException ref = (CertPathValidatorException) oref;
        CertPathValidatorException test = (CertPathValidatorException) otest;
        CertPath cp = ref.getCertPath();
        int ind = ref.getIndex();
        assertEquals("Incorrect index", test.getIndex(), ind);
        if (cp == null) {
            assertNull("getCertPath() must return null", test.getCertPath());
        } else {
            CertPath res = test.getCertPath();
            assertEquals("Incorrect CertPath", res.getClass(), cp.getClass());
        }
    }
View Full Code Here


            CertPathParameters params) throws CertPathValidatorException,
            InvalidAlgorithmParameterException {
        ++sw;
        if (certPath == null) {
            if ((sw % 2) == 0) {
                throw new CertPathValidatorException("certPath null");
            }
        }
        if (params == null) {
            if ((sw % 3) == 0) {
                throw new InvalidAlgorithmParameterException("params null");
View Full Code Here

        X509Certificate firstCert = null;
        if (!certList.isEmpty()) {
            firstCert = certList.get(0);
        }

        CertPathValidatorException lastException = null;

        // We iterate through the set of trust anchors until we find
        // one that works at which time we stop iterating
        for (TrustAnchor anchor : anchors) {
            X509Certificate trustedCert = anchor.getTrustedCert();
            if (trustedCert != null) {
                if (debug != null) {
                    debug.println("PKIXCertPathValidator.engineValidate() "
                        + "anchor.getTrustedCert() != null");
                }
                // if this trust anchor is not worth trying,
                // we move on to the next one
                if (!isWorthTrying(trustedCert, firstCert)) {
                    continue;
                }

                if (debug != null) {
                    debug.println("anchor.getTrustedCert()."
                        + "getSubjectX500Principal() = "
                        + trustedCert.getSubjectX500Principal());
                }
            } else {
                if (debug != null) {
                    debug.println("PKIXCertPathValidator.engineValidate(): "
                        + "anchor.getTrustedCert() == null");
                }
            }

            try {
                PolicyNodeImpl rootNode = new PolicyNodeImpl(null,
                    PolicyChecker.ANY_POLICY, null, false,
                    Collections.singleton(PolicyChecker.ANY_POLICY), false);
                PolicyNode policyTree =
                    doValidate(anchor, cp, certList, pkixParam, rootNode);
                // if this anchor works, return success
                return new PKIXCertPathValidatorResult(anchor, policyTree,
                    basicChecker.getPublicKey());
            } catch (CertPathValidatorException cpe) {
                // remember this exception
                lastException = cpe;
            }
        }

        // could not find a trust anchor that verified
        // (a) if we did a validation and it failed, use that exception
        if (lastException != null) {
            throw lastException;
        }
        // (b) otherwise, generate new exception
        throw new CertPathValidatorException
                        ("Path does not chain with any of the trust anchors");
    }
View Full Code Here

                for (String oid : unresolvedCritExts) {
                    debug.println(oid);
                }
            }

            CertPathValidatorException ocspCause = null;
            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, unresolvedCritExts);

                    // OCSP has validated the cert so skip the CRL check
                    if (isRevocationCheck(currChecker, j, certPathCheckers)) {
                        if (debug != null) {
                            debug.println("-checker" + (j + 1) +
                                " validation succeeded");
                        }
                        j++;
                        continue; // skip
                    }

                } catch (CertPathValidatorException cpve) {
                    // Throw the saved OCSP exception
                    // (when the CRL check has also failed)
                    if (ocspCause != null &&
                        currChecker instanceof CrlRevocationChecker) {
                        throw ocspCause;
                    }
                    /*
                     * Handle failover from OCSP to CRLs
                     */
                    CertPathValidatorException currentCause =
                        new CertPathValidatorException(cpve.getMessage(),
                            cpve.getCause(), cpOriginal, cpSize - (i + 1));

                    // Check if OCSP has confirmed that the cert was revoked
                    if (cpve instanceof CertificateRevokedException) {
                        throw currentCause;
                    }
                    // Check if it is appropriate to failover
                    if (! isRevocationCheck(currChecker, j, certPathCheckers)) {
                        // no failover
                        throw currentCause;
                    }
                    // Save the current exception
                    // (in case the CRL check also fails)
                    ocspCause = currentCause;

                    // Otherwise, failover to CRLs
                    if (debug != null) {
                        debug.println(cpve.getMessage());
                        debug.println(
                            "preparing to failover (from OCSP to CRLs)");
                    }
                }

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

            if (debug != null)
                debug.println("checking for unresolvedCritExts");
            if (!unresolvedCritExts.isEmpty()) {
                throw new CertPathValidatorException("unrecognized " +
                    "critical extension(s)", null, cpOriginal, cpSize-(i+1));
            }

            if (debug != null)
                debug.println("\ncert" + (i+1) + " validation succeeded.\n");
View Full Code Here

            if (debug != null) {
                debug.println("UntrustedChecker: untrusted certificate " +
                        currCert.getSubjectX500Principal());
            }

            throw new CertPathValidatorException(
                "Untrusted certificate: " + currCert.getSubjectX500Principal());
        }
    }
View Full Code Here

        URI responderURI = null;
        try {
            X509CertImpl certImpl = X509CertImpl.toImpl(cert);
            responderURI = getResponderURI(certImpl);
            if (responderURI == null) {
                throw new CertPathValidatorException
                    ("No OCSP Responder URI in certificate");
            }
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
        } catch (CertificateException ce) {
            throw new CertPathValidatorException
                ("Exception while encoding OCSPRequest", ce);
        } catch (IOException ioe) {
            throw new CertPathValidatorException
                ("Exception while encoding OCSPRequest", ioe);
        }
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
            responderURI, issuerCert, null);
        return (RevocationStatus) ocspResponse.getSingleResponse(certId);
View Full Code Here

        CertId certId = null;
        try {
            X509CertImpl certImpl = X509CertImpl.toImpl(cert);
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
        } catch (CertificateException ce) {
            throw new CertPathValidatorException
                ("Exception while encoding OCSPRequest", ce);
        } catch (IOException ioe) {
            throw new CertPathValidatorException
                ("Exception while encoding OCSPRequest", ioe);
        }
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
            responderURI, responderCert, date);
        return (RevocationStatus) ocspResponse.getSingleResponse(certId);
View Full Code Here

        byte[] bytes = null;
        try {
            OCSPRequest request = new OCSPRequest(certIds);
            bytes = request.encodeBytes();
        } catch (IOException ioe) {
            throw new CertPathValidatorException
                ("Exception while encoding OCSPRequest", ioe);
        }

        InputStream in = null;
        OutputStream out = null;
        byte[] response = null;
        try {
            URL url = responderURI.toURL();
            if (debug != null) {
                debug.println("connecting to OCSP service at: " + url);
            }
            HttpURLConnection con = (HttpURLConnection)url.openConnection();
            con.setConnectTimeout(CONNECT_TIMEOUT);
            con.setReadTimeout(CONNECT_TIMEOUT);
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setRequestMethod("POST");
            con.setRequestProperty
                ("Content-type", "application/ocsp-request");
            con.setRequestProperty
                ("Content-length", String.valueOf(bytes.length));
            out = con.getOutputStream();
            out.write(bytes);
            out.flush();
            // Check the response
            if (debug != null &&
                con.getResponseCode() != HttpURLConnection.HTTP_OK) {
                debug.println("Received HTTP error: " + con.getResponseCode()
                    + " - " + con.getResponseMessage());
            }
            in = con.getInputStream();
            int contentLength = con.getContentLength();
            if (contentLength == -1) {
                contentLength = Integer.MAX_VALUE;
            }
            response = new byte[contentLength > 2048 ? 2048 : contentLength];
            int total = 0;
            while (total < contentLength) {
                int count = in.read(response, total, response.length - total);
                if (count < 0)
                    break;

                total += count;
                if (total >= response.length && total < contentLength) {
                    response = Arrays.copyOf(response, total * 2);
                }
            }
            response = Arrays.copyOf(response, total);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ioe) {
                    throw ioe;
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException ioe) {
                    throw ioe;
                }
            }
        }

        OCSPResponse ocspResponse = null;
        try {
            ocspResponse = new OCSPResponse(response, date, responderCert);
        } catch (IOException ioe) {
            // response decoding exception
            throw new CertPathValidatorException(ioe);
        }
        if (ocspResponse.getResponseStatus() != ResponseStatus.SUCCESSFUL) {
            throw new CertPathValidatorException
                ("OCSP response error: " + ocspResponse.getResponseStatus());
        }

        // Check that the response includes a response for all of the
        // certs that were supplied in the request
        for (CertId certId : certIds) {
            SingleResponse sr = ocspResponse.getSingleResponse(certId);
            if (sr == null) {
                if (debug != null) {
                    debug.println("No response found for CertId: " + certId);
                }
                throw new CertPathValidatorException(
                    "OCSP response does not include a response for a " +
                    "certificate supplied in the OCSP request");
            }
            if (debug != null) {
                debug.println("Status of certificate (with serial number " +
View Full Code Here

                    if ((buildParams.isPolicyMappingInhibited()) ||
                        (!policyMappingFound)) {
                        if (debug != null) {
                            debug.println("loop detected!!");
                        }
                        throw new CertPathValidatorException("loop detected");
                    }
                }
            }
        }
View Full Code Here

                if (debug != null) {
                    debug.println("ForwardState.updateState() unexpected "
                        + "exception");
                    e.printStackTrace();
                }
                throw new CertPathValidatorException(e);
            }
        }

        init = false;
    }
View Full Code Here

TOP

Related Classes of java.security.cert.CertPathValidatorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.