OperatorCreationException, CertificateVerificationException, CertificateException TimeStampToken timeStampToken = new TimeStampToken(new CMSSignedData(contents.getBytes())); System.out.println("Time stamp gen time: " + timeStampToken.getTimeStampInfo().getGenTime()); System.out.println("Time stamp tsa name: " + timeStampToken.getTimeStampInfo().getTsa().getName());
private TimeStampToken extractTimeStampTokenFromSignerInformation(SignerInformation signerInformation) throws CMSException, IOException, TSPException { if (signerInformation.getUnsignedAttributes() == null) { return null; } AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes(); // https://stackoverflow.com/questions/1647759/how-to-validate-if-a-signed-jar-contains-a-timestamp Attribute attribute = unsignedAttributes.get( PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); if (attribute == null) { return null; } ASN1Object obj = (ASN1Object) attribute.getAttrValues().getObjectAt(0); CMSSignedData signedTSTData = new CMSSignedData(obj.getEncoded()); return new TimeStampToken(signedTSTData); }
TimeStampToken tsToken = new TimeStampToken( new CMSSignedData(tsSeq.getEncoded("DER")));
private TimeStampToken createTimeStampToken(final String base64EncodedTimestamp) throws DSSException { logger.debug("Creating timestamp token"); try { byte[] tokenBytes = Base64.decodeBase64(base64EncodedTimestamp); CMSSignedData signedData = new CMSSignedData(tokenBytes); return new TimeStampToken(signedData); } catch (Exception e) { logger.error("Error parsing timestamp token: " + e.getMessage()); throw new TechnicalException("Error parsing timestamp token", e); } }
TimeStampToken token = new TimeStampToken(new CMSSignedData(response)); InputStream in = new FileInputStream("tsp.cer"); CertificateFactory factory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) factory.generateCertificate(in); //RSA Signature processing with BC X509CertificateHolder holder = new X509CertificateHolder(cert.getEncoded()); SignerInformationVerifier siv = new BcRSASignerInfoVerifierBuilder(new DefaultDigestAlgorithmIdentifierFinder(), new BcDigestCalculatorProvider()).build(holder); //Signature processing with JCA and other provider //X509CertificateHolder holderJca = new JcaX509CertificateHolder(cert); //SignerInformationVerifier sivJca = new JcaSimpleSignerInfoVerifierBuilder().setProvider("anotherprovider").build(holderJca); token.validate(siv);
private TimeStampToken getTimeStamp(List<InMemoryDocument> documents) { try { CMSSignedData cms = new CMSSignedData(documents.stream() .filter(d -> d.getName().toUpperCase().endsWith(TIMESTAMP_FILE)).findAny().orElseThrow(IllegalArgumentException::new).getBytes()); return new TimeStampToken(cms); } catch (CMSException | TSPException | IOException e) { throw new MalformedDocumentException(e); } }
/** * The default constructor for ASiCXMLDocumentValidator. * * @param timestamp {@code DSSDocument} representing the timestamp to validate * @param detachedContents the {@code List} containing the potential signed documents * @throws eu.europa.ec.markt.dss.exception.DSSException */ public ASiCTimestampDocumentValidator(final DSSDocument timestamp, final List<DSSDocument> detachedContents) throws DSSException { super(timestamp); try { timeStampToken = new TimeStampToken(cmsSignedData); } catch (TSPException e) { throw new DSSException(e); } catch (IOException e) { throw new DSSException(e); } if (detachedContents == null || detachedContents.size() == 0) { throw new DSSNullException(DSSDocument.class, "detachedContents"); } timestampExternalContents = detachedContents; }
byte[] encodedTimestampToken = encapsulatedTimeStampToken .getValue(); timeStampTokens.add(new TimeStampToken(new CMSSignedData( encodedTimestampToken)));
private TimeStampToken getTimeStamp(AsicParseResult documents) { try { return new TimeStampToken(new CMSSignedData(documents.getTimeStampToken().getBytes())); } catch (CMSException | TSPException | IOException e) { throw new DigiDoc4JException("Document malformed or not matching documentType", e); } }
TSPException, NoSuchAlgorithmException, CertificateVerificationException TimeStampToken timeStampToken = new TimeStampToken(new CMSSignedData(contents.getBytes())); System.out.println("Time stamp gen time: " + timeStampToken.getTimeStampInfo().getGenTime()); System.out.println("Time stamp tsa name: " + timeStampToken.getTimeStampInfo().getTsa().getName());
/** * @param validationCertPool * @param outerCatalog the PDF Dict of the outer document, if the PDFDocument in a enclosed revision. Can be null. * @param document the signed PDFDocument * @param cms the CMS (CAdES) bytes * @param inputStream the stream of the whole signed document * @throws IOException */ PdfBoxDocTimestampInfo(CertificatePool validationCertPool, PdfDict outerCatalog, PDDocument document, PDSignature signature, byte[] cms, InputStream inputStream) throws DSSException, IOException { super(validationCertPool, outerCatalog, document, signature, cms, inputStream); try { TimeStampToken timeStampToken = new TimeStampToken(new CMSSignedData(cms)); TimestampType timestampType = TimestampType.SIGNATURE_TIMESTAMP; if (document.getDocumentCatalog().getCOSDictionary().containsKey("DSS")) { timestampType = TimestampType.ARCHIVE_TIMESTAMP; } timestampToken = new TimestampToken(timeStampToken, timestampType, validationCertPool); if (LOG.isDebugEnabled()) { LOG.debug("Created PdfBoxDocTimestampInfo {}: {}", timestampType, uniqueId()); } } catch (CMSException e) { throw new DSSException(e); } catch (TSPException e) { throw new DSSException(e); } catch (IOException e) { throw new DSSException(e); } }
/** * This method generates a bouncycastle {@code TimeStampToken} based on base 64 encoded {@code String}. * * @param base64EncodedTimestamp * @return bouncycastle {@code TimeStampToken} * @throws DSSException */ public static TimeStampToken createTimeStampToken(final String base64EncodedTimestamp) throws DSSException { try { final byte[] tokenBytes = DSSUtils.base64Decode(base64EncodedTimestamp); final CMSSignedData signedData = new CMSSignedData(tokenBytes); return new TimeStampToken(signedData); } catch (DSSException e) { throw new DSSException(e); } catch (CMSException e) { throw new DSSException(e); } catch (TSPException e) { throw new DSSException(e); } catch (IOException e) { throw new DSSException(e); } }
private TimeStampToken extractTimeStampTokenFromSignerInformation(SignerInformation signerInformation) throws CMSException, IOException, TSPException { if (signerInformation.getUnsignedAttributes() == null) { return null; } AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes(); // https://stackoverflow.com/questions/1647759/how-to-validate-if-a-signed-jar-contains-a-timestamp Attribute attribute = unsignedAttributes.get( PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); ASN1Object obj = (ASN1Object) attribute.getAttrValues().getObjectAt(0); CMSSignedData signedTSTData = new CMSSignedData(obj.getEncoded()); return new TimeStampToken(signedTSTData); }
TimeStampToken timeStampToken = new TimeStampToken(new CMSSignedData(response)); CMSSignedData s = timeStampToken.toCMSSignedData();
TimeStampToken timestampToken = new TimeStampToken(new CMSSignedData( encodedTimestampToken)); CertStore certStore = timestampToken.getCertificatesAndCRLs(
private List<TimestampToken> createTimestamps(final ASN1ObjectIdentifier attrType, final TimestampType timestampType, final ArchiveTimestampType archiveTimestampType) { final List<TimestampToken> timestampTokenList = new ArrayList<TimestampToken>(); final AttributeTable attributes = attrType.equals(id_aa_ets_contentTimestamp) ? signerInformation.getSignedAttributes() : signerInformation.getUnsignedAttributes(); if (attributes != null) { final ASN1EncodableVector allAttributes = attributes.getAll(attrType); for (int ii = 0; ii < allAttributes.size(); ii++) { final Attribute attribute = (Attribute) allAttributes.get(ii); final ASN1Set attrValues = attribute.getAttrValues(); for (final ASN1Encodable value : attrValues.toArray()) { try { final byte[] encoded = value.toASN1Primitive().getEncoded(); // getEncoded(ASN1Encoding.DER) final CMSSignedData signedData = new CMSSignedData(encoded); final TimeStampToken token = new TimeStampToken(signedData); final TimestampToken timestampToken = new TimestampToken(token, timestampType, certPool); timestampToken.setArchiveTimestampType(archiveTimestampType); timestampTokenList.add(timestampToken); } catch (Exception e) { throw new DSSException(e); } } } } return timestampTokenList; }
public void validate(byte[] content, byte[] timeStamp, byte[] hash) throws CertificateCoreException { try { TimeStampToken timeStampToken = new TimeStampToken(new CMSSignedData(timeStamp)); CMSSignedData s = timeStampToken.toCMSSignedData();
TimeStampToken tsToken = new TimeStampToken( new CMSSignedData(tsSeq.getEncoded("DER")));
ContentInfo tsContentInfo = ContentInfo.getInstance(asn1is.readObject()); asn1is.close(); tsToken = new TimeStampToken(tsContentInfo); } catch (IOException ex)
/** * Remove any archive-timestamp-v2/3 attribute added after the timestampToken */ private ASN1Sequence filterUnauthenticatedAttributes(ASN1Set unauthenticatedAttributes, TimestampToken timestampToken) { ASN1EncodableVector result = new ASN1EncodableVector(); for (int ii = 0; ii < unauthenticatedAttributes.size(); ii++) { final Attribute attribute = Attribute.getInstance(unauthenticatedAttributes.getObjectAt(ii)); final ASN1ObjectIdentifier attrType = attribute.getAttrType(); if (id_aa_ets_archiveTimestampV2.equals(attrType) || id_aa_ets_archiveTimestampV3.equals(attrType)) { try { TimeStampToken token = new TimeStampToken(new CMSSignedData(DSSASN1Utils.getDEREncoded(attribute.getAttrValues().getObjectAt(0).toASN1Primitive()))); if (!token.getTimeStampInfo().getGenTime().before(timestampToken.getGenerationTime())) { continue; } } catch (Exception e) { throw new DSSException(e); } } result.add(unauthenticatedAttributes.getObjectAt(ii)); } return new DERSequence(result); }