Skip to main content

Scripts for signing using KSP library on Jenkins

Get DigiCert​​®​​ Software Trust Manager client tools setup for Jenkins. Integration with Jenkins will allow for automation into a CI/CD pipeline.

Prerequisites

  • Jenkins build system

  • Any agent with OS that supports Java on Jenkins

  • JDK installed on the agent

  • DigiCert​​®​​ Software Trust Manager setup

  • DigiCert​​®​​ Software Trust Manager client for your OS

  • Signing tools present for the required signing (such as signtool.exe or mage.exe)

注意

You can download client tools from the DigiCert ONE® portal in the DigiCert​​®​​ Software Trust Manager > Resources > Client tool repository.

Client tools

DigiCert​​®​​ Software Trust Manager clients can be downloaded in a package.

Download Client tools

  1. Sign in to DigiCert ONE.

  2. Navigate to DigiCert​​®​​ Software Trust Manager > Resources > Client tool repository.

  3. Select your operating system.

  4. Click the download icon next to DigiCert​​®​​ Software Trust Manager clients.

Register the KSP

To register the KSP, open a command prompt and run:

smksp_registrar.exe register

Verify the KSP

To verify that your KSP is configured properly, and that your client can properly authenticate to the DigiCert​​®​​ Software Trust Manager service, run:

certutil.exe -csp "DigiCert Software Trust Manager KSP" -key -user

Synchronize certificates

For the client tools to access the private keys in the service through the Key Storage Provider (KSP), your certificates must be synchronized to the local certificate store. Only if the certificate is synchronized, the private key remains stored securely in DigiCert​​®​​ Software Trust Manager.

To synchronize your certificates to the local certificate store, open a command prompt and run:

smksp_cert_sync.exe

To view the certificates, open Certificate Manager for the user account used to run the certificate sync utility:

certmgr.msc

If you do not see your certificates in the Certificate Manager, verify that you have opened the correct certificate store. There is a different certificate store for each Windows user account.

注意

All certificates are synched to the user store only. The certificates are not synchronized to the machine store (yet).

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:

  1. Sign in to DigiCert ONE.

  2. Select the profile icon (top-right).

  3. Select Admin Profile.

  4. Scroll down to API Tokens.

  5. Select  Create API token.

    注意

    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:

  1. Sign in to DigiCert ONE.

  2. Select the profile icon (top-right).

  3. Select Admin Profile.

  4. Scroll down to Authentication certificates.

  5. Select Create authentication certificate.

    注意

    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.

Download required signing tools

Follow the instructions in the articles below to integrate with signing tools.

注意

For more information regarding which file types can be signed with these signing tools, refer to: Integrate third-party signing tools.

Integration with Jenkins

Environment variables setup for pipeline

The client tools need these environment variables to connect with DigiCert​​®​​ Software Trust Manager to provide its service. They can be integrated as environment variables that are part of the pipeline as shown in the example below or they can be configured at an OS environment level.

pipeline {
          environment{
       SM_CLIENT_CERT_PASSWORD='**********'
       SM_CLIENT_CERT_FILE='<Path to client Auth Cert File>'
       SM_HOST='https://clientauth.one.digicert.com'
       SM_API_KEY='<Api Token>'
          }
}

Create keypair and certificate

Create test keypair and certificate

stage('keypair setup') {
  steps {
    bat 'smctl keypair generate rsa <Keypair Name> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID> --generate-cert=true --key-type=TEST'
}

The keypair name and certificate name must be unique inputs, meaning that they cannot exist on the portal already.

You can retrieve the certificate profile ID from the DigiCert One portal at DigiCert​​®​​ Software Trust Manager > Certificates > Certificate profiles. Select a profile (Profile category should be Test) that you want to use to generate the certificate.

Create a certificate from an existing keypair

An example of a Jenkins stage to generate a certificate for an existing keypair:

stage('keypair setup') {
   steps {
     bat 'smctl keypair generate-cert <Keypair ID> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID> --set-as-default-cert=true --key-  type=PRODUCTION'
}

For this step, 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:

  • Running a "smctl keypair ls" command on the command line with all environment variables set up.

  • Referring to the DigiCert​​®​​ Software Trust Manager on the DigiCert One portal and going to DigiCert​​®​​ Software Trust Manager > Keypairs and clicking on a keypair.

As in the previous use cases, the certificate profile ID used must belong to the correct profile category.

Sign

You can sign with Jarsigner, Mage, NuGet, or SignTool.

Sign with SignTool

To sign with SignTool:

stage('sign') {
  steps {
    bat 'signtool.exe sign /csp "DigiCert Signing Manager KSP" /kc "KeypairAlias" /f certificate.crt /tr http://timestamp.digicert.com UNSIGNED.EXE'
}

The input parameters are the alias of the keypair used for signing, the name/alias of the certificate that needs to be used for signing, and the path to the file that needs to be signed.

Sign with Mage

To sign with Mage:

stage('sign') {
  steps {
    bat 'mage -sign deploy.application -CertFile certificate.crt -KeyContainer KeypairAlias -CryptoProvider “DigiCert Signing Manager KSP” '
}

The input parameters are the path to the file that needs to be signed, the name/alias of the certificate that needs to be used for signing, and the alias of the keypair used for signing.

Sign with NuGet

To sign with NuGet:

stage('sign') {
  steps {
    bat 'nuget sign HelloWorld.1.3.0.17\* -Timestamper http://timestamp.digicert.com -outputdirectory ..\am-HelloWorld.1.3.0.17 -CertificateFingerprint ‎fe509cdc76517a18a37d927e770216b35683d656 -Verbosity detailed -Overwrite'
}

The input parameters are the the path to the file that needs to be signed, the path of the output signed file, and the fingerprint of the certificate that needs to be used for signing.

Sign with Jarsigner

To sign with Jarsigner:

stage('sign') {
  steps {
    bat 'jarsigner -keystore NONE -storetype Windows-My -signedjar <signed_file>.jar -sigalg SHA256withRSA -digestalg SHA256 <jarfile> <alias>'
}

The input parameters are the path where the signed jar needs to be output, the path to the jar that needs to be signed, and the name/alias of the certificate that needs to be used for signing.

Verify signature

You can verify a signature with Jarsigner, Mage, NuGet, or SignTool.

Verify signature with Jarsigner

To verify a signature with Jarsigner:

stage('verify') {
  steps {
    bat 'jarsigner -verify <Path to Signed Jar>'
}

Verify signature with Mage

To verify a signature with Mage:

stage('verify') {
  steps {
    bat 'mage.exe  -verify deploy.application'
}

Verify signature with NuGet

To verify a signature with NuGet:

stage('verify') {
  steps {
    bat 'nuget verify -All am-HelloWorld.1.3.0.17\*'
}

Verify signature with SignTool

To verify a signature with SignTool:

stage('verify') {
 steps {
   bat 'signtool.exe sign verify /v /pa UNSIGNED.EXE'
}