PKCS11によるAzureパイプラインの統合
前提条件
Azure DevOps のセットアップ
Azure DevOps上でJavaをサポートする OS を持つ任意のカスタムエージェント(セルフホスティング)。
エージェントにインストールされた JDK
DigiCert® Software Trust Manager Accessの設定(下記参照)
DigiCert® Software Trust Manager PKCS11ライブラリ (クライアントツール)
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.
Create PKCS11 configuration file
To create a configuration file with the path to this shared library:
Open an integrated development environment (IDE) or plain text editor.
Copy and paste the following text into the editor:
Save the file as pkcs11properties.cfg.
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
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:
Sign in to DigiCert ONE.
Select the profile icon (top-right).
Select Admin Profile.
Scroll down to API Tokens.
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:
Sign in to DigiCert ONE.
Select the profile icon (top-right).
Select Admin Profile.
Scroll down to Authentication certificates.
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>
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のパスのみです。
サンプルパイプライン
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: 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'