HashcodeGenericValidationService extends GenericValidationService { public Reports validate(List<ValidationDocument> validationDocuments) { List<Reports> reports = validationDocuments.stream().map(validationDocument -> validateDocument(validationDocument)).collect(Collectors.toList()); return mergeReportsToOne(reports); }  Reports validate(List<ValidationDocument> validationDocuments);  }
@Test public void validHashcodeRequest() throws Exception { Reports response = validationService.validate(getValidationDocumentSingletonList()); SignatureScope signatureScope = response.getSimpleReport().getValidationConclusion().getSignatures().get(0).getSignatureScopes().get(0); Assert.assertEquals("LvhnsrgBZBK9kTQ8asbPtcsjuEhBo9s3QDdCcIxlMmo=", signatureScope.getHash()); Assert.assertEquals("SHA256", signatureScope.getHashAlgo()); Assert.assertEquals("test.pdf", signatureScope.getName()); Assert.assertEquals((Integer) 1, response.getSimpleReport().getValidationConclusion().getValidSignaturesCount()); Assert.assertEquals(1L, response.getSimpleReport().getValidationConclusion().getSignatures().size()); }
@Test public void validMultipleSignatures() throws Exception { List<ValidationDocument> validationDocuments = getValidationDocumentSingletonList(); validationDocuments.addAll(getValidationDocumentSingletonList()); Reports response = validationService.validate(validationDocuments); Assert.assertEquals((Integer) 2, response.getSimpleReport().getValidationConclusion().getValidSignaturesCount()); Assert.assertEquals((Integer) 2, response.getSimpleReport().getValidationConclusion().getSignaturesCount()); Assert.assertEquals(2L, response.getSimpleReport().getValidationConclusion().getSignatures().size()); }
@Test public void validDataFromSignatureFile() throws Exception { List<ValidationDocument> validationDocuments = getValidationDocumentSingletonList(); validationDocuments.get(0).setDatafiles(null); Reports response = validationService.validate(validationDocuments); SignatureScope signatureScope = response.getSimpleReport().getValidationConclusion().getSignatures().get(0).getSignatureScopes().get(0); Assert.assertEquals("LvhnsrgBZBK9kTQ8asbPtcsjuEhBo9s3QDdCcIxlMmo=", signatureScope.getHash()); Assert.assertEquals("SHA256", signatureScope.getHashAlgo()); Assert.assertEquals("test.pdf", signatureScope.getName()); }
@Test public void hashcodeValidationCertificateCorrectlyPresent() throws Exception { Reports response = validationService.validate(getValidationDocumentSingletonList()); SignatureValidationData signatureValidationData = response.getSimpleReport().getValidationConclusion().getSignatures().get(0); CertificateFactory cf = CertificateFactory.getInstance("X.509"); Assert.assertEquals(3, signatureValidationData.getCertificates().size()); ee.openeid.siva.validation.document.report.Certificate signerCertificate = signatureValidationData.getCertificatesByType(CertificateType.SIGNING).get(0); Certificate signerX509Certificate = cf.generateCertificate(new ByteArrayInputStream(Base64.decode(signerCertificate.getContent().getBytes()))); Assert.assertEquals("PAULIUS PODOLSKIS", CertUtil.getCommonName((X509Certificate) signerX509Certificate)); Assert.assertEquals("PAULIUS PODOLSKIS", signerCertificate.getCommonName()); ee.openeid.siva.validation.document.report.Certificate timestampCertificate = signatureValidationData.getCertificatesByType((CertificateType.SIGNATURE_TIMESTAMP)).get(0); Certificate timestampX509Certificate = cf.generateCertificate(new ByteArrayInputStream(Base64.decode(timestampCertificate.getContent().getBytes()))); Assert.assertEquals("SK TIMESTAMPING AUTHORITY", CertUtil.getCommonName((X509Certificate) timestampX509Certificate)); Assert.assertEquals("SK TIMESTAMPING AUTHORITY", timestampCertificate.getCommonName()); ee.openeid.siva.validation.document.report.Certificate revocationCertificate = signatureValidationData.getCertificatesByType((CertificateType.REVOCATION)).get(0); Certificate revocationX509Certificate = cf.generateCertificate(new ByteArrayInputStream(Base64.decode(revocationCertificate.getContent().getBytes()))); Assert.assertEquals("VI Registru Centras OCSP (IssuingCA-A)", CertUtil.getCommonName((X509Certificate) revocationX509Certificate)); Assert.assertEquals("VI Registru Centras OCSP (IssuingCA-A)", revocationCertificate.getCommonName()); }
@Test public void hashcodeValidationSubjectDNCorrectlyPresent() throws Exception { Reports reports = validationService.validate(getValidationDocumentSingletonList()); Assert.assertSame(1, reports.getSimpleReport().getValidationConclusion().getSignatures().size()); SignatureValidationData signature = reports.getSimpleReport().getValidationConclusion().getSignatures().get(0); assertNotNull(signature.getSubjectDistinguishedName()); assertEquals("38605170596", signature.getSubjectDistinguishedName().getSerialNumber()); assertEquals("PAULIUS PODOLSKIS", signature.getSubjectDistinguishedName().getCommonName()); }
@Test public void populatesSignerRole() throws IOException, URISyntaxException { Reports reports = validationService.validate(getValidationDocumentSingletonList()); List<SignerRole> signerRole = reports.getSimpleReport().getValidationConclusion().getSignatures().get(0).getInfo().getSignerRole(); assertEquals(1, signerRole.size()); assertEquals("Direktorius", signerRole.get(0).getClaimedRole()); }
@Test public void populatesSignatureProductionPlace() throws IOException, URISyntaxException { Reports reports = validationService.validate(getValidationDocumentSingletonList("test-files/signatures_with_sig_production_place.xml")); SignatureProductionPlace signatureProductionPlace = reports.getSimpleReport().getValidationConclusion() .getSignatures().get(0).getInfo().getSignatureProductionPlace(); assertEquals("Tallinn", signatureProductionPlace.getCity()); assertEquals("Harjumaa", signatureProductionPlace.getStateOrProvince()); assertEquals("12345", signatureProductionPlace.getPostalCode()); assertEquals("Eesti", signatureProductionPlace.getCountryName()); }
@Test public void populatesSignatureMethod() throws IOException, URISyntaxException { Reports reports = validationService.validate(getValidationDocumentSingletonList("test-files/signatures_with_sig_production_place.xml")); assertEquals("http: reports.getSimpleReport().getValidationConclusion().getSignatures().get(0).getSignatureMethod()); }
@Test public void populatesTimeAssertionMessageImprint() throws IOException, URISyntaxException { Reports reports = validationService.validate(getValidationDocumentSingletonList()); assertEquals("MDEwDQYJYIZIAWUDBAIBBQAEIBf8So+lfR/lrfzu5i+SZwguJGakhr/W+eHwrAQJ0acJ", reports.getSimpleReport().getValidationConclusion().getSignatures().get(0).getInfo().getTimeAssertionMessageImprint()); }