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


Java TimeStampResponse类代码示例

本文整理汇总了Java中org.bouncycastle.tsp.TimeStampResponse的典型用法代码示例。如果您正苦于以下问题:Java TimeStampResponse类的具体用法?Java TimeStampResponse怎么用?Java TimeStampResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getTimestampViaSpy

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的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")));
}
 
开发者ID:open-eid,项目名称:digidoc4j,代码行数:20,代码来源:SkDataLoaderTest.java

示例2: responseParse

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的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");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:ParseTest.java

示例3: unacceptableResponseParse

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的package包/类
private void unacceptableResponseParse(
    byte[]  response) 
    throws Exception
{
    TimeStampResponse resp = new TimeStampResponse(response);

    if (resp.getStatus() != PKIStatus.REJECTION)
    {
        fail("request not rejected.");
    }
    
    if (resp.getFailInfo().intValue() != PKIFailureInfo.unacceptedPolicy)
    {
        fail("request not rejected.");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:17,代码来源:ParseTest.java

示例4: testTimestampServerTrust

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的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);
}
 
开发者ID:e-Contract,项目名称:jtrust,代码行数:70,代码来源:TSATest.java

示例5: generalizedTimeParse

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的package包/类
private void generalizedTimeParse(
    byte[]  response) 
    throws Exception
{
    TimeStampResponse resp = new TimeStampResponse(response);

    if (resp.getStatus() != PKIStatus.GRANTED)
    {
        fail("request not rejected.");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:12,代码来源:ParseTest.java

示例6: v2SigningResponseParse

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的package包/类
private void v2SigningResponseParse(
    byte[] encoded)
    throws Exception
{
    TimeStampResponse response = new TimeStampResponse(encoded);

    Store store = response.getTimeStampToken().getCertificates();
    X509CertificateHolder cert = (X509CertificateHolder)store.getMatches(response.getTimeStampToken().getSID()).iterator().next();

    response.getTimeStampToken().validate(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:12,代码来源:ParseTest.java

示例7: parse

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的package包/类
public void parse(
    byte[]  encoded,
    boolean tokenPresent)
    throws Exception
{
    TimeStampResponse   response = new TimeStampResponse(encoded);

    if (tokenPresent && response.getTimeStampToken() == null)
    {
        fail("token not found when expected.");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:13,代码来源:ParseTest.java

示例8: validate

import org.bouncycastle.tsp.TimeStampResponse; //导入依赖的package包/类
/**
 * Efetua a validacao de um carimbo de tempo
 *
 * @param response O carimbo de tempo a ser validado
 * @throws TimestampException
 */
public void validate(byte[] response) throws TimestampException {
    try {
        Security.addProvider(new BouncyCastleProvider());
        TimeStampResponse tsr = new TimeStampResponse(response);
        TimeStampToken timeStampToken = tsr.getTimeStampToken();
        CMSSignedData s = timeStampToken.toCMSSignedData();

        int verified = 0;

        Store certStore = s.getCertificates();
        SignerInformationStore signers = s.getSignerInfos();
        Collection c = signers.getSigners();
        Iterator it = c.iterator();

        while (it.hasNext()) {
            SignerInformation signer = (SignerInformation) it.next();
            Collection certCollection = certStore.getMatches(signer.getSID());
            Iterator certIt = certCollection.iterator();
            X509CertificateHolder cert = (X509CertificateHolder) certIt.next();
            if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert))) {
                verified++;
            }

            cert.getExtension(new ASN1ObjectIdentifier("2.5.29.31")).getExtnValue();
        }

        logger.info("Assinaturas Verificadas....: {}", verified);
        this.timestamp = new Timestamp(timeStampToken);
    } catch (TSPException | IOException | CMSException | OperatorCreationException | CertificateException ex) {
        throw new TimestampException(ex.getMessage());
    }
}
 
开发者ID:humbertopacheco,项目名称:timestamp,代码行数:39,代码来源:TimestampGenerator.java


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