forked from mosip/inji-certify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INJICERT-617] add support for EC K1 key generation & VC signing (mos…
…ip#200) * [INJICERT-617] add support for EC K1 key generation & VC signing Signature support added: - EcdsaKoblitzSignature2016 - EcdsaSecp256k1Signature2019 (verified) Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-544] add context for ldp_vc in docker compose Signed-off-by: Harsh Vardhan <[email protected]> --------- Signed-off-by: Harsh Vardhan <[email protected]>
- Loading branch information
Showing
15 changed files
with
217 additions
and
6 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
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
62 changes: 62 additions & 0 deletions
62
...c/main/java/io/mosip/certify/proofgenerators/EcdsaKoblitzSignature2016ProofGenerator.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,62 @@ | ||
package io.mosip.certify.proofgenerators; | ||
|
||
import com.danubetech.keyformats.jose.JWSAlgorithm; | ||
import info.weboftrust.ldsignatures.LdProof; | ||
import info.weboftrust.ldsignatures.canonicalizer.Canonicalizer; | ||
import info.weboftrust.ldsignatures.canonicalizer.URDNA2015Canonicalizer; | ||
import io.mosip.certify.core.constants.Constants; | ||
import io.mosip.certify.core.constants.SignatureAlg; | ||
import io.mosip.kernel.signature.dto.JWSSignatureRequestDto; | ||
import io.mosip.kernel.signature.dto.JWTSignatureResponseDto; | ||
import io.mosip.kernel.signature.service.SignatureService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* EcdsaKoblitzSignature2016 as per https://w3c-ccg.github.io/lds-koblitz2016/ | ||
* - secp256k1 | ||
* - used by Bitcoin & Etherium | ||
* - from W3C Web Payments Community Group | ||
* | ||
* // NOTE: Avoid using this signature and use the 2019 EC K1 instead. | ||
*/ | ||
@Component | ||
@ConditionalOnProperty(name = "mosip.certify.data-provider-plugin.issuer.vc-sign-algo", havingValue = SignatureAlg.EC_K1_2016) | ||
public class EcdsaKoblitzSignature2016ProofGenerator implements ProofGenerator { | ||
|
||
@Autowired | ||
SignatureService signatureService; | ||
|
||
Canonicalizer canonicalizer = new URDNA2015Canonicalizer(); | ||
|
||
@Override | ||
public String getName() { | ||
return SignatureAlg.EC_K1_2016; | ||
} | ||
|
||
@Override | ||
public Canonicalizer getCanonicalizer() { | ||
return canonicalizer; | ||
} | ||
|
||
@Override | ||
public LdProof generateProof(LdProof vcLdProof, String vcEncodedHash, Map<String, String> keyID) { | ||
JWSSignatureRequestDto payload = new JWSSignatureRequestDto(); | ||
payload.setDataToSign(vcEncodedHash); | ||
payload.setApplicationId(keyID.get(Constants.APPLICATION_ID)); | ||
payload.setReferenceId(keyID.get(Constants.REFERENCE_ID)); | ||
payload.setIncludePayload(false); | ||
payload.setIncludeCertificate(false); | ||
payload.setIncludeCertHash(true); | ||
payload.setValidateJson(false); | ||
payload.setB64JWSHeaderParam(false); | ||
payload.setCertificateUrl(""); | ||
payload.setSignAlgorithm(JWSAlgorithm.ES256K); | ||
JWTSignatureResponseDto jwsSignedData = signatureService.jwsSign(payload); | ||
return LdProof.builder().base(vcLdProof).defaultContexts(false) | ||
.jws(jwsSignedData.getJwtSignedData()).build(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...main/java/io/mosip/certify/proofgenerators/EcdsaSecp256k1Signature2019ProofGenerator.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,60 @@ | ||
package io.mosip.certify.proofgenerators; | ||
|
||
import com.danubetech.keyformats.jose.JWSAlgorithm; | ||
import info.weboftrust.ldsignatures.LdProof; | ||
import info.weboftrust.ldsignatures.canonicalizer.Canonicalizer; | ||
import info.weboftrust.ldsignatures.canonicalizer.URDNA2015Canonicalizer; | ||
import io.mosip.certify.core.constants.Constants; | ||
import io.mosip.certify.core.constants.SignatureAlg; | ||
import io.mosip.kernel.signature.dto.JWSSignatureRequestDto; | ||
import io.mosip.kernel.signature.dto.JWTSignatureResponseDto; | ||
import io.mosip.kernel.signature.service.SignatureService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* EcdsaSecp256k1Signature2019 as per https://w3c-ccg.github.io/lds-ecdsa-secp256k1-2019/ | ||
* - secp256k1 | ||
* - from W3C Web Payments Community Group | ||
* - ref: https://w3c-ccg.github.io/ld-cryptosuite-registry/#ecdsasecp256k1signature2019 | ||
*/ | ||
@Component | ||
@ConditionalOnProperty(name = "mosip.certify.data-provider-plugin.issuer.vc-sign-algo", havingValue = SignatureAlg.EC_SECP256K1_2019) | ||
public class EcdsaSecp256k1Signature2019ProofGenerator implements ProofGenerator { | ||
|
||
@Autowired | ||
SignatureService signatureService; | ||
|
||
Canonicalizer canonicalizer = new URDNA2015Canonicalizer(); | ||
|
||
@Override | ||
public String getName() { | ||
return SignatureAlg.EC_SECP256K1_2019; | ||
} | ||
|
||
@Override | ||
public Canonicalizer getCanonicalizer() { | ||
return canonicalizer; | ||
} | ||
|
||
@Override | ||
public LdProof generateProof(LdProof vcLdProof, String vcEncodedHash, Map<String, String> keyID) { | ||
JWSSignatureRequestDto payload = new JWSSignatureRequestDto(); | ||
payload.setDataToSign(vcEncodedHash); | ||
payload.setApplicationId(keyID.get(Constants.APPLICATION_ID)); | ||
payload.setReferenceId(keyID.get(Constants.REFERENCE_ID)); | ||
payload.setIncludePayload(false); | ||
payload.setIncludeCertificate(false); | ||
payload.setIncludeCertHash(true); | ||
payload.setValidateJson(false); | ||
payload.setB64JWSHeaderParam(false); | ||
payload.setCertificateUrl(""); | ||
payload.setSignAlgorithm(JWSAlgorithm.ES256K); | ||
JWTSignatureResponseDto jwsSignedData = signatureService.jwsSign(payload); | ||
return LdProof.builder().base(vcLdProof).defaultContexts(false) | ||
.jws(jwsSignedData.getJwtSignedData()).build(); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
MERGE INTO KEY_POLICY_DEF (APP_ID,KEY_VALIDITY_DURATION,PRE_EXPIRE_DAYS,ACCESS_ALLOWED,IS_ACTIVE,CR_BY,CR_DTIMES) KEY(APP_ID) VALUES ('ROOT', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_SERVICE', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_PARTNER', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_VC_SIGN_RSA', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_VC_SIGN_ED25519', 1095, 50, 'NA', true, 'mosipadmin', now()), ('BASE', 730, 30, 'NA', true, 'mosipadmin', now()); | ||
MERGE INTO KEY_POLICY_DEF (APP_ID,KEY_VALIDITY_DURATION,PRE_EXPIRE_DAYS,ACCESS_ALLOWED,IS_ACTIVE,CR_BY,CR_DTIMES) KEY(APP_ID) VALUES ('ROOT', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_SERVICE', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_PARTNER', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_VC_SIGN_RSA', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_VC_SIGN_ED25519', 1095, 50, 'NA', true, 'mosipadmin', now()), ('BASE', 730, 30, 'NA', true, 'mosipadmin', now()), ('CERTIFY_VC_SIGN_EC_K1', 1095, 50, 'NA', true, 'mosipadmin', now()), ('CERTIFY_VC_SIGN_EC_R1', 1095, 50, 'NA', true, 'mosipadmin', now()); |
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.