Skip to main content

Jenkins とKSP の統合

STMのクライアントツールを Jenkins 用にセットアップします。Jenkins と統合することで、CI/CD パイプラインへの自動化が可能になります。

前提条件

  • Jenkins ビルドシステム

  • Jenkins 上で Javaを サポートする OS を持つ任意のエージェント

  • エージェントにインストールされた JDK

  • DigiCert​​®​​ Software Trust Managerのセットアップ

  • お使いのOSに対応する DigiCert​​®​​ Software Trust Manager クライアント

  • 必要な署名ツール(signtool.exe や mage.exe など)が存在している。

注記

クライアントツールは、DigiCert Oneポータルの DigiCert​​®​​ Software Trust Manager -> リソース -> クライアントツールでダウンロードすることができます。

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 permissionsUsers 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 permissionsUsers 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のセットアップ

システム変数として設定することで、環境変数が永続的に残るようにしてください。

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

Jenkins との統合

テスト用鍵ペアと証明書を作成する

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

鍵ペア名と証明書名は、一意の入力でなければなりません。つまりポータル上に既に存在することはできません。

証明書プロファイルIDは DigiCert Oneポータルの DigiCert​​®​​ Software Trust Manager > 証明書 > 証明書管理 > 証明書プロファイルで取得できます。証明書の生成に使用するプロファイルを選択します(プロファイルカテゴリはテストでなければなりません)。

既存の鍵ペアから証明書を作成する

既存の鍵ペア用の証明書を生成する Jenkins のステージの例:

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

このステップで必要な入力は、鍵ペアID、証明書名(一意でなければなりません)、および証明書プロファイルIDです。鍵ペアIDを取得するには、次の2つの方法があります。

  • すべての環境変数が設定された状態で、コマンドラインから「smctl 鍵ペアはコマンド」を実行。

  • DigiCert Oneポータルの DigiCert​​®​​ Software Trust Managerを参照し、DigiCert​​®​​ Software Trust Manager -> 鍵の管理と進み、鍵ペアをクリックします。

前述の使用ケースと同様に、使用する証明書プロファイルIDは正しいプロファイルカテゴリに属していなければなりません。

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