-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INJICERT-434] add preliminary VC 2.0 support via DataProvider plugin…
… & VCFormatter + VCSigner (#93) * [INJICERT-434] add DataProvider plugin interface Co-Authored by: Piyush7034 <[email protected]> Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] temp add sleep to replace JARs Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] update interface definitions Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add repository to fetch VC Templates Signed-off-by: Piyush Shukla <[email protected]> * [INJICERT-434] add prelimnary impl for VC template & sign * Velocity Engine 1.7 used for templating * Embedded mosip/keymanager used for key signing with RSASignature2018 * older issuance plugin(VCIssuancePlugin) compatibility is maintained w hack assuming VC2.0 is always generated by DataProvider+VCFormatter+VCSigner Co-Authored by: Piyush7034 <[email protected]> Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add sample tests for templating Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] fix TemplateRepository definition Co-Authored by: Hitesh Jain <[email protected]> Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] generate RSA key for signing VCs Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] fix local setup, update templates Co-Authored by: Hitesh Jain <[email protected]> Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-497] use the correct plugin type for VCI resp * add config to point the VCI b/w VCIssuancePlugin & DataProviderPlugin Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] improve time handling iff DataProvider skips issuance/expiry time Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] get public key URL from config Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] fix integration test Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] separate CertifyPlugin & PluginIssuer VCIssuanceService Two use-cases are possible now: * CertifyPlugin: Uses DataProviderPlugin + VCFormatter + VCSigner to generate the credential by itself. With this, DataProviderPlugin will share the Credential data and formatting & signing will be done by Certify. * PluginIssuer: Uses VCIssuancePlugin, which will generate the credential all by itself and Certify will just deliver the Credential over the OpenID4VCI. Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add unit tests & refactor impl Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add lib for json unit-test & update javadoc Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add create & update TS to template_data table Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add mandatory issuer property for DataProvider VC Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] optimise imports Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] improve logging for keymanagerlib Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] add redis pwd in cfg file Signed-off-by: Harsh Vardhan <[email protected]> --------- Signed-off-by: Harsh Vardhan <[email protected]> Signed-off-by: Piyush Shukla <[email protected]> Co-authored-by: Piyush Shukla <[email protected]>
- Loading branch information
1 parent
0272972
commit e87f210
Showing
40 changed files
with
1,318 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
certify-core/src/main/java/io/mosip/certify/core/constants/SignatureAlg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.mosip.certify.core.constants; | ||
|
||
/** | ||
* SignatureAlg is the constants file of supported VC sign algorithms. | ||
* TODO(later): convert this into a structure such that it enables | ||
* consumers to choose VC sign algos with | ||
*/ | ||
public class SignatureAlg { | ||
// LinkedDataSignature Algorithms | ||
public static final String RSA_SIGNATURE_SUITE = "RsaSignature2018"; | ||
|
||
public static final String ED25519_SIGNATURE_SUITE = "Ed25519Signature2018"; | ||
|
||
// RS256, PS256, ES256 --> JWSAlgorithm.RS256.getName(); | ||
} |
6 changes: 6 additions & 0 deletions
6
certify-core/src/main/java/io/mosip/certify/core/constants/VCDM1Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.mosip.certify.core.constants; | ||
|
||
public class VCDM1Constants { | ||
public static final String ISSUANCE_DATE = "issuanceDate"; | ||
public static final String EXPIRATION_DATE = "expirationDate"; | ||
} |
11 changes: 11 additions & 0 deletions
11
certify-core/src/main/java/io/mosip/certify/core/constants/VCDM2Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.mosip.certify.core.constants; | ||
|
||
/** | ||
* VC Data Model 2.0 Constants are some constant fields for the (draft) | ||
* VC DataModel 2.0. | ||
* ref: | ||
*/ | ||
public class VCDM2Constants { | ||
public static final String VALID_UNITL = "validUntil"; | ||
public static final String VALID_FROM = "validFrom"; | ||
} |
8 changes: 8 additions & 0 deletions
8
certify-core/src/main/java/io/mosip/certify/core/constants/VCDMConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.mosip.certify.core.constants; | ||
|
||
public class VCDMConstants { | ||
|
||
// the below assertionMethods are common b/w VC 1.1 & VC 2.0 | ||
public static final String ASSERTION_METHOD = "assertionMethod"; | ||
public static final String PROOF = "proof"; | ||
} |
34 changes: 34 additions & 0 deletions
34
certify-core/src/main/java/io/mosip/certify/core/entity/TemplateData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.mosip.certify.core.entity; | ||
|
||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import jakarta.validation.constraints.NotBlank; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@IdClass(TemplateId.class) | ||
public class TemplateData { | ||
@NotBlank(message = "Template is mandatory") | ||
@Getter | ||
@Setter | ||
private String template; | ||
@Id | ||
@Getter | ||
@Setter | ||
private String context; | ||
@Id | ||
@Getter | ||
@Setter | ||
private String credentialType; | ||
|
||
@NotBlank | ||
@Column(name = "cr_dtimes") | ||
private LocalDateTime createdTimes; | ||
|
||
@Column(name = "upd_dtimes") | ||
private LocalDateTime updatedTimes; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
certify-core/src/main/java/io/mosip/certify/core/entity/TemplateId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.mosip.certify.core.entity; | ||
|
||
import lombok.*; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TemplateId implements Serializable { | ||
@Getter | ||
@Setter | ||
private String context; | ||
@Getter | ||
@Setter | ||
private String credentialType; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof TemplateId that)) return false; | ||
return Objects.equals(context, that.context) && Objects.equals(credentialType, that.credentialType); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(context, credentialType); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
certify-core/src/main/java/io/mosip/certify/core/repository/TemplateRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.mosip.certify.core.repository; | ||
|
||
import io.mosip.certify.core.entity.TemplateData; | ||
import io.mosip.certify.core.entity.TemplateId; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface TemplateRepository extends JpaRepository<TemplateData, TemplateId> { | ||
Optional<TemplateData> findByCredentialTypeAndContext(String credentialType, String context); | ||
// NOTE: best practice? .save() | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
...src/test/java/io/mosip/certify/core/validators/CredentialRequestValidatorFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.mosip.certify.core.validators; | ||
|
||
import io.mosip.certify.core.constants.VCFormats; | ||
import io.mosip.certify.core.dto.CredentialDefinition; | ||
import io.mosip.certify.core.dto.CredentialRequest; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class CredentialRequestValidatorFactoryTest { | ||
|
||
CredentialRequestValidatorFactory factory; | ||
|
||
@Before | ||
public void setUp() { | ||
factory = new CredentialRequestValidatorFactory(); | ||
} | ||
|
||
@Test | ||
public void isValid_invalidFormat() { | ||
CredentialRequest cr = new CredentialRequest(); | ||
cr.setFormat("fake-format"); | ||
assertFalse(factory.isValid(cr)); | ||
} | ||
|
||
@Test | ||
public void isValid_LDP_true() { | ||
CredentialRequest cr = new CredentialRequest(); | ||
cr.setFormat(VCFormats.LDP_VC); | ||
cr.setCredential_definition(new CredentialDefinition()); | ||
assertTrue(factory.isValid(cr)); | ||
} | ||
|
||
@Test | ||
public void isValid_mDoc_true() { | ||
CredentialRequest cr = new CredentialRequest(); | ||
cr.setFormat(VCFormats.MSO_MDOC); | ||
cr.setDoctype("mDoc-doctype-fake"); | ||
cr.setClaims(Map.of("isAge", "21")); | ||
CredentialDefinition cd = new CredentialDefinition(); | ||
cd.setType(List.of("VerifiableCredential", "MockDrivingLicense")); | ||
cd.setContext(List.of("https://example.context.page.sh")); | ||
cr.setCredential_definition(new CredentialDefinition()); | ||
assertTrue(factory.isValid(cr)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#set($validFrom = $validFrom) ## Assume $validFrom might be null or undefined | ||
#set($validUntil = $validUntil) ## Assume $validFrom might be null or undefined | ||
|
||
{ | ||
"@context": [ | ||
"https://www.w3.org/ns/credentials/v2", | ||
"${context}" | ||
], | ||
"type": [ | ||
"VerifiableCredential", | ||
"SchoolCertificate" | ||
], | ||
"validFrom": "${validFrom}", | ||
"issuer": "${issuer}", | ||
#if($validUntil) | ||
"validUntil": "${validUntil}", | ||
#end | ||
"credentialSubject": { | ||
"foundingDate": "${dob}", | ||
"city": "${city}", | ||
#if($amenities) | ||
"amenities": #if($amenities)$amenities#else#set($amenities = '"[]"') $amenities#end, | ||
#end | ||
"name": "${name}", | ||
"principalName": "${principalName}", | ||
"schoolType": "${schoolType}", | ||
"country": "${country}", | ||
"schoolRegistrationNumber": "${policyName}" | ||
}, | ||
"renderMethod": [{ | ||
"id": "https://vharsh.github.io/DID/insurance_svg_template.svg", | ||
"type": "SvgRenderingTemplate", | ||
"name": "Portrait Mode", | ||
"css3MediaQuery": "@media (orientation: portrait)", | ||
"digestMultibase": "zQmAPdhyxzznFCwYxAp2dRerWC85Wg6wFl9G270iEu5h6JqW" | ||
}] | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
...ation-api/src/main/java/io/mosip/certify/api/exception/DataProviderExchangeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.mosip.certify.api.exception; | ||
|
||
import io.mosip.certify.api.util.ErrorConstants; | ||
|
||
/** | ||
* {@link DataProviderExchangeException} is thrown when the DataProvider | ||
* plugin fails to return user data against a set of claims generated by | ||
* an Authentication provider. | ||
*/ | ||
public class DataProviderExchangeException extends Exception { | ||
private String errorCode; | ||
|
||
public DataProviderExchangeException() { | ||
super(ErrorConstants.VCI_DATAFETCH_FAILED); | ||
this.errorCode = ErrorConstants.VCI_DATAFETCH_FAILED; | ||
} | ||
|
||
public DataProviderExchangeException(String errorCode) { | ||
super(errorCode); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public DataProviderExchangeException(String errorCode, String errorMessage) { | ||
super(errorCode + " -> " + errorMessage); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public String getErrorCode() { | ||
return errorCode; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
certify-integration-api/src/main/java/io/mosip/certify/api/spi/DataProviderPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.mosip.certify.api.spi; | ||
|
||
import io.mosip.certify.api.exception.DataProviderExchangeException; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* DataProviderPlugin is implemented by type#2 of identity plugin | ||
* implementors to fetch data for Certify to template into a VC | ||
* format of choice using {@link VCFormatter}. | ||
*/ | ||
public interface DataProviderPlugin { | ||
Map<String, Object> fetchData(Map<String, Object> identityDetails) throws DataProviderExchangeException; | ||
} |
13 changes: 13 additions & 0 deletions
13
certify-integration-api/src/main/java/io/mosip/certify/api/spi/VCFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.mosip.certify.api.spi; | ||
|
||
|
||
import java.util.Map; | ||
/** | ||
* VCDataModelFormatter is a templating engine which takes @param templateInput and returns a templated VC. | ||
* Some implementations include | ||
* - VC 2.0 data model templating engine | ||
*/ | ||
public interface VCFormatter { | ||
// TODO: Should it be changed to JSONObject? | ||
String format(Map<String, Object> templateInput, Map<String, Object> defaultSettings); | ||
} |
11 changes: 11 additions & 0 deletions
11
certify-integration-api/src/main/java/io/mosip/certify/api/spi/VCSigner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.mosip.certify.api.spi; | ||
|
||
import io.mosip.certify.api.dto.VCResult; | ||
import java.util.Map; | ||
|
||
/** | ||
* VCSigner can sign any VC provided a vcHash & Signer inputs | ||
*/ | ||
public interface VCSigner { | ||
VCResult<?> perform(String templatedVC, Map<String, String> params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.