@Test public void should_sign_a_time_stamp_request() throws TSPException, CertificateEncodingException, OperatorCreationException, IOException { final TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); reqGen.setCertReq(true); final byte[] hash = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; final BigInteger nonce = BigInteger.TEN; final TimeStampRequest request = reqGen.generate(TSPAlgorithms.SHA1, hash, nonce); final TimeStampResponse timeStampResponse = timeStampSignatureWithKeystore.sign(request); final TimeStampToken timeStampToken = timeStampResponse.getTimeStampToken(); assertThat(timeStampResponse.getStatus()).isEqualTo(0); assertThat(timeStampResponse.getEncoded()).isNotNull(); assertThat(timeStampToken.getTimeStampInfo().getNonce()).isEqualTo(nonce); assertThat(timeStampToken.getTimeStampInfo().getMessageImprintDigest()).isEqualTo(hash); assertThat(timeStampToken.getCertificates().getMatches(null)).hasSize(2); }
@Override public TimeStampResponse sign(TimeStampRequest request) throws OperatorCreationException, TSPException, CertificateEncodingException { final DigestCalculator digestCalculator = digestCalculatorProvider.get(new AlgorithmIdentifier(request.getMessageImprintAlgOID())); final String tspAlgorithm = computeTspAlgorithm(key, VitamConfiguration.getDefaultTimestampDigestType()); final SignerInfoGenerator signerInfoGen = new JcaSimpleSignerInfoGeneratorBuilder().build(tspAlgorithm, key, (X509Certificate) certificateChain[0]); final ASN1ObjectIdentifier tsaPolicy = new ASN1ObjectIdentifier(tspPolicy); final TimeStampTokenGenerator tokenGen = new TimeStampTokenGenerator(signerInfoGen, digestCalculator, tsaPolicy); tokenGen.addCertificates(new JcaCertStore(Arrays.asList(certificateChain))); final TimeStampResponseGenerator timeStampResponseGenerator = new TimeStampResponseGenerator(tokenGen, TSPAlgorithms.ALLOWED); final Date currentDate = LocalDateUtil.getDate(LocalDateUtil.now()); return timeStampResponseGenerator.generate(request, BigInteger.ONE, currentDate); }
TimeStampSignatureWithKeystore implements TimeStampSignature { @Override public TimeStampResponse sign(TimeStampRequest request) throws OperatorCreationException, TSPException, CertificateEncodingException { final DigestCalculator digestCalculator = digestCalculatorProvider.get(new AlgorithmIdentifier(request.getMessageImprintAlgOID())); final String tspAlgorithm = computeTspAlgorithm(key, VitamConfiguration.getDefaultTimestampDigestType()); final SignerInfoGenerator signerInfoGen = new JcaSimpleSignerInfoGeneratorBuilder().build(tspAlgorithm, key, (X509Certificate) certificateChain[0]); final ASN1ObjectIdentifier tsaPolicy = new ASN1ObjectIdentifier(tspPolicy); final TimeStampTokenGenerator tokenGen = new TimeStampTokenGenerator(signerInfoGen, digestCalculator, tsaPolicy); tokenGen.addCertificates(new JcaCertStore(Arrays.asList(certificateChain))); final TimeStampResponseGenerator timeStampResponseGenerator = new TimeStampResponseGenerator(tokenGen, TSPAlgorithms.ALLOWED); final Date currentDate = LocalDateUtil.getDate(LocalDateUtil.now()); return timeStampResponseGenerator.generate(request, BigInteger.ONE, currentDate); } }
TimeStampSignatureWithKeystore implements TimeStampSignature { @Override public TimeStampResponse sign(TimeStampRequest request) throws OperatorCreationException, TSPException, CertificateEncodingException { final DigestCalculator digestCalculator = digestCalculatorProvider.get(new AlgorithmIdentifier(request.getMessageImprintAlgOID())); final String tspAlgorithm = computeTspAlgorithm(key, VitamConfiguration.getDefaultTimestampDigestType()); final SignerInfoGenerator signerInfoGen = new JcaSimpleSignerInfoGeneratorBuilder().build(tspAlgorithm, key, (X509Certificate) certificateChain[0]); final ASN1ObjectIdentifier tsaPolicy = new ASN1ObjectIdentifier(tspPolicy); final TimeStampTokenGenerator tokenGen = new TimeStampTokenGenerator(signerInfoGen, digestCalculator, tsaPolicy); tokenGen.addCertificates(new JcaCertStore(Arrays.asList(certificateChain))); final TimeStampResponseGenerator timeStampResponseGenerator = new TimeStampResponseGenerator(tokenGen, TSPAlgorithms.ALLOWED); final Date currentDate = LocalDateUtil.getDate(LocalDateUtil.now()); return timeStampResponseGenerator.generate(request, BigInteger.ONE, currentDate); } TimeStampSignatureWithKeystore(File pkcs12Path, char[] keystorePassword); }
TimeStampSignatureWithKeystore implements TimeStampSignature { @Override public TimeStampResponse sign(TimeStampRequest request) throws OperatorCreationException, TSPException, CertificateEncodingException { final DigestCalculator digestCalculator = digestCalculatorProvider.get(new AlgorithmIdentifier(request.getMessageImprintAlgOID())); final String tspAlgorithm = computeTspAlgorithm(key, VitamConfiguration.getDefaultTimestampDigestType()); final SignerInfoGenerator signerInfoGen = new JcaSimpleSignerInfoGeneratorBuilder().build(tspAlgorithm, key, (X509Certificate) certificateChain[0]); final ASN1ObjectIdentifier tsaPolicy = new ASN1ObjectIdentifier(tspPolicy); final TimeStampTokenGenerator tokenGen = new TimeStampTokenGenerator(signerInfoGen, digestCalculator, tsaPolicy); tokenGen.addCertificates(new JcaCertStore(Arrays.asList(certificateChain))); final TimeStampResponseGenerator timeStampResponseGenerator = new TimeStampResponseGenerator(tokenGen, TSPAlgorithms.ALLOWED); final Date currentDate = LocalDateUtil.getDate(LocalDateUtil.now()); return timeStampResponseGenerator.generate(request, BigInteger.ONE, currentDate); } TimeStampSignatureWithKeystore(File pkcs12Path, char[] keystorePassword); @Override TimeStampResponse sign(TimeStampRequest request); }
TimeStampSignatureWithKeystore implements TimeStampSignature { @Override public TimeStampResponse sign(TimeStampRequest request) throws OperatorCreationException, TSPException, CertificateEncodingException { final DigestCalculator digestCalculator = digestCalculatorProvider.get(new AlgorithmIdentifier(request.getMessageImprintAlgOID())); final String tspAlgorithm = computeTspAlgorithm(key, VitamConfiguration.getDefaultTimestampDigestType()); final SignerInfoGenerator signerInfoGen = new JcaSimpleSignerInfoGeneratorBuilder().build(tspAlgorithm, key, (X509Certificate) certificateChain[0]); final ASN1ObjectIdentifier tsaPolicy = new ASN1ObjectIdentifier(tspPolicy); final TimeStampTokenGenerator tokenGen = new TimeStampTokenGenerator(signerInfoGen, digestCalculator, tsaPolicy); tokenGen.addCertificates(new JcaCertStore(Arrays.asList(certificateChain))); final TimeStampResponseGenerator timeStampResponseGenerator = new TimeStampResponseGenerator(tokenGen, TSPAlgorithms.ALLOWED); final Date currentDate = LocalDateUtil.getDate(LocalDateUtil.now()); return timeStampResponseGenerator.generate(request, BigInteger.ONE, currentDate); } TimeStampSignatureWithKeystore(File pkcs12Path, char[] keystorePassword); @Override TimeStampResponse sign(TimeStampRequest request);  }