Esempio n. 1
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());
  }
Esempio n. 2
0
 /** Here we determine the type of the signature. */
 private void addSignatureProfile(SignatureWrapper signature, XmlSignature xmlSignature) {
   SignatureType signatureType = SignatureType.NA;
   String certificateId = signature.getSigningCertificateId();
   if (certificateId != null) {
     signatureType = getSignatureType(certificateId);
   }
   xmlSignature.setSignatureLevel(signatureType.name());
 }
Esempio n. 3
0
 public void init(DiagnosticData diagnosticData, Date currentTime) {
   Set<SignatureWrapper> signatures = diagnosticData.getAllSignatures();
   for (SignatureWrapper signature : signatures) {
     addPOE(signature.getId(), currentTime);
   }
   Set<TimestampWrapper> timestamps = diagnosticData.getAllTimestamps();
   for (TimestampWrapper timestamp : timestamps) {
     addPOE(timestamp.getId(), currentTime);
   }
   List<CertificateWrapper> usedCertificates = diagnosticData.getUsedCertificates();
   for (CertificateWrapper certificate : usedCertificates) {
     addPOE(certificate.getId(), currentTime);
     Set<RevocationWrapper> revocations = certificate.getRevocationData();
     if (CollectionUtils.isNotEmpty(revocations)) {
       for (RevocationWrapper revocation : revocations) {
         if (RevocationOrigin.SIGNATURE.name().equals(revocation.getOrigin())) {
           addPOE(revocation.getId(), currentTime);
         }
       }
     }
   }
 }
Esempio n. 4
0
 private void addSignatureScope(
     final SignatureWrapper diagnosticSignature, final XmlSignature xmlSignature) {
   XmlSignatureScopes signatureScopes = diagnosticSignature.getSignatureScopes();
   if (signatureScopes != null
       && CollectionUtils.isNotEmpty(signatureScopes.getSignatureScope())) {
     for (XmlSignatureScopeType scopeType : signatureScopes.getSignatureScope()) {
       XmlSignatureScope scope = new XmlSignatureScope();
       scope.setName(scopeType.getName());
       scope.setScope(scopeType.getScope());
       scope.setValue(scopeType.getValue());
       xmlSignature.getSignatureScope().add(scope);
     }
   }
 }
Esempio n. 5
0
 private void addSignedBy(
     final SignatureWrapper diagnosticSignature, final XmlSignature xmlSignature) {
   String unknown = "?";
   String signedBy = unknown;
   String certificateId = diagnosticSignature.getSigningCertificateId();
   if (StringUtils.isNotEmpty(certificateId)) {
     signedBy = diagnosticData.getUsedCertificateById(certificateId).getCommonName();
     if (signedBy.equals(StringUtils.EMPTY)) {
       signedBy = diagnosticData.getUsedCertificateById(certificateId).getGivenName();
       if (signedBy.equals(StringUtils.EMPTY)) {
         signedBy = diagnosticData.getUsedCertificateById(certificateId).getSurname();
         if (signedBy.equals(StringUtils.EMPTY)) {
           signedBy = diagnosticData.getUsedCertificateById(certificateId).getPseudo();
           if (signedBy.equals(StringUtils.EMPTY)) {
             signedBy = unknown;
           }
         }
       }
     }
   }
   xmlSignature.setSignedBy(signedBy);
 }
Esempio n. 6
0
 private void addSignatureFormat(
     final SignatureWrapper diagnosticSignature, final XmlSignature xmlSignature) {
   xmlSignature.setSignatureFormat(diagnosticSignature.getSignatureFormat());
 }
Esempio n. 7
0
 private void addSigningTime(
     final SignatureWrapper diagnosticSignature, final XmlSignature xmlSignature) {
   xmlSignature.setSigningTime(diagnosticSignature.getDateTime());
 }
Esempio n. 8
0
 private void addCounterSignature(SignatureWrapper signature, XmlSignature xmlSignature) {
   if (AttributeValue.COUNTERSIGNATURE.equals(signature.getType())) {
     xmlSignature.setType(AttributeValue.COUNTERSIGNATURE);
     xmlSignature.setParentId(signature.getParentId());
   }
 }
Esempio n. 9
0
  /**
   * @param simpleReport
   * @param signature the diagnosticSignature element in the diagnostic data
   * @throws DSSException
   */
  private void addSignature(SimpleReport simpleReport, SignatureWrapper signature)
      throws DSSException {

    totalSignatureCount++;

    String signatureId = signature.getId();
    XmlSignature xmlSignature = new XmlSignature();
    xmlSignature.setId(signatureId);

    addCounterSignature(signature, xmlSignature);
    addSignatureScope(signature, xmlSignature);
    addSigningTime(signature, xmlSignature);
    addSignatureFormat(signature, xmlSignature);
    addSignedBy(signature, xmlSignature);

    XmlConstraintsConclusion constraintsConclusion = null;
    switch (validationLevel) {
      case BASIC_SIGNATURES:
      case TIMESTAMPS:
        constraintsConclusion = getBasicSignatureValidationConclusion(signatureId);
        break;
      case LONG_TERM_DATA:
        constraintsConclusion = getLongTermDataValidationConclusion(signatureId);
        break;
      case ARCHIVAL_DATA:
        constraintsConclusion = getArchivalValidationConclusion(signatureId);
        break;
      default:
        logger.error("Unsupported validation level : " + validationLevel);
        break;
    }

    Indication indication = constraintsConclusion.getConclusion().getIndication();
    SubIndication subIndication = constraintsConclusion.getConclusion().getSubIndication();

    List<String> errorList = xmlSignature.getErrors();

    XmlConclusion conclusion = constraintsConclusion.getConclusion();
    List<XmlName> errors = conclusion.getErrors();
    if (CollectionUtils.isNotEmpty(errors)) {
      for (XmlName error : errors) {
        errorList.add(error.getValue());
      }
    }

    // TODO refactor
    xmlSignature.getWarnings().addAll(getWarnings(signatureId));
    xmlSignature.getInfos().addAll(getInfos(signatureId));

    if (Indication.PASSED.equals(indication)) {
      validSignatureCount++;
      xmlSignature.setIndication(Indication.TOTAL_PASSED);
    } else if (Indication.FAILED.equals(indication)) {
      xmlSignature.setIndication(Indication.TOTAL_FAILED);
    } else {
      xmlSignature.setIndication(indication); // INDERTERMINATE
    }
    xmlSignature.setSubIndication(subIndication);

    addSignatureProfile(signature, xmlSignature);

    simpleReport.getSignature().add(xmlSignature);
  }