Skip to content

Commit

Permalink
[INJICERT-657] rename Svg -> SVG and other minor changes (#149)
Browse files Browse the repository at this point in the history
* [INJICERT-657] rename Svg -> SVG and other minor changes

Signed-off-by: Harsh Vardhan <[email protected]>

* [INJICERT-657] make mass renames, update DB

Changes:
* svg_template DB becomes template_registry & it's ID column becomes a
  String from UUID type

Signed-off-by: Harsh Vardhan <[email protected]>

* [INJICERT-657] move proofgenerator package

Signed-off-by: Harsh Vardhan <[email protected]>

* Docker and script code changes

Signed-off-by: Piyush7034 <[email protected]>

* [INJICERT-657] rename Certify keys in KeyManager

Signed-off-by: Harsh Vardhan <[email protected]>

* [INJICERT-657] rename Certify keys in KeyManager

Signed-off-by: Harsh Vardhan <[email protected]>

* [INJICERT-657] move VCFormatter & VCSigner to certify-service

Signed-off-by: Harsh Vardhan <[email protected]>

* [INJICERT-657] make Velocity template cacheable

Signed-off-by: Harsh Vardhan <[email protected]>

---------

Signed-off-by: Harsh Vardhan <[email protected]>
Signed-off-by: Piyush7034 <[email protected]>
Co-authored-by: Piyush7034 <[email protected]>
Signed-off-by: Vishwa <[email protected]>
  • Loading branch information
vharsh and Piyush7034 authored Dec 17, 2024
1 parent 62de89c commit 55ecc97
Show file tree
Hide file tree
Showing 90 changed files with 548 additions and 2,491 deletions.
40 changes: 1 addition & 39 deletions certify-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,48 +53,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- templating dependencies -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public class Constants {
public static final String CLIENT_ID = "client_id";
public static final String CERTIFY_PARTNER_APP_ID = "CERTIFY_PARTNER";
public static final String CERTIFY_SERVICE_APP_ID = "CERTIFY_SERVICE";
public static final String CERTIFY_VC_SIGN_RSA = "CERTIFY_VC_SIGN_RSA";
public static final String CERTIFY_VC_SIGN_ED25519 = "CERTIFY_VC_SIGN_ED25519";
public static final String ROOT_KEY = "ROOT";
public static final String EMPTY_REF_ID = "";
public static final String ED25519_REF_ID = "ED25519_SIGN";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ErrorConstants {
public static final String PROOF_HEADER_INVALID_ALG = "proof_header_invalid_alg";
public static final String PROOF_HEADER_INVALID_KEY = "proof_header_invalid_key";
public static final String PROOF_HEADER_AMBIGUOUS_KEY = "proof_header_ambiguous_key";
public static final String UNSUPPORTED_OPENID_VERSION = "unsupported_openid4vci_draft_version";
public static final String UNSUPPORTED_OPENID_VERSION = "unsupported_openid4vci_version";
public static final String INVALID_TEMPLATE_ID = "template_with_id_not_found";
public static final String EMPTY_TEMPLATE_CONTENT = "empty_template_content";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
public class SignatureAlg {
// LinkedDataSignature Algorithms
public static final String RSA_SIGNATURE_SUITE = "RsaSignature2018";
public static final String RSA_SIGNATURE_SUITE_2018 = "RsaSignature2018";

public static final String ED25519_SIGNATURE_SUITE = "Ed25519Signature2018";
public static final String ED25519_SIGNATURE_SUITE_2018 = "Ed25519Signature2018";

public static final String ED25519_SIGNATURE_SUITE_2020 = "Ed25519Signature2020";

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
import io.mosip.certify.api.exception.VCIExchangeException;

import java.util.Map;

/**
* VCIssuancePlugin is implemented by VC plugin
* implementors who want to make use of an existing VC Issuance Infrastructure
* or want to do everything by themselves to generate the VC from the plugin.
* VC is received by the plugin and sent to Certify and forwarded to the
* client applications.
*/
public interface VCIssuancePlugin {

/**
Expand Down

This file was deleted.

22 changes: 21 additions & 1 deletion certify-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,27 @@
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.41.2</version>
</dependency>

<!-- templating dependencies -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.mosip.certify</groupId>
<artifactId>certify-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@EnableCaching
@SpringBootApplication(scanBasePackages = "io.mosip.certify,"+
"io.mosip.certify.core.*," +
"io.mosip.certify.services.repository," +
"io.mosip.certify.services.entity," +
"io.mosip.kernel.crypto," +
"io.mosip.kernel.keymanager.hsm," +
"io.mosip.kernel.cryptomanager," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import io.mosip.certify.core.constants.Constants;
import io.mosip.certify.services.KeyManagerConstants;
import io.mosip.kernel.keymanagerservice.dto.KeyPairGenerateRequestDto;
import io.mosip.kernel.keymanagerservice.service.KeymanagerService;
import io.mosip.kernel.keymanagerservice.dto.SymmetricKeyGenerateRequestDto;
Expand All @@ -31,8 +30,8 @@
import org.springframework.web.client.RestTemplate;

@Configuration
@EnableJpaRepositories(basePackages = {"io.mosip.kernel.keymanagerservice.repository", "io.mosip.certify.core.repository"})
@EntityScan(basePackages = {"io.mosip.kernel.keymanagerservice.entity, io.mosip.certify.core.entity"})
@EnableJpaRepositories(basePackages = {"io.mosip.kernel.keymanagerservice.repository", "io.mosip.certify.services.repository"})
@EntityScan(basePackages = {"io.mosip.kernel.keymanagerservice.entity, io.mosip.certify.services.entity"})
@Slf4j
public class AppConfig implements ApplicationRunner {

Expand Down Expand Up @@ -75,7 +74,7 @@ public void run(ApplicationArguments args) throws Exception {
log.info("===================== CERTIFY_SERVICE ROOT KEY CHECK ========================");
String objectType = "CSR";
KeyPairGenerateRequestDto rootKeyRequest = new KeyPairGenerateRequestDto();
rootKeyRequest.setApplicationId(KeyManagerConstants.ROOT_KEY);
rootKeyRequest.setApplicationId(Constants.ROOT_KEY);
// Set the reference id to empty string, as keymanager is expecting the same for initialization
rootKeyRequest.setReferenceId(org.apache.commons.lang3.StringUtils.EMPTY);
keymanagerService.generateMasterKey(objectType, rootKeyRequest);
Expand All @@ -87,8 +86,8 @@ public void run(ApplicationArguments args) throws Exception {
keymanagerService.generateMasterKey(objectType, masterKeyRequest);
// TODO: Generate an EC & ED key via K8s Job(INJICERT-469)
KeyPairGenerateRequestDto rsaKeyRequest = new KeyPairGenerateRequestDto();
rsaKeyRequest.setApplicationId(KeyManagerConstants.CERTIFY_MOCK_RSA);
rsaKeyRequest.setReferenceId(KeyManagerConstants.EMPTY_REF_ID);
rsaKeyRequest.setApplicationId(Constants.CERTIFY_VC_SIGN_RSA);
rsaKeyRequest.setReferenceId(Constants.EMPTY_REF_ID);
rsaKeyRequest.setForce(false);
keymanagerService.generateMasterKey("certificate", rsaKeyRequest);
if(!StringUtils.isEmpty(cacheSecretKeyRefId)) {
Expand All @@ -109,13 +108,13 @@ public void run(ApplicationArguments args) throws Exception {
// Generate an Ed25519Key:
// 1. Generate a master key first to enable Keymanager to store the key.
KeyPairGenerateRequestDto storeKey = new KeyPairGenerateRequestDto();
storeKey.setApplicationId(KeyManagerConstants.CERTIFY_MOCK_ED25519);
storeKey.setReferenceId(org.apache.commons.lang3.StringUtils.EMPTY);
storeKey.setApplicationId(Constants.CERTIFY_VC_SIGN_ED25519);
storeKey.setReferenceId(Constants.EMPTY_REF_ID);
keymanagerService.generateMasterKey("certificate", storeKey);
// 2. Generate an Ed25519 key later
KeyPairGenerateRequestDto ed25519Req = new KeyPairGenerateRequestDto();
ed25519Req.setApplicationId(KeyManagerConstants.CERTIFY_MOCK_ED25519);
ed25519Req.setReferenceId(KeyManagerConstants.ED25519_REF_ID);
ed25519Req.setApplicationId(Constants.CERTIFY_VC_SIGN_ED25519);
ed25519Req.setReferenceId(Constants.ED25519_REF_ID);
keymanagerService.generateECSignKey("certificate", ed25519Req);
log.info("===================== CERTIFY KEY SETUP COMPLETED ========================");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.certify.core.entity.SvgTemplate;
import io.mosip.certify.core.exception.CertifyException;
import io.mosip.certify.core.repository.SvgTemplateRepository;
import io.mosip.certify.services.entity.RenderingTemplate;
import io.mosip.certify.services.repository.RenderingTemplateRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -30,11 +29,11 @@

@Configuration
@Slf4j
public class TemplateConfig implements CommandLineRunner {
public class TemplatesLoader implements CommandLineRunner {
@Autowired
SvgTemplateRepository svgRenderTemplateRepository;
RenderingTemplateRepository svgRenderTemplateRepository;

@Value("${mosip.certify.svg-templates}")
@Value("${mosip.certify.rendering-templates:}")
private String svgTemplateJson;

@Autowired
Expand All @@ -45,35 +44,31 @@ public class TemplateConfig implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
Long count = svgRenderTemplateRepository.count();
if (count != 0) {
return;
}
String svgTemplateContent = "";
List<Object> svgTemplateMap;

if(svgTemplateJson.startsWith("http")) {
svgTemplateContent = restTemplate.getForObject(svgTemplateJson, String.class);
} else {
Resource resource = new ClassPathResource(svgTemplateJson);
// TODO: Verify this w.r.t local path
try {
svgTemplateContent = (Files.readString(resource.getFile().toPath()));
} catch (IOException e) {
log.error("Missing local json file for referring svg templates", e);
}
}


if(!svgTemplateContent.isEmpty()) {
try {
svgTemplateMap = objectMapper.readValue(svgTemplateContent, List.class);
} catch (JsonProcessingException e) {
throw new CertifyException("Missing configuration for svg template content " + e.getMessage());
}

List<SvgTemplate> svgRenderTemplates = svgRenderTemplateRepository.findAll();

if(svgRenderTemplates.isEmpty()) {
List <Object> svgTemplateMap = objectMapper.readValue(svgTemplateContent, List.class);
svgTemplateMap.forEach((value) -> {
SvgTemplate svgRenderTemplate = new SvgTemplate();
RenderingTemplate svgRenderTemplate = new RenderingTemplate();
LinkedHashMap<String, Object> valueMap = (LinkedHashMap<String, Object>) value;
UUID id = UUID.fromString(valueMap.get("id").toString());
String id = valueMap.get("id").toString();
svgRenderTemplate.setId(id);
String templateURI = valueMap.get("content").toString();
if(templateURI.startsWith("http")) {
Expand All @@ -88,7 +83,10 @@ public void run(String... args) throws Exception {
log.info("Template inserted in svg template table.");
svgRenderTemplateRepository.save(svgRenderTemplate);
});
} catch (JsonProcessingException e) {
log.error("Missing configuration for svg template content " + e.getMessage());
}

}
log.info("=============== CERTIFY TEMPLATE SETUP COMPLETED ===============");
}
Expand Down
Loading

0 comments on commit 55ecc97

Please sign in to comment.