TimeStampTokenValidationService implements ValidationService { @Override public Reports validateDocument(ValidationDocument validationDocument) { List<InMemoryDocument> documents = getFilesFromContainer(validationDocument); validateContainer(documents); TimeStampToken timeStampToken = getTimeStamp(documents); List<Error> errors = validateTimeStamp(documents, timeStampToken); TimeStampTokenValidationReportBuilder reportBuilder = new TimeStampTokenValidationReportBuilder(validationDocument, timeStampToken, signaturePolicyService.getPolicy(validationDocument.getSignaturePolicy()), errors, reportConfigurationProperties.isReportSignatureEnabled()); return reportBuilder.build(); }  @Override Reports validateDocument(ValidationDocument validationDocument); @Autowired @Qualifier("timestampPolicyService") void setSignaturePolicyService(SignaturePolicyService<ValidationPolicy> signaturePolicyService); @Autowired void setReportConfigurationProperties(ReportConfigurationProperties reportConfigurationProperties);  }
@Test public void validTimeStampToken() { SimpleReport simpleReport = validationService.validateDocument(buildValidationDocument("timestamptoken-ddoc.asics")).getSimpleReport(); TimeStampTokenValidationData validationData = simpleReport.getValidationConclusion().getTimeStampTokens().get(0); Assert.assertEquals(TimeStampTokenValidationData.Indication.TOTAL_PASSED, validationData.getIndication()); Assert.assertEquals("SK TIMESTAMPING AUTHORITY", validationData.getSignedBy()); Assert.assertNull(validationData.getError()); }
@Test public void certificatePresent() throws Exception{ SimpleReport simpleReport = validationService.validateDocument(buildValidationDocument("timestamptoken-ddoc.asics")).getSimpleReport(); TimeStampTokenValidationData timeStampTokenValidationData = simpleReport.getValidationConclusion().getTimeStampTokens().get(0); CertificateFactory cf = CertificateFactory.getInstance("X.509"); Assert.assertEquals(1, timeStampTokenValidationData.getCertificates().size()); ee.openeid.siva.validation.document.report.Certificate certificate = timeStampTokenValidationData.getCertificates().get(0); Assert.assertEquals(CertificateType.CONTENT_TIMESTAMP, certificate.getType()); Assert.assertEquals("SK TIMESTAMPING AUTHORITY", certificate.getCommonName()); Certificate timeStampCertificate = cf.generateCertificate(new ByteArrayInputStream(Base64.decode(certificate.getContent().getBytes()))); Assert.assertEquals("SK TIMESTAMPING AUTHORITY", CertUtil.getCommonName((X509Certificate) timeStampCertificate)); }
@Test public void multipleDataFile() throws Exception { expectedException.expect(DocumentRequirementsException.class); validationService.validateDocument(buildValidationDocument("timestamptoken-two-data-files.asics")); }
@Test public void notValidTstFile() throws Exception { expectedException.expect(MalformedDocumentException.class); validationService.validateDocument(buildValidationDocument("timestamptoken-invalid.asics")); }
@Test public void dataFiledChanged() throws Exception { SimpleReport simpleReport = validationService.validateDocument(buildValidationDocument("timestamptoken-datafile-changed.asics")).getSimpleReport(); Assert.assertEquals("Signature not intact", simpleReport.getValidationConclusion().getTimeStampTokens().get(0).getError().get(0).getContent()); }
@Test public void signatureNotIntact() throws Exception { SimpleReport simpleReport = validationService.validateDocument(buildValidationDocument("timestamptoken-signature-modified.asics")).getSimpleReport(); Assert.assertEquals("Signature not intact", simpleReport.getValidationConclusion().getTimeStampTokens().get(0).getError().get(0).getContent()); }
@Test public void onlySimpleReportPresentInDocumentValidationResultReports() { Reports reports = validationService.validateDocument(buildValidationDocument("timestamptoken-ddoc.asics")); assertNotNull(reports.getSimpleReport().getValidationConclusion()); assertNotNull(reports.getDetailedReport().getValidationConclusion()); assertNotNull(reports.getDiagnosticReport().getValidationConclusion()); assertNull(reports.getDetailedReport().getValidationProcess()); assertNull(reports.getDiagnosticReport().getDiagnosticData()); }