Skip to main content

PKCS11との Maven 統合

前提条件

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

  • エージェントにインストールされた 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 as a package.

Download client tools

  1. In the Software Trust menu, go to Resources > Client tool repository.

  2. Select your operating system, and then select the corresponding download (download_icon.png) icon next to the desired client.

Create PKCS11 configuration file

To create a configuration file with the path to the 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 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.

  1. In DigiCert ONE, select the profile (profile_icon.png) icon, and then select Admin Profile.

  2. Under API keys, select Create API key.

  3. For Name, enter a descriptive name for the key.

  4. For End date (optional), enter the date when the key should expire.

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

  1. In DigiCert ONE, select the profile (profile_icon.png) icon, and then select Admin Profile.

  2. Under Client authentication certificates, select Create client authentication certificate.

  3. For Nickname, enter a descriptive name for the key.

  4. For End date, enter the date when the certificate should expire.

  5. Select the desired Encryption and Signature hash algorithm.

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

PKCS11_CONFIG

Provide the path to the PKCS#11 configuration file.

SM_TLS_SKIP_VERIFY

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

Create keypair and certificate

As an example, to generate an RSA test keypair with certificate, create a .bat file which contains the command to generate the test keypair. The contents of smtcl_gen_testcert.bat are:

keypair generate rsa <keypair alias> --cert-alias=<certificate alias> --cert-profile-id=<certificate profile ID> --generate-cert=true --key-type=TEST

Then, add in the pom.xml:

<plugins>
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
              <phase>generate-sources</phase>
                <configuration>
                    <target>
                        <exec dir="C:\smtools" executable="smctl_gen_testcert.bat"  failonerror="true">
                        </exec>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
       </execution>
   </executions>      
</plugin>
</plugins>

The keypair name and certificate name are must be unique inputs, meaning that they cannot exist on the portal already.

The certificate profile ID to be used can be retrieved from the DigiCert One portal at DigiCert​​®​​ Software Trust Manager > Certificates > Certificate profiles. Select a profile (Profile Category should be Test) that you want to generate the certificate with, and you should see the profile ID.

Create production keypair with certificate

As an example, to generate an RSA production keypair with certificate, create a .bat file which contains the command to generate the production keypair. The contents of smtcl_gen_prodcert.bat are:

keypair generate rsa <keypair alias> --cert-alias=<certificate alias> --cert-profile-id=<certificate profile ID> --generate-cert=true --key-type=PRODUCTION

Then, add in the pom.xml:

<plugins>
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
              <phase>generate-sources</phase>
                <configuration>
                    <target>
                        <exec dir="C:\smtools" executable="smctl_gen_prodcert.bat"  failonerror="true">
                        </exec>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
       </execution>
   </executions>      
</plugin>
</plugins>
  

The parameters are the same as the previous case, but be sure to select a certificate profile that has the profile category as Production.

Create certificate from an existing keypair

As an example, to generate a certificate for an existing keypair, create a .bat file which contains the command to generate a certificate for an existing keypair. Here, the contents of smctl_gen_cert_for_keypair.bat are:

smctl keypair generate-cert <keypair ID> --cert-alias=<certificate alias> --cert-profile-id=<certificate profile ID> --set-as-default-cert=true 

Then, add in the pom.xml:

<plugins>
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
              <phase>generate-sources</phase>
                <configuration>
                    <target>
                        <exec dir="C:\smtools" executable="smctl_gen_cert_for_keypair.bat"  failonerror="true">
                        </exec>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
       </execution>
   </executions>      
</plugin>
</plugins>

For this step, the inputs required are a keypair ID, certificate name (which should be unique), and certificate profile ID. The keypair ID can be retrieved in two ways:

  • Run a smctl keypair ls command on the command line with all environment variables set up.

  • Refer to DigiCert​​®​​ Software Trust Manager on the DigiCert One portal and go to DigiCert​​®​​ Software Trust Manager > Keypairs and select a keypair.

Also, as in the previous use cases, the certificate profile ID used should belong to the correct profile category.

Maven との統合

Apache Mavenは,jarsignerと統合するためのプラグインを提供しています。STM PKCS11をMavenの実装に統合するには、POM.xml ファイル内のBuildプロパティを更新して、このプラグインを使用するようにする必要があります。

プラグイン

groupId = org.apache.maven.plugins
artifactId = maven-jarsigner-plugin
version = 3.0.0

実行方法

id = sign
goal = sign

設定

keystore = NONE
alias = <certificate alias>
storepass = none
keypass = none
providerClass = sun.security.pkcs11.SunPKCS11
storetype = PKCS11
providerArg = <path to pkcs11 config file>

例えば:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<artifact.classifier />
</properties>
<groupId>com.digicert</groupId>
<artifactId>signing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>pkcs11</name>
<description>pkcs11 signing</description>
<url>https://github.com/company/project</url>
<prerequisites>
<maven>3.3.9</maven>
</prerequisites>
<dependencies/>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>sign</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>NONE</keystore>
<alias>KPRose</alias>
<storepass>none</storepass>
<providerClass>sun.security.pkcs11.SunPKCS11</providerClass>
<storetype>PKCS11</storetype>
<providerArg>C:\smtools\pkcs11properties.cfg</providerArg>
<tsa>http://timestamp.digicert.com</tsa>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<extensions>true</extensions>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>-Xlint</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.version}</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>ProjectName-@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

Verify signature

To verify a signature:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<certs>true</certs>
</configuration>
</plugin>