Skip to content

Commit

Permalink
chore: Fixing code review
Browse files Browse the repository at this point in the history
  • Loading branch information
koptan committed Jan 15, 2024
1 parent 8f92066 commit 43866eb
Show file tree
Hide file tree
Showing 34 changed files with 129 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
package org.eclipse.tractusx.ssi.examples;

import java.net.http.HttpClient;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolverException;
import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory;
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.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.resolver.DidDocumentResolverAlreadyRegisteredException;
import org.eclipse.tractusx.ssi.lib.exception.resolver.DidDocumentResolverNotRegisteredException;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;

Expand All @@ -43,8 +41,7 @@ public class ResolveDIDDoc {
* exception
*/
public static DidDocument ResovleDocument(String didUrl)
throws DidDocumentResolverNotRegisteredException,
DidDocumentResolverAlreadyRegisteredException, DidParseException, DidResolverException {
throws DidParseException, DidResolverException {

// DID Resolver Constracture params
DidWebParser didParser = new DidWebParser();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/eclipse/tractusx/ssi/examples/Validation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package org.eclipse.tractusx.ssi.examples;

import com.nimbusds.jwt.SignedJWT;
import org.eclipse.tractusx.ssi.lib.exception.proof.JwtAudienceCheckFailedException;
import org.eclipse.tractusx.ssi.lib.exception.proof.JwtAudienceCheckException;
import org.eclipse.tractusx.ssi.lib.exception.proof.JwtExpiredException;
import org.eclipse.tractusx.ssi.lib.exception.proof.SignatureParseException;
import org.eclipse.tractusx.ssi.lib.jwt.SignedJwtValidator;
Expand All @@ -34,11 +34,11 @@ public class Validation {
*
* @param signedJWT the signed jwt
* @param audience the audience
* @throws JwtAudienceCheckFailedException the jwt audience check failed exception
* @throws JwtAudienceCheckException the jwt audience check failed exception
* @throws JwtExpiredException the jwt expired exception
*/
public static void validateJWTDate(SignedJWT signedJWT, String audience)
throws JwtAudienceCheckFailedException, JwtExpiredException, SignatureParseException {
throws JwtAudienceCheckException, JwtExpiredException, SignatureParseException {
SignedJwtValidator jwtValidator = new SignedJwtValidator();
jwtValidator.validateDate(signedJWT);
}
Expand All @@ -48,11 +48,11 @@ public static void validateJWTDate(SignedJWT signedJWT, String audience)
*
* @param signedJWT the signed jwt
* @param audience the audience
* @throws JwtAudienceCheckFailedException the jwt audience check failed exception
* @throws JwtAudienceCheckException the jwt audience check failed exception
* @throws JwtExpiredException the jwt expired exception
*/
public static void validateJWTAudiences(SignedJWT signedJWT, String audience)
throws JwtAudienceCheckFailedException, JwtExpiredException, SignatureParseException {
throws JwtAudienceCheckException, JwtExpiredException, SignatureParseException {
SignedJwtValidator jwtValidator = new SignedJwtValidator();
jwtValidator.validateAudiences(signedJWT, audience);
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@
import com.nimbusds.jwt.SignedJWT;
import java.net.http.HttpClient;
import java.security.SignatureException;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolverException;
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.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
import org.eclipse.tractusx.ssi.lib.exception.json.TransformJsonLdException;
import org.eclipse.tractusx.ssi.lib.exception.key.InvalidPublicKeyFormatException;
import org.eclipse.tractusx.ssi.lib.exception.proof.NoVerificationKeyFoundException;
import org.eclipse.tractusx.ssi.lib.exception.proof.SignatureParseException;
import org.eclipse.tractusx.ssi.lib.exception.proof.SignatureVerificationFailedException;
import org.eclipse.tractusx.ssi.lib.exception.proof.SignatureVerificationException;
import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedSignatureTypeException;
import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedVerificationMethodException;
import org.eclipse.tractusx.ssi.lib.exception.resolver.DidDocumentResolverNotRegisteredException;
import org.eclipse.tractusx.ssi.lib.jwt.SignedJwtVerifier;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofValidation;
Expand All @@ -47,14 +46,15 @@
* @throws DidParseException
* @throws SignatureException
* @throws DidResolverException
* @throws SignatureVerificationFailedException
* @throws SignatureVerificationException
* @throws UnsupportedVerificationMethodException
*/
public class Verification {

public static void verifyJWT(SignedJWT jwt)
throws DidParseException, SignatureException, DidResolverException,
SignatureVerificationFailedException, UnsupportedVerificationMethodException {
SignatureVerificationException, UnsupportedVerificationMethodException,
SignatureParseException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand All @@ -74,17 +74,16 @@ public static void verifyJWT(SignedJWT jwt)
* @throws DidDocumentResolverNotRegisteredException
* @throws TransformJsonLdException
* @throws NoVerificationKeyFoundException
* @throws SignatureVerificationFailedException
* @throws SignatureVerificationException
* @throws InvalidPublicKeyFormatException
* @throws DidParseException
* @throws SignatureParseException
* @throws UnsupportedSignatureTypeException
*/
public static boolean verifyED21559LD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationFailedException,
NoVerificationKeyFoundException, TransformJsonLdException,
DidDocumentResolverNotRegisteredException {
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand All @@ -97,9 +96,8 @@ public static boolean verifyED21559LD(VerifiableCredential verifiableCredential)

public static boolean verifyJWSLD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationFailedException,
NoVerificationKeyFoundException, DidDocumentResolverNotRegisteredException,
TransformJsonLdException {
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
import org.eclipse.tractusx.ssi.lib.crypt.IKeyGenerator;
import org.eclipse.tractusx.ssi.lib.crypt.KeyPair;
import org.eclipse.tractusx.ssi.lib.exception.key.InvalidPrivateKeyFormatException;
import org.eclipse.tractusx.ssi.lib.exception.key.InvalidPublicKeyFormatException;
import org.eclipse.tractusx.ssi.lib.exception.key.KeyGenerationException;

/** X21559 key generator. */
Expand All @@ -49,17 +47,10 @@ public KeyPair generateKey() throws KeyGenerationException {
Ed25519PublicKeyParameters publicKey = (Ed25519PublicKeyParameters) keyPair.getPublic();

x21559PrivateKey x21559PrivateKey;
try {
x21559PrivateKey = new x21559PrivateKey(privateKey.getEncoded());
} catch (InvalidPrivateKeyFormatException e) {
throw new KeyGenerationException(e.getCause());
}
x21559PrivateKey = new x21559PrivateKey(privateKey.getEncoded());

x21559PublicKey x21559PublicKey;
try {
x21559PublicKey = new x21559PublicKey(publicKey.getEncoded());
} catch (InvalidPublicKeyFormatException e) {
throw new KeyGenerationException(e.getCause());
}
x21559PublicKey = new x21559PublicKey(publicKey.getEncoded());
return new KeyPair(x21559PublicKey, x21559PrivateKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.eclipse.tractusx.ssi.lib.did.resolver;

import java.util.Arrays;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.tractusx.ssi.lib.did.resolver;

import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;

Expand Down Expand Up @@ -70,7 +72,7 @@ public DidUniResolver(HttpClient client, URI uniResolverEndpoint)
}

@Override
public DidDocument resolve(Did did) throws DidResolverException {
public DidDocument resolve(Did did) throws DidResolverException, DidParseException {
URI requestUri =
uniResolverEndpoint.resolve(uniResolverResolvePath).resolve("./" + did.toString());
final HttpRequest request = HttpRequest.newBuilder().uri(requestUri).GET().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolverException;
import org.eclipse.tractusx.ssi.lib.did.web.util.Constants;
import org.eclipse.tractusx.ssi.lib.did.web.util.DidWebParser;
import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;

Expand Down Expand Up @@ -63,7 +63,6 @@ public DidDocument resolve(Did did) throws DidResolverException, DidParseExcepti
final URI uri = parser.parse(did, enforceHttps);

final HttpRequest request = HttpRequest.newBuilder().uri(uri).GET().build();

try {
final HttpResponse<String> response =
client.send(request, HttpResponse.BodyHandlers.ofString());
Expand All @@ -84,6 +83,7 @@ public DidDocument resolve(Did did) throws DidResolverException, DidParseExcepti
final Map<String, Object> json = mapper.readValue(body, Map.class);

return new DidDocument(json);

} catch (Exception e) {
throw new DidResolverException(
String.format("Unexpected exception: %s", e.getClass().getName()), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,37 @@
package org.eclipse.tractusx.ssi.lib.exception.did;

import org.eclipse.tractusx.ssi.lib.exception.SSIException;
/** The type Did parse exception. */

/** The type Did parse exception. */
public class DidParseException extends SSIException {

private static final long serialVersionUID = -8099856673022088164L;
/**
* Instantiates a new Did parse exception.
/**
* Instantiates a new Did parse exception.
*
* @param message the message
*/
public DidParseException(String did) {
super(String.format("Invalid DID URL: %s, not able to parse it", did));
}
/**
* Instantiates a new Did parse exception.
/**
* Instantiates a new Did parse exception.
*
* @param message the message
* @param cause the cause
*/
public DidParseException(String message, Throwable cause) {
super(message, cause);
}
/**
* Instantiates a new Did parse exception.
/**
* Instantiates a new Did parse exception.
*
* @param cause the cause
*/
public DidParseException(Throwable cause) {
super(cause);
}
/**
/**
* Instantiates a new Did parse exception.
*
* @param message the message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,51 @@
* *******************************************************************************
*/

package org.eclipse.tractusx.ssi.lib.exception.resolver;
package org.eclipse.tractusx.ssi.lib.exception.did;

import org.eclipse.tractusx.ssi.lib.model.did.DidMethod;
import org.eclipse.tractusx.ssi.lib.exception.SSIException;

/** The type SSI did document resolver already registered exception. */
public class DidDocumentResolverAlreadyRegisteredException extends Exception {
/** The type Did resolver exception. */
public class DidResolverException extends SSIException {

private static final long serialVersionUID = 1101625710675168299L;
/**
* Instantiates a new did document resolver already registered exception.
* Instantiates a new Did resolver exception.
*
* @param message the message
*/
public DidDocumentResolverAlreadyRegisteredException(DidMethod didMethod) {
super(String.format("No DID document resolver registered for DID method '%s'", didMethod));
}

/**
* Instantiates a new did document resolver already registered exception.
*
* @param message the message
* @param cause the cause
*/
public DidDocumentResolverAlreadyRegisteredException(String message) {
public DidResolverException(String message) {
super(message);
}

/**
* Instantiates a new did document resolver already registered exception.
* Instantiates a new Did resolver exception from another exception with a message.
*
* @param message the message
* @param cause the cause
*/
public DidDocumentResolverAlreadyRegisteredException(String message, Throwable cause) {
public DidResolverException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new did document resolver already registered exception.
* Instantiates a new Did resolver exception from another exception.
*
* @param message the message
* @param cause the cause
*/
public DidDocumentResolverAlreadyRegisteredException(Throwable cause) {
public DidResolverException(Throwable cause) {
super(cause);
}

/**
* Instantiates a new did document resolver already registered exception.
* Instantiates a new Did resolver exception with a message from another exception, allowing for
* disabling and printing the stack trace.
*
* @param message the message
* @param cause the cause
* @param enableSuppression the enable suppression
* @param writableStackTrace the writable stack trace
*/
public DidDocumentResolverAlreadyRegisteredException(
public DidResolverException(
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/** The type tranform json LD exception. */
public class TransformJsonLdException extends SSIException {

private static final long serialVersionUID = -1139580728763064789L;
/**
* Instantiates a new tranform json LD exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

package org.eclipse.tractusx.ssi.lib.exception.key;

import org.eclipse.tractusx.ssi.lib.exception.SSIException;

/** The type Invalide private key format. */
public class InvalidPrivateKeyFormatException extends SSIException {
public class InvalidPrivateKeyFormatException extends KeyGenerationException {
private static final long serialVersionUID = -3348735256693555408L;
/**
* Instantiates a new Invalid private key format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

package org.eclipse.tractusx.ssi.lib.exception.key;

import org.eclipse.tractusx.ssi.lib.exception.SSIException;

/** The type Invalid public key format. */
public class InvalidPublicKeyFormatException extends SSIException {
public class InvalidPublicKeyFormatException extends KeyGenerationException {
private static final long serialVersionUID = -8303592321627404757L;
/**
* Instantiates a new Invalide public key format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

package org.eclipse.tractusx.ssi.lib.exception.key;

import org.eclipse.tractusx.ssi.lib.exception.SSIException;

/** The type Key Generation Exception */
Expand Down
Loading

0 comments on commit 43866eb

Please sign in to comment.