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
Sign in to DigiCert ONE.
Navigate to DigiCert® KeyLocker > Resources > Client tool repository.
Select your operating system.
Click the download icon next to DigiCert® KeyLocker clients.
Register the KSP
To register the KSP, open a command prompt and run:
smctl windows ksp 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:
smctl windows certsync
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
KeyLocker enforces multi-factor authentication for security purposes. To access keypairs, certificates, and sign code, you need to set up two types of credentials: An API key and an authentication certificate.
Create an API key
The API key is an authentication method used to verify you as a user and your permissions assigned in DigiCert ONE. The API key provides the first factor authentication.
In DigiCert ONE, select the profile (
) icon, and then select Admin Profile.Under API keys, select Create API key.
For Name, enter a descriptive name for the key.
For End date (optional), enter the date when the key should expire.
Select Create. The API key appears this one time and can't be accessed again. Securely store the API key for future use.
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.
In DigiCert ONE, select the profile (
) icon, and then select Admin Profile.Under Client authentication certificates, select Create client authentication certificate.
For Nickname, enter a descriptive name for the key.
For End date, enter the date when the certificate should expire.
Select the desired Encryption and Signature hash algorithm.
Select Generate certificate. The password appears this one time and can't be accessed again. Download the certificate and securely store the password for future use.
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
Identify your client authentication certificate.
Encode the file to base64. For encoding run command:
base64 file_name
In GitLab > CI/CD Settings > Variables add the new variables:
Key = SM_CLIENT_CERT_FILE_B64 Value = encoded value from base64 file_name
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: - saas-windows-medium-amd64 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 変数として統合することができます。
これらの環境変数に設定する値は、以下のようになります。
環境変数  | 説明  | 
|---|---|
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:  
  - saas-windows-medium-amd64
  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:  
  - saas-windows-medium-amd64
  script:
    - |
      & $SSM\smctl windows ksp listIntegration with GitLab CI/CD
Find Signtool and Mage
Command to find signtool:
stages:
  - set-SM-certificate
set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - saas-windows-medium-amd64
  script:
    - |
      Get-ChildItem -Path 'C:\Program Files (x86)\Windows Kits\10\App Certification Kit' -Filter signtool.exe -RecurseCommand to find Mage:
stages:
  - set-SM-certificate
set_SM_certificate:
  stage: set-SM-certificate
  tags:  
  - saas-windows-medium-amd64
  script:
    - |
      Get-ChildItem -Path 'C:\Program Files (x86)\Microsoft SDKs\Windows'     -Filter mage.exe -RecurseSign
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:  
  - saas-windows-medium-amd64
  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:  
  - saas-windows-medium-amd64
  script:
    - |
           nuget sign <package folder> -Timestamper http://timestamp.digicert.com -outputdirectory <output folder> -Certificate Fingerprint <SHA1 Thumbprint> -HashAlgorithm SHA256 -Verbosity detailed -OverwriteThe 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:  
  - saas-windows-medium-amd64
  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:  
  - saas-windows-medium-amd64
  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:  
  - saas-windows-medium-amd64
  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:  
  - saas-windows-medium-amd64
  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\smctl windows certsync
      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:\