Skip to content

Commit

Permalink
Merge pull request #77 from koptan/issue-34-signature-proofoptions-no…
Browse files Browse the repository at this point in the history
…t-included

Feat: adding Proof Configuration to Signature
  • Loading branch information
borisrizov-zf authored Apr 10, 2024
2 parents caed90f + 5943b95 commit 9727c2d
Show file tree
Hide file tree
Showing 34 changed files with 917 additions and 271 deletions.
4 changes: 4 additions & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ maven/mavencentral/net.i2p.crypto/eddsa/0.3.0, CC0-1.0, approved, CQ22537
maven/mavencentral/org.apache.commons/commons-lang3/3.14.0, Apache-2.0, approved, #11677
maven/mavencentral/org.bouncycastle/bcprov-jdk18on/1.77, MIT AND CC0-1.0, approved, #11595
maven/mavencentral/org.checkerframework/checker-qual/3.37.0, MIT, approved, clearlydefined
maven/mavencentral/org.apache.commons/commons-lang3/3.12.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apache.httpcomponents/httpclient/4.5.14, Apache-2.0 AND LicenseRef-Public-Domain, approved, CQ23527
maven/mavencentral/org.apache.httpcomponents/httpcore/4.4.16, Apache-2.0, approved, CQ23528
maven/mavencentral/org.checkerframework/checker-compat-qual/2.5.5, GPL-2.0-only with Classpath-Exception-2.0, approved, #11598
maven/mavencentral/org.codehaus.woodstox/stax2-api/4.2.1, BSD-2-Clause, approved, #2670
maven/mavencentral/org.eclipse.parsson/parsson/1.1.5, EPL-2.0, approved, ee4j.parsson
maven/mavencentral/org.projectlombok/lombok/1.18.30, MIT AND LicenseRef-Public-Domain, approved, CQ23907
17 changes: 7 additions & 10 deletions src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.InvalidJsonLdException;
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;
Expand All @@ -53,9 +54,8 @@
public class Verification {

public static void verifyJWT(SignedJWT jwt)
throws DidParseException, SignatureException, DidResolverException,
SignatureVerificationException, UnsupportedVerificationMethodException,
SignatureParseException {
throws DidParseException, SignatureException, SignatureVerificationFailedException,
UnsupportedVerificationMethodException, DidResolverException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand All @@ -66,7 +66,6 @@ public static void verifyJWT(SignedJWT jwt)

jwtVerifier.verify(jwt);
}

/**
* Verify ed25519 signed ld.
*
Expand All @@ -84,9 +83,8 @@ public static void verifyJWT(SignedJWT jwt)
*/
public static boolean verifyED25519LD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException,
SignatureVerificationFailedException {
InvalidPublicKeyFormatException, SignatureVerificationFailedException,
NoVerificationKeyFoundException, TransformJsonLdException, InvalidJsonLdException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand All @@ -99,9 +97,8 @@ public static boolean verifyED25519LD(VerifiableCredential verifiableCredential)

public static boolean verifyJWSLD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException,
SignatureVerificationFailedException {
InvalidPublicKeyFormatException, SignatureVerificationFailedException,
NoVerificationKeyFoundException, TransformJsonLdException, InvalidJsonLdException {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/eclipse/tractusx/ssi/lib/crypt/IKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public interface IKey {
int getKeyLength();

/**
* Convert the key to a string for storing
* As string for storing purpose.
*
* @return the string
* @throws IOException the io exception
* @throws KeyTransformationException the key transformation exception
*/
String asStringForStoring() throws KeyTransformationException;

/**
* Convert the key to a string for exchange.
* As string for exchange purpose.
*
* @param encodeType the encode type
* @return the string
* @throws IOException the io exception
* @throws KeyTransformationException the key transformation exception
*/
String asStringForExchange(EncodeType encodeType) throws KeyTransformationException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class DidWebParser {
*
* @param did the did
* @return the uri
* @throws DidParseException the did parse exception
*/
public URI parse(Did did) throws DidParseException {
return parse(did, true);
Expand All @@ -50,6 +51,7 @@ public URI parse(Did did) throws DidParseException {
* @param did the did
* @param enforceHttps the enforce https
* @return the uri
* @throws DidParseException the did parse exception
*/
public URI parse(Did did, boolean enforceHttps) throws DidParseException {
if (!did.getMethod().equals(Constants.DID_WEB_METHOD)) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,39 @@ public JwtAudienceCheckException(String expectedAudience, List<String> actualAud
+ ", actual audience: "
+ String.join(", ", actualAudience));
}

/**
* Instantiates a new Jwt audience check failed exception.
*
* @param message the message
*/
public JwtAudienceCheckException(String message) {
super(message);
}

/**
* Instantiates a new jwt audience check failed exception.
*
* @param message the message
* @param cause the cause
*/
public JwtAudienceCheckException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new jwt audience check failed exception.
*
* @param cause the cause
*/
public JwtAudienceCheckException(Throwable cause) {
super(cause);
}

/**
* Instantiates a new jwt audience check failed exception.
*
* @param message the message
* @param cause the cause
* @param enableSuppression the enable suppression
* @param writableStackTrace the writable stack trace
*/
public JwtAudienceCheckException(
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 @@ -24,19 +24,39 @@
/** NoVerificationKeyFoundExcpetion */
public class NoVerificationKeyFoundException extends SignatureVerificationException {
private static final long serialVersionUID = 1L;

/**
* Instantiates a new no verification key found exception.
*
* @param message the message
*/
public NoVerificationKeyFoundException(String message) {
super(message);
}

/**
* Instantiates a new no verification key found exception.
*
* @param message the message
* @param cause the cause
*/
public NoVerificationKeyFoundException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new no verification key found exception.
*
* @param cause the cause
*/
public NoVerificationKeyFoundException(Throwable cause) {
super(cause);
}

/**
* Instantiates a new no verification key found exception.
*
* @param message the message
* @param cause the cause
* @param enableSuppression the enable suppression
* @param writableStackTrace the writable stack trace
*/
public NoVerificationKeyFoundException(
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
@@ -0,0 +1,70 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
* *******************************************************************************
*/

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

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

public class DidWebException extends SSIException {

private static final long serialVersionUID = 1L;

/**
* Instantiates a new Did web exception.
*
* @param message the message
*/
public DidWebException(String message) {
super(message);
}

/**
* Instantiates a new Did web exception.
*
* @param message the message
* @param cause the cause
*/
public DidWebException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new Did web exception.
*
* @param cause the cause
*/
public DidWebException(Throwable cause) {
super(cause);
}

/**
* Instantiates a new Did web exception.
*
* @param message the message
* @param cause the cause
* @param enableSuppression the enable suppression
* @param writableStackTrace the writable stack trace
*/
public DidWebException(
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -116,10 +116,11 @@ private static SignedJWT createSignedES256Jwt(

var algorithm = JWSAlgorithm.EdDSA;
var type = JOSEObjectType.JWT;
var header =
new JWSHeader(
algorithm, type, null, null, null, null, null, null, null, null, issuer, true, null,
null);

JWSHeader.Builder jwsHeaderBuilder =
new JWSHeader.Builder(algorithm).type(type).keyID(issuer).base64URLEncodePayload(true);

var header = jwsHeaderBuilder.build();
var vc = new SignedJWT(header, claimsSet);

vc.sign(signer);
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 SignatureParseException, JwtAudienceCheckException {
throws JwtAudienceCheckException, SignatureParseException, JwtAudienceCheckException {
List<String> audiences;
try {
audiences = jwt.getJWTClaimsSet().getAudience();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver;
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.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.UnsupportedVerificationMethodException;
import org.eclipse.tractusx.ssi.lib.model.MultibaseString;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
Expand All @@ -64,19 +63,19 @@ public class SignedJwtVerifier {
* @throws DidParseException
* @throws SignatureException
* @throws DidResolverException
* @throws SignatureVerificationException
* @throws SignatureVerificationFailedException
* @throws UnsupportedVerificationMethodException
* @throws SignatureParseException
* @throws JOSEException
*/
public boolean verify(SignedJWT jwt)
throws DidParseException, DidResolverException, SignatureVerificationException,
UnsupportedVerificationMethodException, SignatureParseException {
throws DidParseException, SignatureException, DidResolverException,
SignatureVerificationFailedException, UnsupportedVerificationMethodException {

JWTClaimsSet jwtClaimsSet;
try {
jwtClaimsSet = jwt.getJWTClaimsSet();
} catch (ParseException e) {
throw new SignatureParseException(e.getMessage());
throw new SignatureException(e.getMessage());
}

final String issuer = jwtClaimsSet.getIssuer();
Expand All @@ -102,7 +101,7 @@ public boolean verify(SignedJWT jwt)
return true;
}
} catch (JOSEException e) {
throw new SignatureVerificationException(e.getMessage());
throw new SignatureVerificationFailedException(e.getMessage());
}
} else {
throw new UnsupportedVerificationMethodException(
Expand All @@ -123,7 +122,7 @@ public boolean verify(SignedJWT jwt)
return true;
}
} catch (JOSEException e) {
throw new SignatureVerificationException(e.getMessage());
throw new SignatureVerificationFailedException(e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

package org.eclipse.tractusx.ssi.lib.model.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.ipfs.multibase.Multibase;
import java.io.Serializable;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
Expand All @@ -31,7 +33,7 @@
/** The type Base 58 bitcoin. */
@Value
@EqualsAndHashCode
public class Base58Bitcoin implements MultibaseString {
public class Base58Bitcoin implements MultibaseString, Serializable {

/**
* Checks if a string can be decoded.
Expand Down Expand Up @@ -75,6 +77,12 @@ public static Base58Bitcoin create(String encoded) {
return new Base58Bitcoin(decoded, encoded);
}

byte @NonNull [] decoded;
@JsonIgnore byte @NonNull [] decoded;

@NonNull String encoded;

@Override
public String toString() {
return encoded;
}
}
Loading

0 comments on commit 9727c2d

Please sign in to comment.