-
Notifications
You must be signed in to change notification settings - Fork 27
CorDapp Packaging
This document describes how to build format version 2 CPKs, CPBs and CPIs.
You will need a working copy of corda-cli
with the mgm and package plugins installed. See https://github.com/corda/corda-cli-plugin-host#setupbuild.
This describes how to convert an existing CorDapp project to the new Gradle plugin.
- Add a new version number to
gradle.properties
:cordaGradlePluginsVersion2=7.0.0-SNAPSHOT
- Add this repository to pluginManagement/repositories in
settings.gradle
:maven { url "${artifactoryContextUrl}/corda-dev" content { includeGroupByRegex 'net\\.corda\\.plugins(\\..*)?' } }
- Add the plugin to the plugins section of
settings.gradle
:id 'net.corda.plugins.cordapp-cpk2' version cordaGradlePluginsVersion2 id 'net.corda.plugins.cordapp-cpb2' version cordaGradlePluginsVersion2
- Inside the cordapp project change the plugins block at the top of the file:
id 'net.corda.plugins.cordapp-cpk2' // or id 'net.corda.plugins.cordapp-cpb2'
We need to generate a code signing key for signing the CPI. This key can be generated once and kept for reuse.
- Generate a signing key
keytool -genkeypair -alias "signing key 1" -keystore signingkeys.pfx -storepass "keystore password" -dname "cn=CPI Plugin Example - Signing Key 1, o=R3, L=London, c=GB" -keyalg RSA -storetype pkcs12 -validity 4000
- If we are using the gradle plugin default signing key, we need to import it into our key store. Save the following text into a file named
gradle-plugin-default-key.pem
-----BEGIN CERTIFICATE----- MIIB7zCCAZOgAwIBAgIEFyV7dzAMBggqhkjOPQQDAgUAMFsxCzAJBgNVBAYTAkdC MQ8wDQYDVQQHDAZMb25kb24xDjAMBgNVBAoMBUNvcmRhMQswCQYDVQQLDAJSMzEe MBwGA1UEAwwVQ29yZGEgRGV2IENvZGUgU2lnbmVyMB4XDTIwMDYyNTE4NTI1NFoX DTMwMDYyMzE4NTI1NFowWzELMAkGA1UEBhMCR0IxDzANBgNVBAcTBkxvbmRvbjEO MAwGA1UEChMFQ29yZGExCzAJBgNVBAsTAlIzMR4wHAYDVQQDExVDb3JkYSBEZXYg Q29kZSBTaWduZXIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQDjSJtzQ+ldDFt pHiqdSJebOGPZcvZbmC/PIJRsZZUF1bl3PfMqyG3EmAe0CeFAfLzPQtf2qTAnmJj lGTkkQhxo0MwQTATBgNVHSUEDDAKBggrBgEFBQcDAzALBgNVHQ8EBAMCB4AwHQYD VR0OBBYEFLMkL2nlYRLvgZZq7GIIqbe4df4pMAwGCCqGSM49BAMCBQADSAAwRQIh ALB0ipx6EplT1fbUKqgc7rjH+pV1RQ4oKF+TkfjPdxnAAiArBdAI15uI70wf+xlL zU+Rc5yMtcOY4/moZUq36r0Ilg== -----END CERTIFICATE-----
- Import
gradle-plugin-default-key.pem
into the keystorekeytool -importcert -keystore signingkeys.pfx -storepass "keystore password" -noprompt -alias gradle-plugin-default-key -file gradle-plugin-default-key.pem
Please refer to the group policy wiki page to learn more about the GroupPolicy.json
file included in CPIs: Group Policy
If you intend to run a basic static network setup, you can use the corda-cli mgm plugin to generate a group policy file. For example, you could run this command to generate a group policy file:
./corda-cli.sh mgm groupPolicy > TestGroupPolicy.json
Refer to the plugin README.md
for more information on this plugin: README.md
If running a dynamic network, you will need to export the group policy file from the MGM using the HTTP API. Information on how to do this can be found on the MGM Onboarding wiki page.
The gradle plugin will build the CPB. Run this command to turn a CPB into a CPI:
./corda-cli.sh package create-cpi \
--cpb mycpb.cpb \
--group-policy TestGroupPolicy.json \
--cpi-name "cpi name" \
--cpi-version "1.0.0.0-SNAPSHOT" \
--file output.cpi \
--keystore signingkeys.pfx \
--storepass "keystore password" \
--key "signing key 1"
Corda will validate that uploaded CPIs are signed with a trusted key. To trust your signing keys, upload them with these commands.
- Import the gradle plugin default key into Corda
curl --insecure -u admin:admin -X PUT -F alias="gradle-plugin-default-key" -F [email protected] https://localhost:8888/api/v1/certificates/cluster/codesigner
- Export the signing key certificate from the key store
keytool -exportcert -rfc -alias "signing key 1" -keystore signingkeys.pfx -storepass "keystore password" -file signingkey1.pem
- Import the signing key into Corda
Use an alias that will be unique over time. Consider how certificate expiry will require new certificates with the same x500 name as existing certificates and define a naming convention that covers that use case.
curl --insecure -u admin:admin -X PUT -F alias="signingkey1-2022" -F [email protected] https://localhost:8888/api/v1/certificates/cluster/codesigner