From faa875d94e76cc596546361bbbc7e6c974005f4e Mon Sep 17 00:00:00 2001 From: Koptan Date: Tue, 7 Nov 2023 12:11:01 +0100 Subject: [PATCH] feat: new Exception system BREAKING CHANGE: a lot of Exception has been added and removed --- .../tractusx/ssi/examples/ResolveDIDDoc.java | 1 + .../tractusx/ssi/examples/Verification.java | 8 ++++-- .../ssi/lib/crypt/x21559/x21559Generator.java | 15 +++++++++--- .../ssi/lib/exception/SSIException.class | Bin 0 -> 561 bytes .../ssi/lib/exception/SSIException.java | 2 -- ...SignatureVerificationFailedException.java} | 23 +++++++++--------- .../UnsupportedSignatureTypeException.class | Bin 0 -> 1121 bytes .../UnsupportedSignatureTypeException.java | 2 ++ ...nsupportedVerificationMethodException.java | 2 ++ .../ssi/lib/jwt/SignedJwtValidator.java | 2 +- .../ssi/lib/jwt/SignedJwtVerifier.java | 1 + 11 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/eclipse/tractusx/ssi/lib/exception/SSIException.class rename src/main/java/org/eclipse/tractusx/ssi/lib/{did/resolver/DidResolverException.java => exception/proof/SignatureVerificationFailedException.java} (69%) create mode 100644 src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedSignatureTypeException.class diff --git a/src/main/java/org/eclipse/tractusx/ssi/examples/ResolveDIDDoc.java b/src/main/java/org/eclipse/tractusx/ssi/examples/ResolveDIDDoc.java index 4f673fbb..0f0d8dd5 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/examples/ResolveDIDDoc.java +++ b/src/main/java/org/eclipse/tractusx/ssi/examples/ResolveDIDDoc.java @@ -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 */ diff --git a/src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java b/src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java index 7d87273a..f3818c6d 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java +++ b/src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java @@ -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; @@ -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(); @@ -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(); diff --git a/src/main/java/org/eclipse/tractusx/ssi/lib/crypt/x21559/x21559Generator.java b/src/main/java/org/eclipse/tractusx/ssi/lib/crypt/x21559/x21559Generator.java index 7428488c..d0416108 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/lib/crypt/x21559/x21559Generator.java +++ b/src/main/java/org/eclipse/tractusx/ssi/lib/crypt/x21559/x21559Generator.java @@ -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. */ @@ -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); } } diff --git a/src/main/java/org/eclipse/tractusx/ssi/lib/exception/SSIException.class b/src/main/java/org/eclipse/tractusx/ssi/lib/exception/SSIException.class new file mode 100644 index 0000000000000000000000000000000000000000..0fad65c92a91357e57e275f05d7a5063f079dd71 GIT binary patch literal 561 zcmZvY%}T>S6ot>UX=7_OR*krEp@P^nI16><52z>z#Z5{V-6e5|Q({t*RQp=40xo<2 zA4LmVz8DFCC%_9iQio>6oqV6$vO2>lP8-mzzMVs_3i@PhF9e-s4cb-yjI7TWyixE+RB5OIsKK78Vs7xNx_F!Oz>&jj%8q(+3ZXa{>0z# zsR<8$fFEVN(=Kr-jk=qinLBgNy>srp`}5c34*;)Fo}np`#RQTJ_fNeOUQ@E|nNPwT z(MlUn8qHAJs2_W0p6h$E>o!a%WVc$rxs^d0j)Tc8ZXv_)RE1raw|x<4?wZhRo1Q** zwHB@~S}s3t^S}rt-9}^g-Ic+Rekr6duNmgX1wF7avNpgpLuCvicB|%5sJ?nFpI6HR zTF%n)4D)f?C}_rlW*N5Pph)sq--n0g0|#>q`~N972$lNcew4Zw1S&MV(-2+hnO?}7 z7XgoDB3V-%&XB7M$@hDwEgm+l8iq_m^};sa5!NXE)6=%C9Yg+&Qbto9f<11IR7dC1 zc$C2+mK;2`El^-6{wcGNXX=DU)gE@m4wX=a7YyIx$%%kNr|&)4@wqP6l{)DK)mX-E z=I|QPY99mt9P{v@bmgyGdmtS~IbGE&f2$t@U)@S?yNvb$39u;zPO zbM0V_VeN+OacUf_Gc5fbO8q;Oj%D1XR<%zO%>EEG-Xm)r33`F4%H}0)p^wyeGU@lD zF*7(?rMWmDO-H0vD$fL+JC)6?KBh(qPbkv%fRK*}D^ZkmWwVdlqxfe?;rReR8{tc| sld>0}0E=_UKJJWiYNX*UU1FY42`u0N&6C7_NZ&G6EtghBl(2z?-@z0lcK`qY literal 0 HcmV?d00001 diff --git a/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedSignatureTypeException.java b/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedSignatureTypeException.java index b5b966bb..a63b7241 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedSignatureTypeException.java +++ b/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedSignatureTypeException.java @@ -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. * diff --git a/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedVerificationMethodException.java b/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedVerificationMethodException.java index 7b747d43..04f81b7a 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedVerificationMethodException.java +++ b/src/main/java/org/eclipse/tractusx/ssi/lib/exception/proof/UnsupportedVerificationMethodException.java @@ -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; diff --git a/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtValidator.java b/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtValidator.java index 4f22a752..9cae9c47 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtValidator.java +++ b/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtValidator.java @@ -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 audiences; try { audiences = jwt.getJWTClaimsSet().getAudience(); diff --git a/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtVerifier.java b/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtVerifier.java index 46ee3c69..715ead43 100644 --- a/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtVerifier.java +++ b/src/main/java/org/eclipse/tractusx/ssi/lib/jwt/SignedJwtVerifier.java @@ -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;