Scripts for signing using KSP library on Azure pipeline
Prerequisites
Azure DevOps setup
Windows Custom Agent for Azure DevOps
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.
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:
Sign in to DigiCert ONE.
Select the profile icon (top-right).
Select Admin Profile.
Scroll down to API Tokens.
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:
Sign in to DigiCert ONE.
Select the profile icon (top-right).
Select Admin Profile.
Scroll down to Authentication certificates.
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.
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 Azure DevOps pipeline
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 variables in the pipeline which Azure will automatically inject as environment variables in the agent or they can be configured at an OS environment level.
variables: - name: SM_CLIENT_CERT_PASSWORD value: ********* - name: SM_CLIENT_CERT_FILE value: <Path to Client Auth Cert File> - name: SM_HOST value: https://clientauth.one.digicert.com - name: SM_API_KEY value: <API Token>
The values for these environment variables are explained below:
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. |
Create keypair and certificate
Create test keypair and certificate
An example for an Azure pipeline step to generate an RSA test keypair with certificate:
- task: CmdLine@2 displayName: 'Generate Test Keypair' inputs: script: '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.
To retrieve the certificate profile ID:
Sign in to DigiCert ONE.
Navigate to DigiCert® Software Trust Manager > Certificates > Certificate profiles
Click on the certificate profile alias that you want to generate the certificate with.
注意
Ensure that the profile category shows Test.
Identify the Certificate profile ID field.
Create production keypair with certificate
An example of an Azure pipeline step to generate an RSA production keypair with certificate:
- task: CmdLine@2 displayName: 'Generate Production Keypair' inputs: script: 'smctl keypair generate rsa <Keypair Name> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID> --generate-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:
Run a
smctl keypair ls
command on the command line with all environment variables set up.Navigate to: DigiCert ONE > DigiCert® Software Trust Manager > Keypairs and select a keypair.
As in the previous use cases, the certificate profile ID used must belong to the correct profile category.
Sign
You can sign using SignTool, Mage, or Nuget.
注意
To use the thumbprint method of signing a file you will need to run the smksp_cert_sync.exe tool (provided with KSP) to sync the local certificate store with DigiCert® Software Trust Manager and import any new certificates that you may want to use.
Sign with SignTool
Certificate fingerprint method
An example for an Azure DevOps pipeline step for signing an .exe or .dll with a certificate thumbprint is shown below:
- script: signtool sign /sha1 <Certificate Thumbprint> /tr http://timestamp.digicert.com <Path to the exe/DLL to be signed> displayName: "Sign Artifact"
Downloaded certificate method
An example for an Azure DevOps pipeline step for signing an .exe or .dll with a downloaded code signing certificate is shown below:
- script: signtool sign /csp "Digicert Signing Manager KSP" /kc <Keypair Alias> /f <Path to certificate file> /tr http://timestamp.digicert.com <Path to the exe/DLL to be signed> displayName: "Sign Artifact"
The input parameters for this are the alias for the Keypair on DigiCert® Software Trust Manager, the path to the certificate file, and the path to the exe/DLL to be signed.
Sign with Mage
Certificate fingerprint method
An example step of an Azure DevOps pipeline that signs a package using certificate thumbprint:
- script: mage -Sign <Path to .application file> -CertHash <Certificate thumbprint> displayName: 'Sign App'
Downloaded certificate method
An example step of an Azure DevOps pipeline that signs a package using a downloaded code signing certificate:
- script: mage -Sign <Path to .application file> -CertFile <Path to Certificate file> -KeyContainer <Alias/Name of the Keypair on STM> -CryptoProvider "DigiCert Signing Manager KSP"
displayName: 'Sign App'
Sign with NuGet
Certificate fingerprint method
An example step of an Azure DevOps pipeline that signs a package using NuGet using the certificate thumbprint:
- task: NuGetCommand@2 displayName: 'NuGet Sign Custom Package' inputs: command: 'custom' arguments: 'sign <Path to Package> -Timestamper http://timestamp.digicert.com -CertificateFingerprint <certificate thumbprint> -Verbosity detailed -Overwrite'
Verify signature
You can verify a signature using SignTool, Mage, or Nuget.
Verify signature with SignTool
An example of an Azure DevOps step that verifies a signed artifact:
- script: signtool verify /v /pa <Path to the signed exe or dll> displayName: "Verify Artifact"
The only input for this step is the path to the signed exe/DLL that needs to be verified.
Verify signature with Mage
An example step of an Azure DevOps pipeline that verifies a signed app:
- script: mage -Verify <Path to signed .application file> displayName: 'Verify Click Once App'
The only input required here is the path to the signed .application file.
Verify signature with NuGet
An example step of an Azure DevOps pipeline that verifies a package using NuGet:
- task: NuGetCommand@2 displayName: 'NuGet Verify' inputs: command: 'custom' arguments: 'verify -All <Path to Signed Package>'
The only input it takes is the path to the directory of the signed package.