本文整理汇总了Java中org.bouncycastle.tsp.TimeStampRequest类的典型用法代码示例。如果您正苦于以下问题:Java TimeStampRequest类的具体用法?Java TimeStampRequest怎么用?Java TimeStampRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeStampRequest类属于org.bouncycastle.tsp包,在下文中一共展示了TimeStampRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTimeStampToken
import org.bouncycastle.tsp.TimeStampRequest; //导入依赖的package包/类
public static TimeStampToken createTimeStampToken(PrivateKey privateKey, List<X509Certificate> certificateChain)
throws Exception {
Store certs = new JcaCertStore(certificateChain);
TimeStampRequestGenerator requestGen = new TimeStampRequestGenerator();
requestGen.setCertReq(true);
TimeStampRequest request = requestGen.generate(TSPAlgorithms.SHA1, new byte[20], BigInteger.valueOf(100));
TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(
new JcaSimpleSignerInfoGeneratorBuilder().build("SHA1withRSA", privateKey, certificateChain.get(0)),
new JcaDigestCalculatorProviderBuilder().build()
.get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1)),
new ASN1ObjectIdentifier("1.2"));
tsTokenGen.addCertificates(certs);
return tsTokenGen.generate(request, BigInteger.ONE, new Date());
}
示例2: getTimestampViaSpy
import org.bouncycastle.tsp.TimeStampRequest; //导入依赖的package包/类
@Test
public void getTimestampViaSpy() throws Exception {
stubFor(post(urlEqualTo("/"))
.willReturn(aResponse()
.proxiedFrom(configuration.getTspSource())));
byte[] tsRequest = new byte[]{48, 57, 2, 1, 1, 48, 49, 48, 13, 6, 9, 96, -122, 72, 1, 101, 3, 4, 2, 1, 5, 0, 4, 32, 2, 91, 64, 111, 35, -23, -19, -46, 57, -80, -63, -80, -74, 100, 72, 97, -47, -17, -35, -62, 102, 52, 116, 73, -10, -120, 115, 62, 2, 87, -29, -21, 1, 1, -1};
SkDataLoader dataLoader = SkDataLoader.createTimestampDataLoader(configuration);
dataLoader.setUserAgentSignatureProfile(SignatureProfile.LT);
byte[] response = dataLoader.post(MOCK_PROXY_URL, tsRequest);
assertNotNull(response);
TimeStampResponse timeStampResponse = new TimeStampResponse(response);
assertEquals(0, timeStampResponse.getStatus());
timeStampResponse.validate(new TimeStampRequest(tsRequest));
verify(postRequestedFor(urlMatching("/")).
withHeader("Content-Type", containing("application/timestamp-query")).
withHeader("User-Agent", containing("LIB DigiDoc4j")));
}
示例3: responseParse
import org.bouncycastle.tsp.TimeStampRequest; //导入依赖的package包/类
private void responseParse(
byte[] request,
byte[] response,
ASN1ObjectIdentifier algorithm)
throws Exception
{
TimeStampRequest req = new TimeStampRequest(request);
TimeStampResponse resp = new TimeStampResponse(response);
CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");
X509Certificate cert = (X509Certificate)fact.generateCertificate(new ByteArrayInputStream(signingCert));
resp.validate(req);
resp.getTimeStampToken().validate(cert, "BC");
}
示例4: testTimestampServerTrust
import org.bouncycastle.tsp.TimeStampRequest; //导入依赖的package包/类
private void testTimestampServerTrust(String tsaLocation) throws Exception {
// setup
TimeStampRequestGenerator requestGen = new TimeStampRequestGenerator();
requestGen.setCertReq(true);
TimeStampRequest request = requestGen.generate(TSPAlgorithms.SHA1,
new byte[20], BigInteger.valueOf(100));
byte[] requestData = request.getEncoded();
DefaultHttpClient httpClient = new DefaultHttpClient();
// HttpHost proxy = new HttpHost("proxy.yourict.net", 8080);
// httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
// proxy);
HttpPost postMethod = new HttpPost(tsaLocation);
ContentType contentType = ContentType
.create("application/timestamp-query");
HttpEntity requestEntity = new ByteArrayEntity(requestData, contentType);
postMethod.addHeader("User-Agent", "jTrust TSP Client");
postMethod.setEntity(requestEntity);
// operate
long t0 = System.currentTimeMillis();
HttpResponse httpResponse = httpClient.execute(postMethod);
StatusLine statusLine = httpResponse.getStatusLine();
int statusCode = statusLine.getStatusCode();
long t1 = System.currentTimeMillis();
LOG.debug("dt TSP: " + (t1 - t0) + " ms");
if (statusCode != HttpURLConnection.HTTP_OK) {
LOG.error("Error contacting TSP server " + TSA_LOCATION);
throw new Exception("Error contacting TSP server " + TSA_LOCATION);
}
HttpEntity httpEntity = httpResponse.getEntity();
TimeStampResponse tspResponse = new TimeStampResponse(
httpEntity.getContent());
postMethod.releaseConnection();
TimeStampToken timeStampToken = tspResponse.getTimeStampToken();
SignerId signerId = timeStampToken.getSID();
Store certificatesStore = timeStampToken.getCertificates();
Collection<X509CertificateHolder> signerCollection = certificatesStore
.getMatches(signerId);
Iterator<X509CertificateHolder> signerCollectionIterator = signerCollection
.iterator();
X509CertificateHolder signerCertificateHolder = signerCollectionIterator
.next();
// TODO: check time-stamp token signature
List<X509Certificate> certificateChain = getCertificateChain(
signerCertificateHolder, certificatesStore);
for (X509Certificate cert : certificateChain) {
LOG.debug("certificate subject: " + cert.getSubjectX500Principal());
LOG.debug("certificate issuer: " + cert.getIssuerX500Principal());
}
CertificateRepository certificateRepository = BelgianTrustValidatorFactory
.createTSACertificateRepository();
TrustValidator trustValidator = new TrustValidator(
certificateRepository);
// NetworkConfig networkConfig = new NetworkConfig("proxy.yourict.net",
// 8080);
TrustValidatorDecorator trustValidatorDecorator = new TrustValidatorDecorator(
null);
trustValidatorDecorator.addDefaultTrustLinkerConfig(trustValidator);
trustValidator.isTrusted(certificateChain);
}
示例5: requestParse
import org.bouncycastle.tsp.TimeStampRequest; //导入依赖的package包/类
private void requestParse(
byte[] request,
ASN1ObjectIdentifier algorithm)
throws IOException
{
TimeStampRequest req = new TimeStampRequest(request);
if (!req.getMessageImprintAlgOID().equals(algorithm))
{
fail("failed to get expected algorithm - got "
+ req.getMessageImprintAlgOID() + " not " + algorithm);
}
if (request != sha1Request && request != sha1noNonse)
{
if (!req.getReqPolicy().equals(TSPTestUtil.EuroPKI_TSA_Test_Policy))
{
fail("" + algorithm + " failed policy check.");
}
if (request == ripemd160Request)
{
if (!req.getCertReq())
{
fail("" + algorithm + " failed certReq check.");
}
}
}
assertEquals("version not 1", 1, req.getVersion());
assertEquals("critical extensions found when none expected", 0, req.getCriticalExtensionOIDs().size());
assertEquals("non-critical extensions found when none expected", 0, req.getNonCriticalExtensionOIDs().size());
if (request != sha1noNonse)
{
if (req.getNonce() == null)
{
fail("" + algorithm + " nonse not found when one expected.");
}
}
else
{
if (req.getNonce() != null)
{
fail("" + algorithm + " nonse not found when one not expected.");
}
}
try
{
req.validate(TSPAlgorithms.ALLOWED, null, null, "BC");
}
catch (Exception e)
{
fail("validation exception.");
}
if (!Arrays.areEqual(req.getEncoded(), request))
{
fail("" + algorithm + " failed encode check.");
}
}