Skip to main content

PKCS11との Gradle統合

前提条件

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

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

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

  • 特定の OS 用の DigiCert​​®​​ Software Trust Manager クライアント(クライアントツール)

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

注記

クライアントツールは、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.

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.

Secure your credentials

Your DigiCert ONE host environment, API key, client authentication certificate and password makes up your environment variables and are required to access Software Trust Manager client tools. Use one of the methods provided below to securely store your credentials based on your operating system.

Gradle との統合

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

証明書付きの RSA テスト鍵ペアを生成する Gradle セットアップの例:

task createKeypair(type: Exec, description: 'create test keypair using DigiCert Signing Manager pkcs11', group: 'Build') {
  def keyType = "TEST"
  def certAlias = "<CertAlias>"
  def operation = "generate"
  def keyPair = "keypair"
  def keyAlg = "<keyAlg>"
  def generateCert = "true"
  def certProfileId="<CertProfileId>"
  def alias = "<KeyPairAlias>"
  commandLine "C:/smtools/smctl.exe", keyPair, operation, keyAlg, "--cert-alias", certAlias, "--cert-profile-id", certProfileId, "--generate-cert", generateCert, "--key-type", keyType
}

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

使用する証明書プロファイルIDは、DigiCert Oneポータルの Secure Signing Manager -> 証明書管理 -> 証明書プロファイルから取得することができます。証明書を生成するプロファイル(プロファイルカテゴリは Test でなければなりません)を選択すると、プロファイルIDが表示されます。

証明書付きの鍵ペアを作成する

証明書付きの RSA プロダクション鍵ペアを生成する Gradle セットアップの例:

task createKeypair(type: Exec, description: 'create production keypair using DigiCert Signing Manager pkcs11', group: 'Build') {
  def keyType = "PRODUCTION"
  def certAlias = "<certAlias>"
  def operation = "generate"
  def keyPair = "keypair"
  def keyAlg = "<keyAlg>"
  def generateCert = "true"
  def certProfileId="<certProfileId>"
  def alias = "<leyPairAlias>"
  commandLine "C:/smtools/smctl.exe", keyPair, operation, keyAlg, "--cert-alias", certAlias, "--cert-profile-id", certProfileId, "--generate-cert", generateCert, "--key-type", keyType
}

パラメータは前の場合と同じですが、プロファイルカテゴリが [プロダクション] である証明書プロファイルを選択していなければならないことに注意してください。

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

既存の鍵ペア付き証明書を生成する Gradle セットアップの例:

task createCertForKeypair(type: Exec, description: 'create certificate for existing keypair using DigiCert Signing Manager pkcs11', group: 'Build') {
  def keyType = "PRODUCTION"
  def certAlias = "<certAlias>"
  def operation = "generate-cert"
  def keyPair = "keypair"
  def keyPairID = "<keyPairId>"
  def certProfileId="<certProfileId>"
  def setAsDefault = "true"
  commandLine "C:/smtools/smctl.exe", keyPair, operation, keyPairID, "--cert-alias", certAlias, "--cert-profile-id", certProfileId, "--set-as-default-cert", setAsDefault, "--key-type", keyType
}

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

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

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

また、前述の使用ケースと同様に、使用する証明書プロファイルIDは正しいプロファイルカテゴリに属している必要があります。

Sign

To integrate DigiCert​​®​​ Software Trust Manager PKCS11 with Gradle implementation, add the code snippet to the build.gradle file:

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java'
}

task sign(type: Exec, dependsOn: 'jar', description: 'jar signing using DigiCert Signing Manager pkcs11', group: 'Build') {
  def storePassword = "NONE"
  def keyStore = "NONE"
  def storeType = "PKCS11"
  def providerClass = "sun.security.pkcs11.SunPKCS11"
  def providerArg = "<Path to smpkcs11.config>"
  def alias = "<keypair alias>"
  def signedjarfile = "<Path of signed file>"
  def unsignedjarfile=""<Path of unsigned file>""
  commandLine "${System.env.JAVA_HOME}/bin/jarsigner.exe", "-keystore", keyStore, "-storepass", storePassword, "-storetype", storeType,  "-providerClass", providerClass, "-providerArg", providerArg, "-signedjar", signedjarfile, "-unsignedjarfile", unsignedjarfile, alias
}

上記の例の入力パラメータは、鍵ペアのエイリアスのパス、設定ファイル、署名済みJarを出力する必要があるパス、署名する必要がある jarのパス、および署名に使用する証明書名です。

Verify signature

An example of a Gradle setup that verifies a signed jar:

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java'
}

task verify(type: Exec, dependsOn: 'jar', description: 'jar verification using DigiCert Signing Manager pkcs11', group: 'Build') {
  def signedjarfile = ""<Path of signed file>""
  commandLine "${System.env.JAVA_HOME}/bin/jarsigner.exe", "-verify", signedjarfile
}

この段階での入力は、検証が必要な署名付き jarのパスのみです。