当前位置: 首页>>代码示例>>Java>>正文


Java BasicOCSPResp.getResponses方法代码示例

本文整理汇总了Java中org.bouncycastle.cert.ocsp.BasicOCSPResp.getResponses方法的典型用法代码示例。如果您正苦于以下问题:Java BasicOCSPResp.getResponses方法的具体用法?Java BasicOCSPResp.getResponses怎么用?Java BasicOCSPResp.getResponses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.cert.ocsp.BasicOCSPResp的用法示例。


在下文中一共展示了BasicOCSPResp.getResponses方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetOCSPCertificateIDAndMatch

import org.bouncycastle.cert.ocsp.BasicOCSPResp; //导入方法依赖的package包/类
@Test
public void testGetOCSPCertificateIDAndMatch() throws IOException, OCSPException {
	CertificateToken certificate = DSSUtils.loadCertificate(new File("src/test/resources/citizen_ca.cer"));
	CertificateToken issuer = DSSUtils.loadCertificate(new File("src/test/resources/belgiumrs2.crt"));
	assertTrue(certificate.isSignedBy(issuer));

	CertificateID certificateID = DSSRevocationUtils.getOCSPCertificateID(certificate, issuer);
	assertNotNull(certificateID);

	BasicOCSPResp basicOCSPResp = DSSRevocationUtils.loadOCSPBase64Encoded(
			"MIIHOgoBAKCCBzMwggcvBgkrBgEFBQcwAQEEggcgMIIHHDCCATOhRDBCMQswCQYDVQQGEwJERTEaMBgGA1UECgwRQnVuZGVzbmV0emFnZW50dXIxFzAVBgNVBAMMDjE0Ui1PQ1NQIDEyOlBOGA8yMDE2MDQyNjA5NDE0M1owgbUwgbIwOzAJBgUrDgMCGgUABBRAEkWUqHsHRftOoCVj8/DhlIT7BwQU/fNQhDCO7COa9TOy44EH3eTvgK4CAgM0gAAYDzIwMTUwOTI5MDkwOTI4WqFgMF4wXAYFKyQIAw0EUzBRMA0GCWCGSAFlAwQCAwUABED48AGg2Q8uukS9H0fDCz8LSLzuISU1he4/rk1s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matches(certificateID, responses[0]));
}
 
开发者ID:esig,项目名称:dss,代码行数:17,代码来源:DSSRevocationUtilsTest.java

示例2: getResponses

import org.bouncycastle.cert.ocsp.BasicOCSPResp; //导入方法依赖的package包/类
private SingleResp[] getResponses(final BasicOCSPResp basicOCSPResp) {
	SingleResp[] responses = new SingleResp[] {};
	try {
		responses = basicOCSPResp.getResponses();
	} catch (Exception e) {
		LOG.error("Unable to parse the responses object from OCSP", e);
		extraInfo.infoOCSPException("Unable to parse the responses object from OCSP : " + e.getMessage());
	}
	return responses;
}
 
开发者ID:esig,项目名称:dss,代码行数:11,代码来源:OCSPToken.java

示例3: getOCSPToken

import org.bouncycastle.cert.ocsp.BasicOCSPResp; //导入方法依赖的package包/类
@Override
public final OCSPToken getOCSPToken(CertificateToken certificateToken, CertificateToken issuerCertificateToken) {
	final List<BasicOCSPResp> containedOCSPResponses = getContainedOCSPResponses();
	if (Utils.isCollectionEmpty(containedOCSPResponses)) {
		return null;
	}

	if (LOG.isTraceEnabled()) {
		final String dssIdAsString = certificateToken.getDSSIdAsString();
		LOG.trace("--> OfflineOCSPSource queried for " + dssIdAsString + " contains: " + containedOCSPResponses.size() + " element(s).");
	}

	Date bestUpdate = null;
	BasicOCSPResp bestBasicOCSPResp = null;
	final CertificateID certId = DSSRevocationUtils.getOCSPCertificateID(certificateToken, issuerCertificateToken);
	for (final BasicOCSPResp basicOCSPResp : containedOCSPResponses) {
		for (final SingleResp singleResp : basicOCSPResp.getResponses()) {
			if (DSSRevocationUtils.matches(certId, singleResp)) {
				final Date thisUpdate = singleResp.getThisUpdate();
				if ((bestUpdate == null) || thisUpdate.after(bestUpdate)) {
					bestBasicOCSPResp = basicOCSPResp;
					bestUpdate = thisUpdate;
				}
			}
		}
	}

	if (bestBasicOCSPResp != null) {
		OCSPToken ocspToken = new OCSPToken();
		ocspToken.setCertId(certId);
		ocspToken.setOrigin(RevocationOrigin.SIGNATURE);
		ocspToken.setBasicOCSPResp(bestBasicOCSPResp);
		return ocspToken;
	}
	return null;
}
 
开发者ID:esig,项目名称:dss,代码行数:37,代码来源:OfflineOCSPSource.java

示例4: getEncoded

import org.bouncycastle.cert.ocsp.BasicOCSPResp; //导入方法依赖的package包/类
/**
 * @return 	a byte array
 * @see com.lowagie.text.pdf.OcspClient#getEncoded()
 */
public byte[] getEncoded() {
    try {
        OCSPReq request = generateOCSPRequest(rootCert, checkCert.getSerialNumber());
        byte[] array = request.getEncoded();
        URL urlt = new URL(url);
        HttpURLConnection con = (HttpURLConnection)urlt.openConnection();
        con.setRequestProperty("Content-Type", "application/ocsp-request");
        con.setRequestProperty("Accept", "application/ocsp-response");
        con.setDoOutput(true);
        OutputStream out = con.getOutputStream();
        DataOutputStream dataOut = new DataOutputStream(new BufferedOutputStream(out));
        dataOut.write(array);
        dataOut.flush();
        dataOut.close();
        if (con.getResponseCode() / 100 != 2) {
            throw new IOException("Invalid HTTP response");
        }
        //Get Response
        InputStream in = (InputStream) con.getContent();
        OCSPResp ocspResponse = new OCSPResp(in);

        if (ocspResponse.getStatus() != 0)
            throw new IOException("Invalid status: " + ocspResponse.getStatus());
        BasicOCSPResp basicResponse = (BasicOCSPResp) ocspResponse.getResponseObject();
        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.cert.ocsp.RevokedStatus) {
                    throw new IOException("OCSP Status is revoked!");
                }
                else {
                    throw new IOException("OCSP Status is unknown!");
                }
            }
        }
    }
    catch (Exception ex) {
        throw new ExceptionConverter(ex);
    }
    return null;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:51,代码来源:OcspClientBouncyCastle.java

示例5: validateSuccessfulResponse

import org.bouncycastle.cert.ocsp.BasicOCSPResp; //导入方法依赖的package包/类
private void validateSuccessfulResponse(OCSPResp ocspResp,
                                        OCSPReq ocspReq,
                                        CertificateSummary... summaries) throws Exception {
    assertThat(summaries).isNotEmpty();

    assertThat(ocspResp.getStatus()).isEqualTo(OCSPRespBuilder.SUCCESSFUL);
    assertThat(ocspResp.getResponseObject()).isExactlyInstanceOf(BasicOCSPResp.class);
    BasicOCSPResp basicResponse = (BasicOCSPResp)ocspResp.getResponseObject();
    assertThat(basicResponse.getProducedAt()).isAfterOrEqualsTo(NOW.toDate());

    // check signature
    boolean validSignature = basicResponse.isSignatureValid(
            new JcaContentVerifierProviderBuilder().setProvider("BC").build(signingCertificate.getPublicKey()));
    assertThat(validSignature).isTrue().withFailMessage("Signature was invalid");
    assertThat(basicResponse.getSignatureAlgorithmID()).isEqualTo(
            new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA")
    );

    // check extensions
    List<ASN1ObjectIdentifier> extensionOIDs = Lists.transform(
            (List<?>) basicResponse.getExtensionOIDs(),
            input -> (ASN1ObjectIdentifier) input  // just casting here
    );
    assertThat(extensionOIDs).containsExactly(OCSPObjectIdentifiers.id_pkix_ocsp_nonce);

    Extension reqNonce = ocspReq.getExtension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce);
    Extension respNonce = basicResponse.getExtension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce);
    assertThat(respNonce).isEqualTo(reqNonce);

    SingleResp[] singleResponses = basicResponse.getResponses();
    Req[] singleRequests = ocspReq.getRequestList();
    assertThat(singleResponses).hasSameSizeAs(singleRequests);

    for (int i = 0; i < singleRequests.length; i++) {
        Req request = singleRequests[i];
        SingleResp response = singleResponses[i];

        assertThat(response.getCertID()).isEqualTo(request.getCertID());

        ASN1ObjectIdentifier[] requestExtensions = request.getSingleRequestExtensions().getExtensionOIDs();
        for (ASN1ObjectIdentifier extensionOID : requestExtensions) {
            Extension extension = response.getExtension(extensionOID);
            assertThat(extension).isNotNull();
            assertThat(extension).isEqualTo(request.getSingleRequestExtensions().getExtension(extensionOID));
        }

        assertThat(response.getCertID().getSerialNumber()).isEqualTo(summaries[i].getSerialNumber());
        org.bouncycastle.cert.ocsp.CertificateStatus ocspCertificateStatus =
                getOCSPCertificateStatus(summaries[i]).getCertificateStatus();
        if (ocspCertificateStatus == GOOD) {
            assertThat(response.getCertStatus()).isEqualTo(GOOD); // They implemented GOOD as null ... really? .....
        } else {
            assertThat(response.getCertStatus()).isEqualToComparingFieldByField(ocspCertificateStatus);
        }

        assertThat(response.getThisUpdate()).isEqualToIgnoringMillis(summaries[i].getThisUpdateTime().toDate());
        assertThat(response.getNextUpdate())
                .hasSecond((summaries[i].getThisUpdateTime().getSecondOfMinute() + REFRESH_TIME) % 60);
    }
}
 
开发者ID:wdawson,项目名称:revoker,代码行数:61,代码来源:OCSPResponderResourceTest.java

示例6: validate

import org.bouncycastle.cert.ocsp.BasicOCSPResp; //导入方法依赖的package包/类
@Override
public ValidationStatus validate(X509Certificate certificate, List<X509Certificate> issuers, Date validationDate) {
	X509Certificate issuer = issuers.get(0);
	ValidationStatus status = new ValidationStatus(certificate, issuer, validationDate, ValidatorSourceType.OCSP, CertificateValidity.UNKNOWN);

	try {
		Principal subjectX500Principal = certificate.getSubjectX500Principal();

		String ocspUrl = getOCSPUrl(certificate);
		if (ocspUrl == null) {
			log.error("OCSP URL for '" + subjectX500Principal + "' is empty");
			return status;
		}

		log.debug("OCSP URL for '" + subjectX500Principal + "' is '" + ocspUrl + "'");

		DigestCalculator digestCalculator = new JcaDigestCalculatorProviderBuilder().build().get(CertificateID.HASH_SHA1);
		CertificateID certificateId = new CertificateID(digestCalculator, new JcaX509CertificateHolder(certificate), certificate.getSerialNumber());

		// Generate OCSP request
		OCSPReq ocspReq = generateOCSPRequest(certificateId);

		// Get OCSP response from server
		OCSPResp ocspResp = requestOCSPResponse(ocspUrl, ocspReq);
		if (ocspResp.getStatus() != OCSPRespBuilder.SUCCESSFUL) {
			log.error("OCSP response is invalid!");
			status.setValidity(CertificateValidity.INVALID);
			return status;
		}

		boolean foundResponse = false;
		BasicOCSPResp basicOCSPResp = (BasicOCSPResp) ocspResp.getResponseObject();
		SingleResp[] singleResps = basicOCSPResp.getResponses();
		for (SingleResp singleResp : singleResps) {
			CertificateID responseCertificateId = singleResp.getCertID();
			if (!certificateId.equals(responseCertificateId)) {
				continue;
			}

			foundResponse = true;

			log.debug("OCSP validationDate: " + validationDate);
			log.debug("OCSP thisUpdate: " + singleResp.getThisUpdate());
			log.debug("OCSP nextUpdate: " + singleResp.getNextUpdate());

			status.setRevocationObjectIssuingTime(basicOCSPResp.getProducedAt());

			Object certStatus = singleResp.getCertStatus();
			if (certStatus == CertificateStatus.GOOD) {
				log.debug("OCSP status is valid for '" + certificate.getSubjectX500Principal() + "'");
				status.setValidity(CertificateValidity.VALID);
			} else {
				if (singleResp.getCertStatus() instanceof RevokedStatus) {
					log.warn("OCSP status is revoked for: " + subjectX500Principal);
					if (validationDate.before(((RevokedStatus) singleResp.getCertStatus()).getRevocationTime())) {
						log.warn("OCSP revocation time after the validation date, the certificate '" + subjectX500Principal + "' was valid at " + validationDate);
						status.setValidity(CertificateValidity.VALID);
					} else {
						Date revocationDate = ((RevokedStatus) singleResp.getCertStatus()).getRevocationTime();
						log.info("OCSP for certificate '" + subjectX500Principal + "' is revoked since " + revocationDate);
						status.setRevocationDate(revocationDate);
						status.setRevocationObjectIssuingTime(singleResp.getThisUpdate());
						status.setValidity(CertificateValidity.REVOKED);
					}
				}
			}
		}

		if (!foundResponse) {
			log.error("There is no matching OCSP response entries");
		}
	} catch (Exception ex) {
		log.error("OCSP exception: ", ex);
	}

	return status;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:78,代码来源:OCSPCertificateVerifier.java


注:本文中的org.bouncycastle.cert.ocsp.BasicOCSPResp.getResponses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。