Package org.bouncycastle.cert.ocsp

Examples of org.bouncycastle.cert.ocsp.BasicOCSPResp


                            }
                        }
                    }

                    // Send a OCSP request.
                    BasicOCSPResp response = OCSPClient.getOCSPResponse(
                        certificate, issuerCertificate);
                    if (response == null) {
                        throw new NoOCSPResponseException(String.format(messages.getString(
                            "Could_not_get_a_OCSP_response_for_the_certificate__%s"),
                            CertificateValidator.getCertificateName(certificate)));
                    }
                    ocspResponses.add(response);

                // Download CRL.
                } else if (useCRL) {
                    // Check if the CRL has already been downloaded.
                    boolean downloaded = false;
                    Collection<String> urls = CRLDownloader.getCRLDistributionPoints(certificate);
                    for (String url : urls) {
                        if (allCRLDistributionPoints.contains(url)) {
                            downloaded = true;
                        } else {
                            allCRLDistributionPoints.add(url);
                        }
                    }
                    if (downloaded) {
                        continue;
                    }

                    // Download CRL.
                    X509CRL crl = CRLDownloader.getCRL(certificate);
                    if (crl == null) {
                        throw new NoCRLException(String.format(messages.getString(
                            "Could_not_get_CRL_for_the_certificate__%s"),
                            CertificateValidator.getCertificateName(certificate)));
                    }
                    crls.add(crl);
                }
            }

            // Add signature certificates, OCSP responses and CRLs to global stores.
            certMap.put(signature, certificates);
            ocspMap.put(signature, ocspResponses);
            crlMap.put(signature, crls);
        }

        // Open output file for writing.
        FileOutputStream output = new FileOutputStream(outputFileName);
        File temp = File.createTempFile("tmp", ".tmp");
        PdfStamper stamper = PdfStamper.createSignature(
            reader, output, '\0', temp, true);

        // Create a DSS (Document Security Store).
        LtvVerification verification = stamper.getLtvVerification();

        // Add certificates, OCSP responses and CRLs to DSS.
        for (String signature : certMap.keySet()) {
            ArrayList<byte[]> certificates = new ArrayList<byte[]>();
            for (X509Certificate certificate : certMap.get(signature)) {
                certificates.add(certificate.getEncoded());
            }
            ArrayList<byte[]> ocsps = new ArrayList<byte[]>();
            for (BasicOCSPResp response : ocspMap.get(signature)) {
                ocsps.add(response.getEncoded());
            }
            ArrayList<byte[]> crls = new ArrayList<byte[]>();
            for (X509CRL crl : crlMap.get(signature)) {
                crls.add(crl.getEncoded());
            }
View Full Code Here


        }

        // Query each OCSP responder until it gets a valid response.
        OcspClientBouncyCastle client = new OcspClientBouncyCastle();
        for (String url : urls) {
            BasicOCSPResp response = client.getBasicOCSPResp(certificate, issuerCertificate, url);
            if (response != null) {
                return response;
            }
        }
View Full Code Here

        String issuerCertificateFileName = command.getOptionValue("issuer");
        String ocspResponseFileName = command.getOptionValue("out");

        try {
            // Request OCSP response.
            BasicOCSPResp response = OCSPClient.getOCSPResponse(
                certificateFileName, issuerCertificateFileName);

            // Check if the certificate has no OCSP information.
            if (response == null) {
                System.err.println(messages.getString(
                    "Certificate_has_no_OCSP_information."));
                System.exit(1);
            }

            // Write response to file.
            FileOutputStream file = new FileOutputStream(ocspResponseFileName);
            file.write(response.getEncoded());
            file.close();

        } catch (Exception exception) {
            // Print stack trace in case of unexpected exception.
            exception.printStackTrace();
View Full Code Here

        ArrayList<BasicOCSPResp> ocsps = new ArrayList<BasicOCSPResp>();
        if (ocspArray != null) {
            for (int i = 0; i < ocspArray.size(); i++) {
                PRStream stream = (PRStream) ocspArray.getAsStream(i);
                OCSPResp response = new OCSPResp(PdfReader.getStreamBytes(stream));
                BasicOCSPResp basicResponse = (BasicOCSPResp) response.getResponseObject();
                ocsps.add(basicResponse);
            }
        }
        PdfArray crlArray = dictionary.getAsArray(PdfName.CRLS);
        ArrayList<X509CRL> crls = new ArrayList<X509CRL>();
View Full Code Here

  public BasicOCSPResp getOcspResponse(X509Certificate signCert, X509Certificate issuerCert) {
    if (signCert == null && issuerCert == null) {
      return null;
    }
    OcspClientBouncyCastle ocsp = new OcspClientBouncyCastle();
    BasicOCSPResp ocspResp = ocsp.getBasicOCSPResp(signCert, issuerCert, null);
    if (ocspResp == null) {
      return null;
    }
    SingleResp[] resp = ocspResp.getResponses();
    for (int i = 0; i < resp.length; i++) {
      Object status = resp[i].getCertStatus();
      if (status == CertificateStatus.GOOD) {
        return ocspResp;
      }
View Full Code Here

     * from the check cert or from other implementation specific source
   * @return  a byte array with the validation or null if the validation could not be obtained
   */
    public byte[] getEncoded(X509Certificate checkCert, X509Certificate rootCert, String url) {
        try {
            BasicOCSPResp basicResponse = getBasicOCSPResp(checkCert, rootCert, url);
            if (basicResponse != null) {
                SingleResp[] responses = basicResponse.getResponses();
                if (responses.length == 1) {
                    SingleResp resp = responses[0];
                    Object status = resp.getCertStatus();
                    if (status == CertificateStatus.GOOD) {
                        return basicResponse.getEncoded();
                    }
                    else if (status instanceof org.bouncycastle.ocsp.RevokedStatus) {
                        throw new IOException(MessageLocalization.getComposedMessage("ocsp.status.is.revoked"));
                    }
                    else {
View Full Code Here

                return;
        }
        ASN1OctetString os = (ASN1OctetString)seq.getObjectAt(1);
        ASN1InputStream inp = new ASN1InputStream(os.getOctets());
        BasicOCSPResponse resp = BasicOCSPResponse.getInstance(inp.readObject());
        basicResp = new BasicOCSPResp(resp);
    }
View Full Code Here

                return;
        }
        ASN1OctetString os = (ASN1OctetString)seq.getObjectAt(1);
        ASN1InputStream inp = new ASN1InputStream(os.getOctets());
        BasicOCSPResponse resp = BasicOCSPResponse.getInstance(inp.readObject());
        basicResp = new BasicOCSPResp(resp);
    }
View Full Code Here

  public BasicOCSPResp getOcspResponse(X509Certificate signCert, X509Certificate issuerCert) {
    if (signCert == null && issuerCert == null) {
      return null;
    }
    OcspClientBouncyCastle ocsp = new OcspClientBouncyCastle();
    BasicOCSPResp ocspResp = ocsp.getBasicOCSPResp(signCert, issuerCert, null);
    if (ocspResp == null) {
      return null;
    }
    SingleResp[] resp = ocspResp.getResponses();
    for (int i = 0; i < resp.length; i++) {
      Object status = resp[i].getCertStatus();
      if (status == CertificateStatus.GOOD) {
        return ocspResp;
      }
View Full Code Here

     * from the check cert or from other implementation specific source
   * @return  a byte array with the validation or null if the validation could not be obtained
   */
    public byte[] getEncoded(X509Certificate checkCert, X509Certificate rootCert, String url) {
        try {
            BasicOCSPResp basicResponse = getBasicOCSPResp(checkCert, rootCert, url);
            if (basicResponse != null) {
                SingleResp[] responses = basicResponse.getResponses();
                if (responses.length == 1) {
                    SingleResp resp = responses[0];
                    Object status = resp.getCertStatus();
                    if (status == CertificateStatus.GOOD) {
                        return basicResponse.getEncoded();
                    }
                    else if (status instanceof org.bouncycastle.ocsp.RevokedStatus) {
                        throw new IOException(MessageLocalization.getComposedMessage("ocsp.status.is.revoked"));
                    }
                    else {
View Full Code Here

TOP

Related Classes of org.bouncycastle.cert.ocsp.BasicOCSPResp

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.