Skip to content

Commit

Permalink
fix: add test and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasalfiti authored and nitin-vavdiya committed May 21, 2024
1 parent 50ba388 commit b3db3e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,29 +460,30 @@ private JWTVerificationResult verifyVCAsJWT(String jwt, DidResolver didResolver,
VerifiableCredential verifiableCredential = new VerifiableCredential(map);

//took this approach to avoid issues in sonarQube
return new JWTVerificationResult(validateSignature(withCredentialsValidation , signedJWT, didResolver) && validateJWTExpiryDate(withCredentialExpiryDate, signedJWT), verifiableCredential);
return new JWTVerificationResult(validateSignature(withCredentialsValidation, signedJWT, didResolver) && validateJWTExpiryDate(withCredentialExpiryDate, signedJWT), verifiableCredential);

}
}

private record JWTVerificationResult(boolean valid, VerifiableCredential verifiableCredential) {
private record JWTVerificationResult(boolean valid, VerifiableCredential verifiableCredential) {

}
}

private boolean validateSignature(boolean withValidateSignature, SignedJWT signedJWT, DidResolver didResolver) {
if(!withValidateSignature) {
return true;
}
//validate jwt signature
try {
SignedJwtVerifier jwtVerifier = new SignedJwtVerifier(didResolver);
return jwtVerifier.verify(signedJWT);
} catch (Exception e) {
log.error("Can not verify signature of jwt", e);
return false;
}
private boolean validateSignature(boolean withValidateSignature, SignedJWT signedJWT, DidResolver didResolver) {
if (!withValidateSignature) {
return true;
}
private boolean validateJWTExpiryDate(boolean withExpiryDate , SignedJWT signedJWT) {
if(!withExpiryDate) {
//validate jwt signature
try {
SignedJwtVerifier jwtVerifier = new SignedJwtVerifier(didResolver);
return jwtVerifier.verify(signedJWT);
} catch (Exception e) {
log.error("Can not verify signature of jwt", e);
return false;
}
}

private boolean validateJWTExpiryDate(boolean withExpiryDate, SignedJWT signedJWT) {
if (!withExpiryDate) {
return true;
}
try {
Expand All @@ -501,7 +502,6 @@ private boolean validateJWTExpiryDate(boolean withExpiryDate , SignedJWT signedJ
/**
* Credentials validation map.
*
* @param verificationRequest the verifiable credential
* @param withCredentialExpiryDate the with credential expiry date
* @return the map
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jwt.SignedJWT;
import com.smartsensesolutions.java.commons.specification.SpecificationUtil;

import lombok.SneakyThrows;

import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings;
import org.eclipse.tractusx.managedidentitywallets.constant.MIWVerifiableCredentialType;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
Expand Down Expand Up @@ -291,6 +289,7 @@ void shouldIssueCredentialAsJwt() throws IOException, ParseException, InvalidPri
Map<String, Object> wallets = mockBaseAndHolderWallet();
Wallet baseWallet = (Wallet) wallets.get("base");
String baseWalletBpn = baseWallet.getBpn();
String baseWalletDid = baseWallet.getDid();
Wallet holderWallet = (Wallet) wallets.get("holder");
String holderWalletBpn = holderWallet.getBpn();
String walletKeyId = "key-1";
Expand Down

0 comments on commit b3db3e0

Please sign in to comment.