CertificateData data2 = certhome.findByPrimaryKey(pk); assertNotNull("Failed to find cert", data2); data2.setStatus(CertificateData.CERT_REVOKED); data2.setRevocationDate(new Date()); data2.setRevocationReason(RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
ICertificateStoreSessionRemote store = storehome.create(); store.revokeCertificate(admin, ocspTestCert,null,RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
    public void test04OcspRevoked() throws Exception {        log.debug(">test04OcspRevoked()");        // Now revoke the certificate and try again        CertificateDataPK pk = new CertificateDataPK();        pk.fingerprint = CertTools.getFingerprintAsString(ocspTestCert);        CertificateData data2 = certhome.findByPrimaryKey(pk);        assertNotNull("Failed to find cert", data2);        data2.setStatus(CertificateData.CERT_REVOKED);        data2.setRevocationDate(new Date());        data2.setRevocationReason(RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);        // And an OCSP request        OCSPReqGenerator gen = new OCSPReqGenerator();        gen.addRequest(new CertificateID(CertificateID.HASH_SHA1, cacert, ocspTestCert.getSerialNumber()));        OCSPReq req = gen.generate();        // POST the OCSP request        WebConversation wc1 = new WebConversation();        ByteArrayInputStream bais = new ByteArrayInputStream(req.getEncoded());        PostMethodWebRequest request = new PostMethodWebRequest(httpReqPath + '/' + resourceOcsp, bais, "application/ocsp-request");        WebResponse webresponse = wc1.getResponse(request);        assertEquals("Response code", 200, webresponse.getResponseCode());        assertEquals("Content-Type", "application/ocsp-response", webresponse.getContentType());        // Extract the response        InputStreamReader in = new InputStreamReader(webresponse.getInputStream());        ByteArrayOutputStream baos = new ByteArrayOutputStream();        // This works for small requests, and OCSP requests are small        int b = in.read();        while (b != -1) {            baos.write(b);            b = in.read();        }        baos.flush();        in.close();        byte[] respBytes = baos.toByteArray();        OCSPResp response = new OCSPResp(new ByteArrayInputStream(respBytes));        assertEquals("Response status not zero.", response.getStatus(), 0);        BasicOCSPResp brep = (BasicOCSPResp) response.getResponseObject();        X509Certificate[] chain = brep.getCerts("BC");        boolean verify = brep.verify(chain[0].getPublicKey(), "BC");        assertTrue("Response failed to verify.", verify);        RespData respData = brep.getResponseData();        SingleResp[] singleResps = respData.getResponses();        assertEquals("No of SingResps should be 1.", singleResps.length, 1);        SingleResp singleResp = singleResps[0];        CertificateID certId = singleResp.getCertID();        assertEquals("Serno in response does not match serno in request.", certId.getSerialNumber(), ocspTestCert.getSerialNumber());        Object status = singleResp.getCertStatus();        assertTrue("Status is not RevokedStatus", status instanceof RevokedStatus);        RevokedStatus rev = (RevokedStatus) status;        assertTrue("Status does not have reason", rev.hasRevocationReason());        int reason = rev.getRevocationReason();        assertEquals("Wrong revocation reason", reason, RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);        log.debug("<test04OcspRevoked()");    }