Skip to main content

GitHubの統合 –KSP

前提条件

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

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

  • DigiCert​​®​​ Software Trust ManagerKSP (クライアントツール)

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 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.

Software Trust Managerのセットアップ

クライアントツールを使用し、DigiCert​​®​​ Software Trust Managerに接続して操作を行うには、DigiCert ONeでのDigiCert​​®​​ Software Trust Managerへのアクセス権がなければなりません。DigiCert​​®​​ Software Trust Managerにアクセスできない場合は、DigiCert ONEの管理者に連絡してアクセスを要求してください。

環境変数内の証明書ファイルを設定する

  1. 証明書をDigiCert ONE > アカウントマネージャ > アクセス > <account_name> > 証明証明書の作成をダウンロードします。

  2. ファイルを base64 にエンコードします。エンコードのコマンドを実行します。

    base64 file_name
  3. GitHub SecretSに、新しいリポジトリシークレットを追加します。

    Name = SM_CLIENT_CERT_FILE_B64
    Value = encoded value from base64 file_name
  4. 署名用の証明書ファイルをセットアップします。

    - name: Setup Certificate
      run: |
        echo "${{ secrets.SM_CLIENT_CERT_FILE_B64 }}" | base64 --decode > /d/Certificate_pkcs12.p12
      shell: bash

GitHub 操作用の環境変数の設定

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

環境変数を GitHub シークレットとして統合するには、次を行います。

  1. GitHub リポジトリにアクセスする

  2. の設定を選択する

  3. シークレット > 操作を選択する

  4. 新しいリポジトリシークレットを選択する

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

Variable

Description

SM_API_KEY

Provide your API token.

SM_CLIENT_CERT_FILE_B64

The base64 encoded text of certificate downloaded from client authentication certificate setup.

SM_CLIENT_CERT_PASSWORD

Provide your client certificate password.

SM_HOST

Provide your host environment.

SM_CODE_SIGNING_CERT_SHA1_HASH

The certificate fingerprint.

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

- name: Set variables
  id: variables
  run: |
    echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
    echo "SM_HOST=${{ secrets.SM_HOST }}" >> "$GITHUB_ENV"
    echo "SM_API_KEY=${{ secrets.SM_API_KEY }}" >> "$GITHUB_ENV"
    echo "SM_CLIENT_CERT_FILE=D:\\Certificate_pkcs12.p12" >> "$GITHUB_ENV"
    echo "SM_CLIENT_CERT_PASSWORD=${{ secrets.SM_CLIENT_CERT_PASSWORD }}" >> "$GITHUB_ENV"
    echo "C:\Program Files (x86)\Windows Kits\10\App Certification Kit" >> $GITHUB_PATH
    echo "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools" >> $GITHUB_PATH
    echo "C:\Program Files\DigiCert\DigiCert Keylocker Tools" >> $GITHUB_PATH
  shell: bash

ヒント

The following tool paths are provided above:

  • DigiCert​​®​​ KeyLocker client tools

    C:\Program Files\DigiCert\DigiCert Keylocker Tools

  • Signtool.exe

    C:\Program Files (x86)\Windows Kits\10\App Certification Kit

  • Mage.exe

    C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools

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

Connect the KSP to GitHub actions and verify that it works.

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

GitHub の操作からクライアントコントロールを呼び出すには、以下を実行します。

以下の curl コマンドで smtools-Windows-x64.msI をダウンロードしてインストールします。

- name: Setup SSM KSP on windows latest
  run: |
    curl -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 /i Keylockertools-windows-x64.msi /quiet /qn
  shell: cmd

注記

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

KSPを確認する

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

- name: Register KSP
  run: |
    smksp_registrar.exe list
  shell: cmd

GitHub の操作との連携

サインツールとMageを見つける

サインツールを見つけるコマンド:

- name: Find Signtool
  run: |
    dir "C:\Program Files (x86)\Microsoft SDKs\Windows\ " /s /b | findstr /i signtool.exe
  shell: cmd

Mageを見つけるコマンド:

- name: Find Signtool
  run: |
      dir "C:\Program Files (x86)\Microsoft SDKs\Windows\ " /s /b | findstr /i mage.exe
  shell: cmd

Signing

signtool.exeを使用して署名する

Sign with Mage

To sign with Mage:

- name: Signing using mage
  run: |
    mage.exe -sign <file_name> -CertHash <hash_or_cert_fingerprint> -a sha256RSA
 shell: cmd

Sign with NuGet

To sign with NuGet:

- name: Signing using nuget
  run: |
    nuget sign <package folder> -Timestamper http://timestamp.digicert.com -outputdirectory <output folder> -Certificate Fingerprint <SHA1 Thumbprint> -HashAlgorithm SHA256 -Verbosity detailed -Overwrite
  shell: cmd

Sign with SignTool

To sign with SignTool:

- name: Signing using signtool
  run: |
    signtool.exe sign /sha1 <certificate thumbprint> /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 <file to be signed>
 shell: cmd

Verify signature

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

Verify signature with Mage

To verify a signature with Mage:

- name: Mage verify
  run: |
    mage -Verify <Path to signed .application file>
  shell: cmd- name: Mage verify
run: |
mage -Verify <path to signed .application file>
shell: cmd

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

Verify signature with NuGet

To verify a signature with NuGet:

- name: Nuget verify
  run: |
    nuget verify -All <output folder>\*
  shell: cmd- name: Nuget verify
run: |
nuget verify -All <output folder>\*
shell: cmd

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

Verify signature with SignTool

To verify a signature with SignTool:

- name: Signtool verify
  run: |
    signtool verify /v /pa <Path to the signed exe/DLL>
  shell: cmd- name: Signtool verify
run: |
signtool verify /v /pa <path to the signed .exe or .dll>
shell: cmd

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

GitHub操作の例

GitHub操作を使ったKSP署名

name: 'build and release electron installer'
on:
  push:
    tags:
      - 'v*'
      
jobs:
  release:
    runs-on: ${{ matrix.os }}
    
    strategy:
      matrix:
        os: [windows-latest]
        
    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Install Node.js, NPM and Yarn
        uses: actions/setup-node@v2
        with: 
          node-version: 14
        
      - name: Build/release Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with: 
          github_token: ${{ secrets.github_token }}
          release: ${{ startsWith(github.ref, 'refs/tags/v') }}
          build_script_name: dist

      - name: NuGet Install
        uses: NuGet/setup-nuget@v1.0.5
        with:
          nuget-version: latest

      - name: Setup Certificate
        run: |
          echo "${{ secrets.SM_CLIENT_CERT_FILE_B64 }}" | base64 --decode > /d/Certificate_pkcs12.p12
          cat /d/Certificate_pkcs12.p12
        shell: bash

          
      - name: Set variables
        id: variables
        run: |
          echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
          echo "SM_HOST=${{ secrets.SM_HOST }}" >> "$GITHUB_ENV"
          echo "SM_API_KEY=${{ secrets.SM_API_KEY }}" >> "$GITHUB_ENV"
          echo "SM_CLIENT_CERT_FILE=D:\\Certificate_pkcs12.p12" >> "$GITHUB_ENV"
          echo "SM_CLIENT_CERT_PASSWORD=${{ secrets.SM_CLIENT_CERT_PASSWORD }}" >> "$GITHUB_ENV"
          echo "C:\Program Files (x86)\Windows Kits\10\App Certification Kit" >> $GITHUB_PATH
          echo "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools" >> $GITHUB_PATH
          echo "C:\Program Files\DigiCert\ DigiCert Keylocker Tools" >> $GITHUB_PATH
        shell: bash

      - name: Setup SSM KSP on windows latest
        run: |
          curl -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 /i Keylockertools-windows-x64.msi /quiet /qn
          smksp_registrar.exe list
          smctl.exe keypair ls
          C:\Windows\System32\certutil.exe -csp "DigiCert Signing Manager KSP" -key -user
          smksp_cert_sync.exe
        shell: cmd

      - name: Signing using Signtool
        run: |
          signtool.exe sign /sha1 ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }} /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 "D:\a\github-action-electron\github-action-electron\dist\my-electron-app Setup ${{ steps.variables.outputs.version }}.exe"
          signtool.exe verify /v /pa "D:\a\github-action-electron\github-action-electron\dist\my-electron-app Setup ${{ steps.variables.outputs.version }}.exe"

      - name: Signing using Nuget
        run: |
          copy D:\a\github-action-electron\github-action-electron\UNSIGNED.nupkg D:\a\github-action-electron\github-action-electron\dist\UNSIGNED.nupkg
          nuget sign "D:\a\github-action-electron\github-action-electron\dist\UNSIGNED.nupkg" -Timestamper http://timestamp.digicert.com -outputdirectory "D:\a\github-action-electron\github-action-electron\dist\Signed" -CertificateFingerprint ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }} -HashAlgorithm SHA256 -Verbosity detailed -Overwrite
          nuget verify -All "D:\a\github-action-electron\github-action-electron\dist\Signed\*"

      - name: Signing using Mage
        run: |
          copy D:\a\github-action-electron\github-action-electron\UNSIGNED2.manifest D:\a\github-action-electron\github-action-electron\dist\UNSIGNED2.manifest
          mage.exe -sign "D:\a\github-action-electron\github-action-electron\dist\UNSIGNED2.manifest" -CertHash ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }} -a sha256RSA
          mage -Verify "D:\a\github-action-electron\github-action-electron\dist\UNSIGNED2.manifest"

      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        with:
          name: ${{ matrix.os }}
          path: |
            dist

コードの実行・ビルド方法

  1. プロジェクトの Package.json ファイルにあるバージョンを更新します(例:1.2.3)

  2. その変更をコミットします (git commit -am v1.2.3)

  3. コミットにタグを付けます (git tag v1.2.3)。タグの名前の形式が v*.*.* であることを確認してください。

    注記

    ワークフローでは、このタグを使ってリリースを作成するタイミングを判断します。

  4. 変更内容を GitHub にプッシュします (git push &amp;&amp; git push --tags)。