Skip to main content

PKCS11によるAzureパイプラインの統合

前提条件

  • Azure DevOps のセットアップ

  • Azure DevOps上でJavaをサポートする OS を持つ任意のカスタムエージェント(セルフホスティング)。

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

  • DigiCert​​®​​ Software Trust Manager Accessの設定(下記参照)

  • DigiCert​​®​​ Software Trust Manager PKCS11ライブラリ (クライアントツール)

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.

Create PKCS11 configuration file

To create a configuration file with the path to this shared library:

  1. Open an integrated development environment (IDE) or plain text editor.

  2. Copy and paste the following text into the editor:

  3. Save the file as pkcs11properties.cfg.

  4. Move the pkcs11properties.cfg file to the same location as the PKCS11 library.

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:

  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.

PKCS11_CONFIG

Provide the path to the PKCS11 configuration file.

SM_TLS_SKIP_VERIFY

Enter true to disable or false to enable TLS verification on client side.

Azure DevOpsパイプラインとの統合

パイプライン用の環境変数の設定

クライアントツールがDigiCert​​®​​ Software Trust Managerと接続してサービスを提供するためには、これらの環境変数が必要です。これらはパイプラインの変数として統合され、Azureは自動的にエージェントの環境変数として注入することができますし、OS 環境レベルで設定することもできます。

variables:
- name: SM_CLIENT_CERT_PASSWORD
 value: <client authentication certificate password>
- name: SM_CLIENT_CERT_FILE
  value: <Path to client authentication certificate file>
- name: SM_HOST
  value: <host url>
- name: SM_API_KEY
  value: <API Token>
- name: PKCS11_CONFIG
  value: <Path to pkcs11properties.cfg>

Certificates and keypairs

The following scripts can be used to generate keypairs and certificates.

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 and certificate alias are must be unique inputs, meaning that they cannot already exist in Software Trust Manager.

To retrieve the certificate profile ID:

  1. Sign in to DigiCert ONE.

  2. Navigate to: DigiCert​​®​​ Software Trust Manager > Certificates > Certificate profiles.

  3. Click on the certificate profile alias that you want to generate the certificate with.

    注記

    The profile category should be Test.

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

注記

Select a certificate profile that has the profile category as Production.

Create certificate from existing keypair

既存の鍵ペア用の証明書を生成するAzure DevOpsパイプラインのステップの例:

- task: CmdLine@2
  displayName: 'Generate Certificate for Existing Keypair'
  inputs:
    script: 'smctl keypair generate-cert <Keypair ID> --cert-alias=<Certificate Name> --cert-profile-id=<Certificate Profile ID>'

For this step, the inputs required are a Keypair ID, certificate name (which should be unique) and certificate profile ID.

You can retrieve the keypair ID in two ways:

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

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

注記

The certificate profile ID used should belong to the correct profile category.

Sign

An example for an Azure DevOps pipeline step for signing a jar is:

- task: CmdLine@2
  displayName: 'Sign Jar'
  inputs:
    script: 'jarsigner -keystore NONE -storepass NONE -storetype PKCS11 -sigalg SHA256withRSA -providerClass sun.security.pkcs11.SunPKCS11 -providerArg $PKCS11_CONFIG -signedJar <Output path for the signed jar> <Input path for jar to be signed> <certificate alias> -tsa http://timestamp.digicert.com'

The input parameters for this example 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.

注記

PKCS11の設定ファイルは、パイプラインの環境に定義されていました。定義されていない場合は、設定ファイルへのパスで代用可能です。

Verification

An example of an Azure DevOps step that verifies a signed jar:

- task: CmdLine@2
  displayName: 'Verify Signed Jar'
  inputs:
    script: 'jarsigner -verify <path to the signed jar>'

このステップでの唯一の入力は、検証する必要がある署名付きjarへのパスです。この段階での入力は、検証が必要な署名付き jarのパスのみです。

Sample pipeline

trigger:
- main

pool:
  name: 'default'
  demands: agent.os -equals Linux

variables:
  - name: SM_CLIENT_CERT_PASSWORD
    value: gxmiK9Oe72Pn
  - name: SM_CLIENT_CERT_FILE
    value: "/home/john.doe/smtools/local_pkcs12.p12"
  - name: SM_HOST
    value: https://clientauth.one.digicert.com
  - name: SM_API_KEY
    value: 01ff018928e385329550b6e7a1_9b38fc5fbb4ef99ceeb7d61e6984107efa4283583cb7a64f5e292582cd3ed848
  - name: PKCS11_CONFIG
    value: "/home/john.doe/smtools/pkcs11properties.cfg"
  - name: KEYPAIR_NAME
    value: "azure-keypair-$(Build.BuildId)"

steps:

- task: CmdLine@2
  displayName: 'Generate Keypair'
  inputs:
    script: '/home/siddharth/smtools/smctl keypair generate rsa $KEYPAIR_NAME --cert-alias=$KEYPAIR_NAME --cert-profile-id=16b073d1-8de8-4ea2-9f5e-88ba6e79063a --generate-cert=true --key-type=PRODUCTION'

- task: Gradle@2
  displayName: 'Build'
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    javaHomeOption: 'path'
    jdkDirectory: '/usr/lib/jvm/java-11-openjdk-amd64'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'build'

- task: CmdLine@2
  displayName: 'Sign Jar'
  inputs:
    script: 'jarsigner -keystore NONE -storepass NONE -storetype PKCS11 -sigalg SHA256withRSA -providerClass sun.security.pkcs11.SunPKCS11 -providerArg $PKCS11_CONFIG -signedJar $(System.DefaultWorkingDirectory)/app/build/libs/signed.jar $(System.DefaultWorkingDirectory)/app/build/libs/app.jar $KEYPAIR_NAME -tsa http://timestamp.digicert.com'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Unsigned Jar'
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/app/build/libs/app.jar'
    ArtifactName: 'Unsigned Jar'
    publishLocation: 'Container'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Signed Jar'
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/app/build/libs/signed.jar'
    ArtifactName: 'Signed Jar'
    publishLocation: 'Container'

- task: CmdLine@2
  displayName: 'Verify Signed Jar'
  inputs:
    script: 'jarsigner -verify $(System.DefaultWorkingDirectory)/app/build/libs/signed.jar'