From 6f70b09523bed428472ed61c0c88964473a243b5 Mon Sep 17 00:00:00 2001 From: Ronak Thacker Date: Mon, 5 Jun 2023 16:32:45 +0530 Subject: [PATCH] feat: update lib method to resolved vc/vp validate --- .../service/CredentialService.java | 10 +++++----- .../service/PresentationService.java | 4 ++-- .../service/WalletKeyService.java | 14 +++++++------- .../service/WalletService.java | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CredentialService.java index 24d4da0c9..ec9235d6b 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CredentialService.java @@ -187,7 +187,7 @@ public VerifiableCredential issueFrameworkCredential(IssueFrameworkCredentialReq Validate.isFalse(callerBPN.equals(baseWallet.getBpn())).launch(new ForbiddenException(BASE_WALLET_BPN_IS_NOT_MATCHING_WITH_REQUEST_BPN_FROM_TOKEN)); // get Key - byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId()); + byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId()); Map subject = Map.of("type", request.getType(), "id", holderWallet.getDid(), @@ -225,7 +225,7 @@ public VerifiableCredential issueDismantlerCredential(IssueDismantlerCredentialR //check duplicate isCredentialExit(holderWallet.getDid(), MIWVerifiableCredentialType.DISMANTLER_CREDENTIAL_CX); - byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId()); + byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId()); Map subject = Map.of("type", MIWVerifiableCredentialType.DISMANTLER_CREDENTIAL, "id", holderWallet.getDid(), @@ -264,7 +264,7 @@ public VerifiableCredential issueMembershipCredential(IssueMembershipCredentialR //validate BPN access Validate.isFalse(callerBPN.equals(baseWallet.getBpn())).launch(new ForbiddenException(BASE_WALLET_BPN_IS_NOT_MATCHING_WITH_REQUEST_BPN_FROM_TOKEN)); - byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId()); + byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId()); List types = List.of(VerifiableCredentialType.VERIFIABLE_CREDENTIAL, MIWVerifiableCredentialType.MEMBERSHIP_CREDENTIAL_CX); //VC Subject Credential credential = CommonUtils.getCredential(Map.of("type", VerifiableCredentialType.MEMBERSHIP_CREDENTIAL, @@ -297,7 +297,7 @@ public Map credentialsValidation(Map data) { // DID Resolver Constracture params DidWebParser didParser = new DidWebParser(); var httpClient = HttpClient.newHttpClient(); - var enforceHttps = true; + var enforceHttps = false; var didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl(); didDocumentResolverRegistry.register( @@ -319,7 +319,7 @@ public VerifiableCredential issueCredential(Map data, String cal Validate.isFalse(callerBpn.equals(issuerWallet.getBpn())).launch(new ForbiddenException(BASE_WALLET_BPN_IS_NOT_MATCHING_WITH_REQUEST_BPN_FROM_TOKEN)); // get Key - byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(issuerWallet.getId()); + byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(issuerWallet.getId()); // Create Credential Credential credential = CommonUtils.getCredential(verifiableCredential.getCredentialSubject().get(0), 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 303e59990..8b1fcbd58 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java @@ -135,7 +135,7 @@ public Map createPresentation(Map data, boolean //Build JWT SignedJWT presentation = presentationFactory.createPresentation( - issuerDid, verifiableCredentials, audience, walletKeyService.getEd25519Key(holderWallet.getId())); + issuerDid, verifiableCredentials, audience, walletKeyService.getPrivateKeyByWalletIdentifier(holderWallet.getId())); response.put("vp", presentation.serialize()); } else { @@ -169,7 +169,7 @@ public Map validatePresentation(Map vp, boolean //validate jwt signature DidWebParser didParser = new DidWebParser(); var httpClient = HttpClient.newHttpClient(); - var enforceHttps = true; + var enforceHttps = false; var didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl(); didDocumentResolverRegistry.register( diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java index 64b946e25..83e0e59d6 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java @@ -59,16 +59,16 @@ protected SpecificationUtil getSpecificationUtil() { @SneakyThrows - public byte[] getPrivateKeyByWalletIdentifier(long walletId) { - WalletKey wallet = walletKeyRepository.getByWalletId(walletId); - String privateKey = encryptionUtils.decrypt(wallet.getPrivateKey()); - return new PemReader(new StringReader(privateKey)).readPemObject().getContent(); + public byte[] getPrivateKeyByWalletIdentifierAsBytes(long walletId) { + return getPrivateKeyByWalletIdentifier(walletId).getEncoded(); } @SneakyThrows - public Ed25519Key getEd25519Key(long walletId) { - return new Ed25519Key(getPrivateKeyByWalletIdentifier(walletId)); - + public Ed25519Key getPrivateKeyByWalletIdentifier(long walletId) { + WalletKey wallet = walletKeyRepository.getByWalletId(walletId); + String privateKey = encryptionUtils.decrypt(wallet.getPrivateKey()); + byte[] content = new PemReader(new StringReader(privateKey)).readPemObject().getContent(); + return Ed25519Key.asPrivateKey(content); } } diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java index cbeb3af7b..25cc85da3 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java @@ -262,7 +262,7 @@ public Wallet createWallet(CreateWalletRequest request) { //issue BPN credentials`` Wallet baseWallet = getWalletByIdentifier(miwSettings.authorityWalletBpn()); - byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId()); + byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId()); List types = List.of(VerifiableCredentialType.VERIFIABLE_CREDENTIAL, MIWVerifiableCredentialType.BPN_CREDENTIAL_CX); Credential credential = CommonUtils.getCredential(Map.of("type", MIWVerifiableCredentialType.BPN_CREDENTIAL, "id", wallet.getDid(),