Example usage for org.bouncycastle.cert.ocsp OCSPException OCSPException

List of usage examples for org.bouncycastle.cert.ocsp OCSPException OCSPException

Introduction

In this page you can find the example usage for org.bouncycastle.cert.ocsp OCSPException OCSPException.

Prototype

public OCSPException(String name, Throwable cause) 

Source Link

Usage

From source file:ee.ria.xroad.common.util.CertHashBasedOcspResponderClient.java

License:Open Source License

/**
 * Creates a GET request to the internal cert hash based OCSP responder and expects OCSP responses.
 *
 * @param destination URL of the OCSP response provider
 * @return list of OCSP response objects
 * @throws IOException   if I/O errors occurred
 * @throws OCSPException if the response could not be parsed
 *//*from  w  w  w. j a  va 2s.  c om*/
public static List<OCSPResp> getOcspResponsesFromServer(URL destination) throws IOException, OCSPException {
    HttpURLConnection connection = (HttpURLConnection) destination.openConnection();
    connection.setRequestProperty("Accept", MimeTypes.MULTIPART_RELATED);
    connection.setDoOutput(true);
    connection.setConnectTimeout(SystemProperties.getOcspResponderClientConnectTimeout());
    connection.setReadTimeout(SystemProperties.getOcspResponderClientReadTimeout());
    connection.setRequestMethod(METHOD);
    connection.connect();

    if (!VALID_RESPONSE_CODES.contains(connection.getResponseCode())) {
        log.error("Invalid HTTP response ({}) from responder: {}", connection.getResponseCode(),
                connection.getResponseMessage());

        throw new IOException(connection.getResponseMessage());
    }

    MimeConfig config = new MimeConfig.Builder().setHeadlessParsing(connection.getContentType()).build();

    final List<OCSPResp> responses = new ArrayList<>();
    final MimeStreamParser parser = new MimeStreamParser(config);

    parser.setContentHandler(new AbstractContentHandler() {
        @Override
        public void startMultipart(BodyDescriptor bd) {
            parser.setFlat();
        }

        @Override
        public void body(BodyDescriptor bd, InputStream is) throws MimeException, IOException {
            if (bd.getMimeType().equalsIgnoreCase(MimeTypes.OCSP_RESPONSE)) {
                responses.add(new OCSPResp(IOUtils.toByteArray(is)));
            }
        }
    });

    try {
        parser.parse(connection.getInputStream());
    } catch (MimeException e) {
        throw new OCSPException("Error parsing response", e);
    }

    return responses;
}

From source file:ee.ria.xroad.signer.certmanager.OcspClient.java

License:Open Source License

private static OCSPResp parseResponse(byte[] data) throws OCSPException {
    try {/* ww w  .  j  av a  2  s . com*/
        return new OCSPResp(data);
    } catch (IOException e) {
        throw new OCSPException("Failed to parse OCSP response", e);
    }
}