CircleCI script integration with PKCS11
Set up DigiCert® Software Trust Manager client tools and integrate them with CircleCI for automation into a CI/CD pipeline.
Prerequisites
CircleCI build system
Any operating system that supports Java on CircleCI
JDK installed on the agent
DigiCert® Software Trust Manager credentials
DigiCert® Software Trust Manager client tools
Client tools
DigiCert® Software Trust Manager clients can be downloaded in a package.
Download client tools
Sign in to DigiCert ONE.
Navigate to DigiCert® Software Trust Manager > Resources > Client tool repository.
Select your operating system.
Click the download icon next to DigiCert® Software Trust Manager clients.
Create PKCS11 configuration file
To create a configuration file with the path to this shared library:
Open an integrated development environment (IDE) or plain text editor.
Copy and paste the following text into the editor:
Save the file as pkcs11properties.cfg.
Move the pkcs11properties.cfg file to the same location as the PKCS11 library.
Set PATH environment variables
Operating systems use the environment variable called PATH to determine where executable files are stored on your system. Use the PATH environment variable to store the file path to your signing tools to ensure that the CLI can reference these signing tools.
User authentication
Software Trust Manager enforces multifactor authentication for security. To access keypairs, certificates, and sign code, you need to set up two types of credentials: an API token and an authentication certificate.
Create an API token
The API token is an authentication method used to verify you as a user and your permissions assigned in DigiCert ONE. The API token provides the first factor authentication.
Follow these steps to generate an API token:
Sign in to DigiCert ONE.
Select the profile icon (top-right).
Select Admin Profile.
Scroll down to API Tokens.
Select Create API token.
Anmerkung
The API token is only shown once, securely store the API key to use it later.
Create an authentication certificate
The client authentication certificate is an authentication method used to verify you as a user and your permissions assigned in DigiCert ONE. The client authentication certificate provides the second factor authentication.
Follow these steps to create a client authentication certificate:
Sign in to DigiCert ONE.
Select the profile icon (top-right).
Select Admin Profile.
Scroll down to Authentication certificates.
Select Create authentication certificate.
Anmerkung
The client authentication certificate password shown after creating an client authentication certificate cannot be accessed again, download the certificate and securely store the password to use it later.
DigiCert® Software Trust Manager environment variables
Set the following environment variables:
Variable | Description |
---|---|
SM_API_KEY | Provide your API token. |
SM_CLIENT_CERT_FILE | Provide your client authentication certificate. |
SM_CLIENT_CERT_PASSWORD | Provide your client certificate password. |
SM_HOST | Provide your host environment. |
PKCS11_CONFIG | Provide the path to the PKCS11 configuration file. |
SM_TLS_SKIP_VERIFY | Enter true to disable or false to enable TLS verification on client side. |
Integration with CircleCI
Environment variables setup for CircleCI
The client tools need these environment variables to connect with DigiCert® Software Trust Manager to provide its service. They can be integrated as CircleCI Environment Variables in CircleCI project.
To set environment variables in CircleCI, go to Projects > Project Settings > Environment Variables.
Set certificate file in environment variables:
Identify your downloaded client authentication certificate.
Encode the file to base64, using the command:
base64 file_name
Go to CircleCI, go to Projects > Project Settings > Environment Variables.
Select Add Environment Variable and add the new variable name as "SM_CLIENT_CERT_FILE_B64" and the encoded value from base64 file_name in the Value field.
Run this code to setup the certificate file for signing:
steps: - checkout - run: name: "Certificate-Setup" command: | cd C:\ New-Item C:\CERT_FILE.p12.b64 Set-Content -Path C:\CERT_FILE.p12.b64 -Value $env:SM_CLIENT_CERT_FILE_B64 certutil -decode CERT_FILE.p12.b64 Certificate_pkcs12.p12 cat Certificate_pkcs12.p12 environment: SM_CLIENT_CERT_FILE: 'C:\Certificate_pkcs12.p12'
Certificates and keypairs
The following scripts can be used to generate keypairs and certificates.
Create test keypair and certificate
To generate a RSA test keypair with certificate using CircleCI:
steps:
- checkout
- run:
name: "Create-Test-Keypair"
command: |
& $env:SSM\smctl.exe keypair generate rsa <Keypair Name> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID> --generate-cert=true --key-type=TEST
environment:
SSM: 'C:\Program Files\DigiCert\DigiCert One Signing Manager Tools'
Anmerkung
The keypair name and certificate name must be unique, meaning these names cannot already exist on the portal.
To retrieve the certificate profile ID:
Access DigiCert ONE > DigiCert® Software Trust Manager > Certificates > Certificate profiles.
Select a certificate profile to generate the certificate (profile category must be test).
Identify the Profile ID.
Create production keypair with certificate
To generate an RSA production keypair with a given certificate using the CircleCI actions pipeline:
steps:
- checkout
- run:
name: "Create-Production-Keypair"
command: |
& $env:SSM\smctl.exe keypair generate rsa <Keypair Name> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID> --generate-cert=true --key-type=PRODUCTION
environment:
SSM: 'C:\Program Files\DigiCert\DigiCert One Signing Manager Tools'
Anmerkung
Select a certificate profile with the profile category "Production".
Create certificate from an existing keypair
To generate a certificate for an existing keypair using CircleCI:
steps:
- checkout
- run:
name: "Create-Certificate"
command: |
& $env:SSM\smctl.exe keypair generate-cert <Keypair ID> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID>
environment:
SSM: 'C:\Program Files\DigiCert\DigiCert One Signing Manager Tools'
Anmerkung
The inputs required are a keypair ID, certificate name (which must be unique), and certificate profile ID.
You can retrieve the keypair ID in two ways:
Sign
To sign with Jarsigner:
- run: name: "Signing using Jarsigner" command: | jarsigner -keystore NONE -storepass NONE -storetype PKCS11 -sigalg SHA256withRSA -providerClass sun.security.pkcs11.SunPKCS11 -providerArg %PKCS11_CONFIG% -signedjar <path to output the signed .jar> <path to the Jar to be signed> <certificate alias> -tsa http://timestamp.digicert.com
Verify signature
To verify a signature with Jarsigner:
- run: name: "Jarsigner verify" command: | jarsigner -verify <Path to Signed Jar>
The only input for this command is the path to the signed.jar file to be verified.
Sample pipeline
version: 2.1
orbs:
win: circleci/windows@4.1
jobs:
SSM_Signing:
executor: win/server-2022
steps:
- checkout
- run:
name: "Certificate-Setup"
command: |
cd C:\
New-Item C:\CERT_FILE.p12.b64
Set-Content -Path C:\CERT_FILE.p12.b64 -Value $env:SM_CLIENT_CERT_FILE_B64
certutil -decode CERT_FILE.p12.b64 Certificate_pkcs12.p12
- run:
name: "Setting-up-the-client-tools"
command: |
cd C:\
curl.exe -X GET https://one.digicert.com/signingmanager/api-ui/v1/releases/smtools-windows-x64.msi/download -H "x-api-key:$env:SM_API_KEY" -o smtools-windows-x64.msi
msiexec.exe /i smtools-windows-x64.msi /quiet /qn | Wait-Process
- run:
name: "Generate Production Keypair"
command: |
& $env:Smctl keypair generate rsa $env:Keypair --cert-alias=$env:Keypair --cert-profile-id=93a61900-e33f-4d24-a91e-f1e405db4452 --generate-cert=true --key-type=PRODUCTION
- run:
name: "Signing using Jarsigner"
command: |
Copy-Item -Path C:\Users\circleci.PACKER-625580E2\project\UNSIGNED.jar -Destination C:\
jarsigner -keystore NONE -storepass NONE -storetype PKCS11 -sigalg SHA256withRSA -providerClass sun.security.pkcs11.SunPKCS11 -providerArg C:\Users\circleci.PACKER-625580E2\project\pkcs11properties.cfg -signedjar C:\SIGNED.jar C:\UNSIGNED.jar $env:Keypair -tsa http://timestamp.digicert.com
- run:
name: "Jarsigner verify"
command: |
jarsigner -verify C:\SIGNED.jar
environment:
SM_CLIENT_CERT_FILE: 'C:\Certificate_pkcs12.p12'
Keypair: 'keypair_circle_test'
Smctl: 'C:\Program Files\DigiCert\DigiCert One Signing Manager Tools\smctl.exe'
workflows:
my-workflow:
jobs: