Beispiel #1
0
 private void addSignatures(SimpleReport simpleReport) throws DSSException {
   validSignatureCount = 0;
   totalSignatureCount = 0;
   List<SignatureWrapper> signatures = diagnosticData.getSignatures();
   for (SignatureWrapper signature : signatures) {
     addSignature(simpleReport, signature);
   }
 }
Beispiel #2
0
  private void validatePolicy(Reports reports) {
    DiagnosticData diagnosticData = reports.getDiagnosticData();

    List<SignatureWrapper> signatures = diagnosticData.getSignatures();
    SignatureWrapper signatureWrapper = signatures.get(0);

    String policyId = diagnosticData.getPolicyId();
    assertEquals("2.16.724.1.3.1.1.2.1.9", policyId);
    assertEquals(
        "https://sede.060.gob.es/politica_de_firma_anexo_1.pdf", signatureWrapper.getPolicyUrl());
    assertFalse(signatureWrapper.isPolicyAsn1Processable());
    assertTrue(signatureWrapper.isPolicyIdentified());
    assertTrue(signatureWrapper.isPolicyStatus());
  }
  @Test
  public void test() throws Exception {
    DSSDocument documentToSign = new InMemoryDocument("Hello World".getBytes());

    CertificateService certificateService = new CertificateService();
    MockPrivateKeyEntry privateKeyEntry =
        certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);

    CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters();
    signatureParameters.bLevel().setSigningDate(new Date());
    signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
    signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
    signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
    signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_LTA);

    CertificateVerifier certificateVerifier = new CommonCertificateVerifier();
    CAdESService service = new CAdESService(certificateVerifier);
    service.setTspSource(
        new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1)));

    ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters);
    SignatureValue signatureValue =
        TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned);
    final DSSDocument signedDocument =
        service.signDocument(documentToSign, signatureParameters, signatureValue);

    SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument);
    validator.setCertificateVerifier(new CommonCertificateVerifier());

    Reports report = validator.validateDocument();
    // report.print();
    DiagnosticData diagnostic = report.getDiagnosticData();
    String timestampId = diagnostic.getSignatures().get(0).getTimestampList().get(0).getId();
    for (TimestampWrapper wrapper : diagnostic.getTimestampList(diagnostic.getFirstSignatureId())) {
      if (wrapper.getType().equals(TimestampType.ARCHIVE_TIMESTAMP.toString())) {
        Assert.assertEquals(
            timestampId, wrapper.getSignedObjects().getTimestampedTimestamp().get(0).getId());
      }
    }
  }