Skip to content

Commit

Permalink
feat: new Exception system
Browse files Browse the repository at this point in the history
BREAKING CHANGE: a lot of Exception has been added and removed
  • Loading branch information
koptan committed Jan 31, 2024
1 parent fd5fbb0 commit 9d6053a
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ResolveDIDDoc {
*
* @param didUrl the did url
* @return the did document
* @throws org.eclipse.tractusx.ssi.lib.did.resolver.DidResolverException
* @throws DidDocumentResolverNotRegisteredException the did document resolver not registered
* exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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.SignatureVerificationException;
import org.eclipse.tractusx.ssi.lib.exception.proof.SignatureVerificationFailedException;
import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedSignatureTypeException;
import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedVerificationMethodException;
import org.eclipse.tractusx.ssi.lib.jwt.SignedJwtVerifier;
Expand Down Expand Up @@ -79,11 +80,13 @@ public static void verifyJWT(SignedJWT jwt)
* @throws DidParseException
* @throws SignatureParseException
* @throws UnsupportedSignatureTypeException
* @throws SignatureVerificationFailedException
*/
public static boolean verifyED21559LD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException {
NoVerificationKeyFoundException, TransformJsonLdException,
SignatureVerificationFailedException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand All @@ -97,7 +100,8 @@ public static boolean verifyED21559LD(VerifiableCredential verifiableCredential)
public static boolean verifyJWSLD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException {
NoVerificationKeyFoundException, TransformJsonLdException,
SignatureVerificationFailedException {
// 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,6 +29,8 @@
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 @@ -47,10 +49,17 @@ public KeyPair generateKey() throws KeyGenerationException {
Ed25519PublicKeyParameters publicKey = (Ed25519PublicKeyParameters) keyPair.getPublic();

x21559PrivateKey x21559PrivateKey;
x21559PrivateKey = new x21559PrivateKey(privateKey.getEncoded());

try {
x21559PrivateKey = new x21559PrivateKey(privateKey.getEncoded());
} catch (InvalidPrivateKeyFormatException e) {
throw new KeyGenerationException(e.getCause());
}
x21559PublicKey x21559PublicKey;
x21559PublicKey = new x21559PublicKey(publicKey.getEncoded());
try {
x21559PublicKey = new x21559PublicKey(publicKey.getEncoded());
} catch (InvalidPublicKeyFormatException e) {
throw new KeyGenerationException(e.getCause());
}
return new KeyPair(x21559PublicKey, x21559PrivateKey);
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
/** The type SSI exception. */
public class SSIException extends Exception {

private static final long serialVersionUID = -6426089110128695365L;

/**
* Instantiates a new SSI exception.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,50 @@
* *******************************************************************************
*/

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

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

/** The type Did resolver exception. */
public class DidResolverException extends SSIException {
/** The type Signature Verification Failed exception. */
public class SignatureVerificationFailedException extends SSIException {

/**
* Instantiates a new Did resolver exception.
* Instantiates a new signature verification failed exception.
*
* @param message the message
*/
public DidResolverException(String message) {
public SignatureVerificationFailedException(String message) {
super(message);
}

/**
* Instantiates a new Did resolver exception from another exception with a message.
* Instantiates a new signature verification failed exception.
*
* @param message the message
* @param cause the cause
*/
public DidResolverException(String message, Throwable cause) {
protected SignatureVerificationFailedException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new Did resolver exception from another exception.
* Instantiates a new signature verification failed exception.
*
* @param cause the cause
*/
public DidResolverException(Throwable cause) {
protected SignatureVerificationFailedException(Throwable cause) {
super(cause);
}

/**
* Instantiates a new Did resolver exception with a message from another exception, allowing for
* disabling and printing the stack trace.
* Instantiates a new signature verification failed exception.
*
* @param message the message
* @param cause the cause
* @param enableSuppression the enable suppression
* @param writableStackTrace the writable stack trace
*/
public DidResolverException(
protected SignatureVerificationFailedException(
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
/** The type Unsupported signature type exception. */
public class UnsupportedSignatureTypeException extends SignatureVerificationException {

private static final long serialVersionUID = 6406987797507777929L;

/**
* Instantiates a new unsupported signature type exception.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
/** The type Unsupported verification method exception. */
public class UnsupportedVerificationMethodException extends SignatureVerificationException {

private static final long serialVersionUID = 6406987797507777929L;

/** The verification method */
@Getter private final VerificationMethod method;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void validateDate(SignedJWT jwt) throws JwtExpiredException, SignaturePar
}

public void validateAudiences(SignedJWT jwt, String expectedAudience)
throws JwtAudienceCheckException, SignatureParseException {
throws SignatureParseException, JwtAudienceCheckException {
List<String> audiences;
try {
audiences = jwt.getJWTClaimsSet().getAudience();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.nimbusds.jose.util.Base64URL;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import java.security.SignatureException;
import java.text.ParseException;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down

0 comments on commit 9d6053a

Please sign in to comment.