diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java index cd0b64be1..31c967c85 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java @@ -47,9 +47,8 @@ import org.eclipse.tractusx.managedidentitywallets.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.utils.CommonUtils; import org.eclipse.tractusx.managedidentitywallets.utils.Validate; -import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistry; -import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistryImpl; -import org.eclipse.tractusx.ssi.lib.did.web.DidWebDocumentResolver; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver; +import org.eclipse.tractusx.ssi.lib.did.web.DidWebResolver; import org.eclipse.tractusx.ssi.lib.did.web.util.DidWebParser; import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; @@ -428,25 +427,18 @@ public Map credentialsValidation(Map data, boole VerifiableCredential verifiableCredential = new VerifiableCredential(data); // DID Resolver Constracture params - DidDocumentResolverRegistry didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl(); - didDocumentResolverRegistry.register( - new DidWebDocumentResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps())); - + DidResolver resolver = new DidWebResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps()); String proofTye = verifiableCredential.getProof().get(StringPool.TYPE).toString(); LinkedDataProofValidation proofValidation; if (SignatureType.ED21559.toString().equals(proofTye)) { - proofValidation = LinkedDataProofValidation.newInstance( - SignatureType.ED21559, - didDocumentResolverRegistry); + proofValidation = LinkedDataProofValidation.newInstance(SignatureType.ED21559, resolver); } else if (SignatureType.JWS.toString().equals(proofTye)) { - proofValidation = LinkedDataProofValidation.newInstance( - SignatureType.JWS, - didDocumentResolverRegistry); + proofValidation = LinkedDataProofValidation.newInstance(SignatureType.JWS, resolver); } else { throw new BadDataException(String.format("Invalid proof type: %s", proofTye)); } - boolean valid = proofValidation.verifiyProof(verifiableCredential); + boolean valid = proofValidation.verifyProof(verifiableCredential); Map response = new TreeMap<>(); diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java index 8df2a8950..6f0ab398b 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java @@ -39,9 +39,8 @@ import org.eclipse.tractusx.ssi.lib.crypt.ed25519.Ed25519Key; import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory; import org.eclipse.tractusx.ssi.lib.crypt.x21559.x21559PrivateKey; -import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistry; -import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistryImpl; -import org.eclipse.tractusx.ssi.lib.did.web.DidWebDocumentResolver; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver; +import org.eclipse.tractusx.ssi.lib.did.web.DidWebResolver; import org.eclipse.tractusx.ssi.lib.did.web.util.DidWebParser; import org.eclipse.tractusx.ssi.lib.exception.InvalidJsonLdException; import org.eclipse.tractusx.ssi.lib.exception.InvalidePrivateKeyFormat; @@ -228,11 +227,8 @@ public Map validatePresentation(Map vp, boolean private boolean validateSignature(SignedJWT signedJWT) { //validate jwt signature try { - DidDocumentResolverRegistry didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl(); - didDocumentResolverRegistry.register( - new DidWebDocumentResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps())); - - SignedJwtVerifier jwtVerifier = new SignedJwtVerifier(didDocumentResolverRegistry); + DidResolver resolver = new DidWebResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps()); + SignedJwtVerifier jwtVerifier = new SignedJwtVerifier(resolver); return jwtVerifier.verify(signedJWT); } catch (Exception e) { log.error("Can not verify signature of jwt", e); @@ -268,27 +264,24 @@ private boolean validateAudience(String audience, SignedJWT signedJWT) { private boolean validateCredential(VerifiableCredential credential) throws UnsupportedSignatureTypeException { - DidDocumentResolverRegistry didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl(); - didDocumentResolverRegistry.register( - new DidWebDocumentResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps())); - + DidResolver resolver = new DidWebResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps()); String proofType = credential.getProof().getType(); LinkedDataProofValidation linkedDataProofValidation; if (SignatureType.ED21559.toString().equals(proofType)) { linkedDataProofValidation = LinkedDataProofValidation.newInstance( SignatureType.ED21559, - didDocumentResolverRegistry + resolver ); } else if (SignatureType.JWS.toString().equals(proofType)) { linkedDataProofValidation = LinkedDataProofValidation.newInstance( SignatureType.JWS, - didDocumentResolverRegistry + resolver ); } else { throw new UnsupportedSignatureTypeException(proofType); } - boolean isValid = linkedDataProofValidation.verifiyProof(credential); + boolean isValid = linkedDataProofValidation.verifyProof(credential); if (isValid) { log.debug("Credential validation result: (valid: {}, credential-id: {})", isValid, credential.getId()); } else { diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java index 61019c676..8f2ff1d8a 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java @@ -37,7 +37,7 @@ import org.eclipse.tractusx.managedidentitywallets.dto.IssueFrameworkCredentialRequest; import org.eclipse.tractusx.managedidentitywallets.utils.AuthenticationUtils; import org.eclipse.tractusx.managedidentitywallets.utils.TestUtils; -import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistryImpl; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver; import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialBuilder; @@ -214,9 +214,9 @@ void validateCredentialsWithInvalidVC() throws com.fasterxml.jackson.core.JsonPr //mock setup LinkedDataProofValidation mock = Mockito.mock(LinkedDataProofValidation.class); utils.when(() -> { - LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidDocumentResolverRegistryImpl.class)); + LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidResolver.class)); }).thenReturn(mock); - Mockito.when(mock.verifiyProof(Mockito.any(VerifiableCredential.class))).thenReturn(false); + Mockito.when(mock.verifyProof(Mockito.any(VerifiableCredential.class))).thenReturn(false); Map stringObjectMap = credentialController.credentialsValidation(map, false).getBody(); Assertions.assertFalse(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); @@ -237,9 +237,9 @@ void validateCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core. //mock setup LinkedDataProofValidation mock = Mockito.mock(LinkedDataProofValidation.class); utils.when(() -> { - LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidDocumentResolverRegistryImpl.class)); + LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidResolver.class)); }).thenReturn(mock); - Mockito.when(mock.verifiyProof(Mockito.any(VerifiableCredential.class))).thenReturn(true); + Mockito.when(mock.verifyProof(Mockito.any(VerifiableCredential.class))).thenReturn(true); Map stringObjectMap = credentialController.credentialsValidation(map, true).getBody(); Assertions.assertTrue(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); @@ -264,9 +264,9 @@ void validateCredentialsWithExpiryCheckFalse() throws com.fasterxml.jackson.core //mock setup LinkedDataProofValidation mock = Mockito.mock(LinkedDataProofValidation.class); utils.when(() -> { - LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidDocumentResolverRegistryImpl.class)); + LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidResolver.class)); }).thenReturn(mock); - Mockito.when(mock.verifiyProof(Mockito.any(VerifiableCredential.class))).thenReturn(true); + Mockito.when(mock.verifyProof(Mockito.any(VerifiableCredential.class))).thenReturn(true); Map stringObjectMap = credentialController.credentialsValidation(map, false).getBody(); Assertions.assertTrue(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); @@ -290,9 +290,9 @@ void validateExpiredCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackso //mock setup LinkedDataProofValidation mock = Mockito.mock(LinkedDataProofValidation.class); utils.when(() -> { - LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidDocumentResolverRegistryImpl.class)); + LinkedDataProofValidation.newInstance(Mockito.any(SignatureType.class), Mockito.any(DidResolver.class)); }).thenReturn(mock); - Mockito.when(mock.verifiyProof(Mockito.any(VerifiableCredential.class))).thenReturn(true); + Mockito.when(mock.verifyProof(Mockito.any(VerifiableCredential.class))).thenReturn(true); Map stringObjectMap = credentialController.credentialsValidation(map, true).getBody(); Assertions.assertFalse(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java index fc53ba6d6..826842516 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java @@ -37,8 +37,9 @@ import org.eclipse.tractusx.managedidentitywallets.dao.repository.HoldersCredentialRepository; import org.eclipse.tractusx.managedidentitywallets.utils.AuthenticationUtils; import org.eclipse.tractusx.managedidentitywallets.utils.TestUtils; -import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistry; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver; import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory; +import org.eclipse.tractusx.ssi.lib.did.web.DidWebResolver; import org.eclipse.tractusx.ssi.lib.exception.DidDocumentResolverNotRegisteredException; import org.eclipse.tractusx.ssi.lib.exception.JwtException; import org.eclipse.tractusx.ssi.lib.jwt.SignedJwtVerifier; @@ -126,8 +127,8 @@ void validateVPAsJwtWithInvalidSignatureAndInValidAudienceAndExpiryDateValidatio try (MockedConstruction mocked = Mockito.mockConstruction(SignedJwtVerifier.class)) { - DidDocumentResolverRegistry didDocumentResolverRegistry = Mockito.mock(DidDocumentResolverRegistry.class); - SignedJwtVerifier signedJwtVerifier = new SignedJwtVerifier(didDocumentResolverRegistry); + DidResolver didResolver = Mockito.mock(DidWebResolver.class); + SignedJwtVerifier signedJwtVerifier = new SignedJwtVerifier(didResolver); Mockito.doThrow(new JwtException("invalid")).when(signedJwtVerifier).verify(Mockito.any(SignedJWT.class));