Skip to main content

Jenkins script integration with KSP

Get 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

  • setup

  • client for your OS

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

Anmerkung

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

Client tools

DigiCert​​®​​ KeyLocker clients can be downloaded in a package.

Download Client tools

  1. Sign in to DigiCert ONE.

  2. Navigate to DigiCert​​®​​ KeyLocker > Resources > Client tool repository.

  3. Select your operating system.

  4. Click the download icon next to DigiCert​​®​​ KeyLocker 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​​®​​ KeyLocker 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​​®​​ KeyLocker.

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.

Anmerkung

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

DigiCert​​®​​ KeyLocker 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.

    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:

  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.

    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​​®​​ KeyLocker 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.

Anmerkung

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 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>'
          }
}

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'
}