Skip to main content

GitLab Software Trust Manager (STM) 統合 -KSP

前提条件

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

  • DigiCert​​®​​ KeyLocker credentials

  • DigiCert​​®​​ KeyLocker client tools

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.

注記

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.

    注記

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

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

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.

Set certificate file in environment variables

  1. Identify your client authentication certificate.

  2. Encode the file to base64. For encoding run command:

    base64 file_name
  3. In GitLab > CI/CD Settings > Variables add the new variables:

    Key = SM_CLIENT_CERT_FILE_B64
    Value = encoded value from base64 file_name
  4. Setup certificate file for signing:

    stages:
      - set-SM-certificate
    
    variables:
      SM_API_KEY: $SM_API_KEY
      SM_CLIENT_CERT_PASSWORD: $SM_CLIENT_CERT_PASSWORD
      SM_HOST: $SM_HOST
    
    set_SM_certificate:
      stage: set-SM-certificate
      tags:  
      - shared-windows
      - windows
      - windows-1809
    
      script:
        - |
          cd C:\
          New-Item C:\CERT_FILE.p12.b64
          Set-Content -Path C:\CERT_FILE.p12.b64 -Value $SM_CLIENT_CERT_FILE_B64
          certutil -decode CERT_FILE.p12.b64 Certificate_pkcs12.p12
    
      variables:
        SM_CLIENT_CERT_FILE: 'C:\Certificate_pkcs12.p12'

Software Trust Managerのセットアップ

クライアントツールがDigiCert​​®​​ Software Trust Managerと接続するためには、これらの環境変数が必要です。

これらは GitLab RepositoryのGitLab 変数として統合することができます。

これらの環境変数に設定する値は、以下のようになります。

1. 環境変数

環境変数

説明

SM_CLIENT_CERT_PASSWORD

パスワードは、クライアント認証用証明書の設定により取得されたパスワードです。

SM_CLIENT_CERT_FILE_B64

クライアント認証用証明書の設定からダウンロードした証明書を base64 でエンコードしたテキスト。

SM_HOST

クライアント認証のある、DigiCert Oneポータルへのパス。

注記

DigiCert ONE 製品のセルフホスト型インスタンスに接続しない限り、ほとんどの場合、このパスはそのまま残ります。

SM_API_KEY

APIトークン設定中に生成されるAPIトークン。

SM_CODE_SIGNING_CERT_SHA1_HASH

証明書のフィンガープリント。


環境変数を設定するコマンド:

stages:
  - set-variables

variables:
  SM_API_KEY: $SM_API_KEY
  SM_CLIENT_CERT_PASSWORD: $SM_CLIENT_CERT_PASSWORD
  SM_HOST: $SM_HOST
  SIGNTOOL: 'C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe'
  MAGE: 'C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\mage.exe'
  SSM: 'C:\Program Files\DigiCert\DigiCert ONE Signing Manager Tools'

注記

"C:\Program Files (x86)\Windows Kits\10\App Certification Kit" は、signtool.exeのパスであり、"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools" は、mage.exeのパスです。

クライアントツールの設定

クライアントコントロールのセットアップ

GitLab CI/CD からクライアントコントロールを起動するために、以下の curl コマンドで smtools-Windows-x64.msI をダウンロードしてインストールします。

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
      curl.exe -X GET  https://ONE.digicert.com/signingmanager/api-ui/v1/releases/Keylockertools-windows-x64.msi/download -H "x-api-key: $SM_API_KEY" -o Keylockertools-windows-x64.msi
      msiexec.exe /i Keylockertools-windows-x64.msi /quiet /qn | Wait-Process

注記

"curl "コマンドは smtools-Windows-x64.msi のインストーラーを、"msiexec"は smtools-Windows-x64.msi のサイレントインストールに使用されるものである。

KSPを確認する

KSPが登録されていることを確認するには、以下を実行します。

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
      & $SSM\smksp_registrar.exe list

Integration with GitLab CI/CD

Find Signtool and Mage

Command to find signtool:

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
      Get-ChildItem -Path 'C:\Program Files (x86)\Windows Kits\10\App Certification Kit' -Filter signtool.exe -Recurse

Command to find Mage:

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
      Get-ChildItem -Path 'C:\Program Files (x86)\Microsoft SDKs\Windows'     -Filter mage.exe -Recurse

Sign

You can sign with Mage, NuGet, or SignTool.

Sign with SignTool

To sign with SignTool:

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
          & $SIGNTOOL sign /sha1 <certificate thumbprint> /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 <file to be signed>

The input parameters are the thumbprint of the certificate to be used for signing and the path to the .exe or .dll to be signed.

Sign with Mage

To sign with Mage:

Signing using nuget.exe:
stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
           nuget sign <package folder> -Timestamper http://timestamp.digicert.com -outputdirectory <output folder> -Certificate Fingerprint <SHA1 Thumbprint> -HashAlgorithm SHA256 -Verbosity detailed -Overwrite

The inputs to this task are the path to the package and the thumbprint of the certificate. The certificate thumbprint on can be identified on the certificate details page in DigiCert ONE portal.

Verify signature

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

Verify signature with Mage

To verify a signature with Mage:

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
           & $MAGE -Verify <Path to signed .application file>

The only input required here is the path to the signed .application file.

Verify signature with NuGet

To verify a signature with NuGet:

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
           nuget verify -All <output folder>\*

The only input required here is the path to the signed folder.

Verify signature with SignTool

To verify a signature with SignTool:

stages:
  - set-SM-certificate

set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - shared-windows
  - windows
  - windows-1809

  script:
    - |
           & $SIGNTOOL verify /v /pa <Path to the signed .exe or .dll>

The only input for this step is the path to the signed .exe or .dll that needs to be verified.

GitLab CI/CD の例

GitLab CI/CD を使ったKSP署名

stages:
  - set-variables
  - ksp-signing

variables:
  SM_API_KEY: $SM_API_KEY
  SM_CLIENT_CERT_PASSWORD: $SM_CLIENT_CERT_PASSWORD
  SM_HOST: $SM_HOST
  SIGNTOOL: 'C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe'
  MAGE: 'C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\mage.exe'
  SSM: 'C:\Program Files\DigiCert\DigiCert ONE Signing Manager Tools'

ksp_signing_job:
  stage: ksp-signing
  tags:  
  - shared-windows
  - windows
  - windows-1809

  variables:
    SM_CLIENT_CERT_FILE: 'C:\Certificate_pkcs12.p12'


  script:
    - |
      cd C:\
      New-Item C:\CERT_FILE.p12.b64
      Set-Content -Path C:\CERT_FILE.p12.b64 -Value $SM_CLIENT_CERT_FILE_B64
      certutil -decode CERT_FILE.p12.b64 Certificate_pkcs12.p12
      
      curl.exe -X GET  https://one.digicert.com/signingmanager/api-ui/v1/releases/Keylockertools-windows-x64.msi/download -H "x-api-key:019d9d49dd7271dd236e84fb83_c879133c1c3f524f2ef68327674135080d34018a3d6128b84e5c982c5769b088" -o Keylockertools-windows-x64.msi
      msiexec.exe /i Keylockertools-windows-x64.msi /quiet /qn | Wait-Process

      & $SSM\smksp_cert_sync.exe

      Copy-Item -Path GitLab-Runner\builds\mypersonal23\signing\UNSIGNED.EXE -Destination C:\
      Copy-Item -Path GitLab-Runner\builds\mypersonal23\signing\UNSIGNED1.manifest -Destination C:\
      Copy-Item -Path GitLab-Runner\builds\mypersonal23\signing\UNSIGNED.nupkg -Destination C:\
      dir 'C:\'

      & $SIGNTOOL sign /sha1 $SM_CODE_SIGNING_CERT_SHA1_HASH /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 C:\UNSIGNED.EXE
      & $SIGNTOOL verify /v /pa C:\UNSIGNED.EXE

      & $MAGE -sign C:\UNSIGNED1.manifest -CertHash $SM_CODE_SIGNING_CERT_SHA1_HASH -a sha256RSA
      & $MAGE -Verify C:\UNSIGNED1.manifest
      
      nuget sign C:\UNSIGNED.nupkg -Timestamper http://timestamp.digicert.com -outputdirectory C:\Signed -CertificateFingerprint $SM_CODE_SIGNING_CERT_SHA1_HASH -HashAlgorithm SHA256 -Verbosity detailed -Overwrite
      nuget verify -All C:\Signed\*
      dir C:\