PKCS#11 Wrapper – JSign Signing Integration Guide

JSign is a versatile, platform-independent tool used for code signing of Windows executable files, installers, and scripts. Because it is written in Java, the same tool signs Windows artifacts from a Linux, macOS, or Windows machine.

JSign reads its signing key from a keystore, and by giving it a keystore type of PKCS11 together with Encryption Consulting’s PKCS#11 wrapper configuration, that keystore becomes your HSM. The private key never leaves the HSM and every signing operation is recorded centrally.

Section 1 covers the steps common to every platform. After that, follow only the track for your operating system — Sections 2 and 3 for Linux (Ubuntu), Sections 4 and 5 for macOS, or Sections 6 and 7 for Windows.

Prerequisites: Access to the CodeSign Secure portal, administrative rights on the client machine, and a file to sign such as an executable, installer, or script.

Common Setup

Every platform needs the same two things before JSign will work: an authentication certificate that identifies your machine to CodeSign Secure, and the two configuration files that ship inside the PKCS#11 Wrapper download.

Step 1: Generate a P12 Authentication Certificate

Generate a P12 Authentication certificate from the System Setup > User > Generate Authentication Certificate dropdown in the CodeSign Secure portal.

P12 cert generate output

Enter the certificate name, user name, and expiry date. A certificate is generated and downloaded, and its password is displayed.

P12 cert details output

NOTE: The password is displayed only once, so copy and store it safely. Both the certificate path and its password are entered into ec_pkcs11client.ini in your platform track.

Step 2: Understand the Two Configuration Files

The PKCS#11 Wrapper download contains two files that must be edited before use. The same fields apply on every platform.

  • pkcs11properties.cfg: Describes the PKCS#11 token to JSign. Update it with the correct library path for your platform. This is also the file passed to JSign as --keystore.
  • ec_pkcs11client.ini: Points the wrapper at your CodeSign Secure server and at the authentication certificate from Step 1. The fields to update are listed below.
FieldDescription
name The path location of the Log xml file you downloaded with the PKCS11 Wrapper tool (EC_PKCS11_CLIENT-LogConfig.xml).
url Verify the server url of your CodeSign Secure portal.
username The username of your CodeSign Secure account.
passcode The secret passcode which was used to set up the CodeSign Secure portal.
path The path location of your SSL Authentication certificate.
passwd The password of your SSL Authentication certificate.

NOTE: When using Luna HSM, the slot number must also be added to the pkcs11properties.cfg file. Each platform track below shows this variation.

Linux (Ubuntu): Install and Configure

To perform signing using JSign Tool and our PKCS11 Wrapper in a Linux (Ubuntu) machine, you would need to follow the below steps.

Step 1: Download the PKCS#11 Wrapper for Ubuntu

Go to EC CodeSign Secure v3.02’s Signing Tools section and download the PKCS11 Wrapper for Ubuntu.

Wrapper download linux output

Step 2: Edit the Configuration Files

Go to your Ubuntu client system and edit the configuration files (ec_pkcs11client.ini and pkcs11properties.cfg) downloaded in the PKCS11 Wrapper.

Config files edit linux output

NOTE: When using Luna HSM, add the slot number in the pkcs11properties.cfg file as shown below.

Luna slot number linux

Step 3: Set the EC_INI_FILE_PATH Environment Variable

Now we need to add the environment variable for the pkcs11 client library.

Run the below command to open the bashrc file:

nano ~/.bashrc
Bashrc open linux output

Now add the EC_INI_FILE_PATH variable with the path of the .ini at the end of the bashrc file, like:

export EC_INI_FILE_PATH=\
/home/administrator/PKCS11_Wrapper-Ubuntu/ec_pkcs11client.ini
Bashrc ini path added linux

Press Ctrl+X, then enter Y, and then press Enter to save.

Reload the environment variables:

source ~/.bashrc
Source bashrc linux output

Check whether the variable has been set correctly:

echo $EC_INI_FILE_PATH
Echo ini path linux output

NOTE: If you cannot see the file location from the echo command, open a new terminal and try again.

Step 4: Install the JSign Tool

Now, you will need to download the latest version of the JSign tool (DEB package) on your Ubuntu machine using this link.

JSign download page linux output
JSign download file linux output

Install the debian package using the below command:

sudo dpkg --install jsign_7.0_all.deb
JSign install linux output

To check whether JSign has been properly installed or not, run the following command:

jsign
JSign version check linux output

Step 5: Install and Activate Java 17

You will also need to install Java (Java 17 or lower) on your Ubuntu machine for JSign to work with our PKCS11 Wrapper.

Run the following command to install Java 17 on your Ubuntu machine:

sudo apt install openjdk-17-jdk
Java17 install linux output

To use Java 17, you will need to set it as the active version.

sudo update-alternatives --config java
Java17 alternatives linux output

Now to check whether Java has been installed properly or not, run:

java -version
Java version check linux output

Step 6: Install the Remaining Packages

You would also need to install some other pre-requisite packages to perform signing using JSign.

sudo apt-get install curl
sudo apt-get install liblog4cxx-dev
sudo apt-get install liblog4cxx12

NOTE: If the “sudo apt-get install liblog4cxx12” command gives an error, install the package directly for your architecture using the commands below.

For amd architecture:

wget http://archive.ubuntu.com/ubuntu/pool/universe/l/log4cxx/\
liblog4cxx12_0.12.1-4_amd64.deb
sudo dpkg -i liblog4cxx12_0.12.1-4_amd64.deb

For arm architecture:

wget http://ports.ubuntu.com/pool/universe/l/log4cxx/\
liblog4cxx12_0.12.1-4_arm64.deb
sudo dpkg -i liblog4cxx12_0.12.1-4_arm64.deb

We are now ready with our Ubuntu environment to perform the signing using JSign tool and PKCS11 Wrapper.

Linux (Ubuntu): Sign the File

The signing command must be run from the directory containing your configuration, so that the relative paths in the command resolve correctly.

Step 1: Change to the Working Directory

For signing, change the working directory of the terminal to that folder which contains your “ec_pkcs11client.ini” file.

Working directory linux output

Step 2: Run the Signing Command

Now, run the signing command from this directory.

<Path of JSign tool> --keystore <Path of pkcs11properties.cfg> \
  --storepass NONE \
  --storetype PKCS11 \
  --alias <Key alias of the signing certificate> \
  <Path of the file to be signed>

A sample command is provided below:

jsign --keystore pkcs11properties.cfg \
  --storepass NONE \
  --storetype PKCS11 \
  --alias gpg2 \
  build_project.ps1
JSign sign output linux

NOTE: On Ubuntu the DEB package installs a jsign launcher on the PATH, so the command begins with jsign rather than with java -jar.

Step 3: Option Reference

The following are the options and their meaning in the command:

OptionDescription
--keystore The path of the pkcs11properties.cfg file, which directs JSign to the PKCS#11 wrapper instead of to a keystore file.
--storepass The keystore password. This is NONE because access is controlled by the wrapper configuration.
--storetype The keystore type, which must be PKCS11.
--alias The key alias of the signing certificate in CodeSign Secure.
<file path> The file to be signed, given as the final argument with no option name.

Step 4: Confirm the Signing Request

NOTE: There is no verification command for the JSign tool.

Open the CodeSign Secure portal and navigate to Reports > Signing Request Report, where every signing request performed through the wrapper is recorded for audit purposes. Confirm that a signing request appears for the certificate you used.

macOS: Install and Configure

To perform signing using JSign Tool and our PKCS11 Wrapper in a MacOS machine, you would need to follow the below steps.

Step 1: Download the PKCS#11 Wrapper

Download our PKCS11 Wrapper Tool from the CodeSign Secure portal in the Signing Tools section in your MacOS.

Wrapper download mac output

Step 2: Update the Configuration Files

Go to your PKCS11 Wrapper directory (../PKCS11_Wrapper-Mac) and update the “pkcs11properties.cfg” and “ec_pkcs11client.ini” with the required details.

For “pkcs11properties.cfg”, update the library path.

NOTE: When using Luna HSM, add the slot number in the pkcs11properties.cfg file as shown below.

Luna slot number mac

For the “ec_pkcs11client.ini” file, update the six fields listed in Section 1, Step 2.

The initialization and configuration files should look like this with all the correct file paths and settings.

Config files content mac output

Step 3: Install and Activate Java 17

You will also need to install Java (Java 17 or lower) on your MacOS machine for JSign to work with our PKCS11 Wrapper.

To install Java 17 on your MacOS machine, run the following command:

brew install openjdk@17

Find the location where Java 17 is installed on your machine:

brew info openjdk@17

Now set Java 17 as the active version. For Zsh:

nano ~/.zshrc

For Bash:

nano ~/.bash_profile

After running the above command, add these lines:

export PATH=<Path of Java 17 bin folder>:$PATH
export JAVA_HOME=<Path of Java 17 bin folder>
Java path added mac

NOTE: JSign is launched with java -jar, which resolves through PATH, so this setting is sufficient for signing. Note that JAVA_HOME is conventionally set to the JDK home directory rather than to its bin subfolder, so if other Java tooling on the machine relies on JAVA_HOME you may wish to point it one level higher.

Reload the environment variables using the below commands. For Zsh:

source ~/.zshrc

For Bash:

source ~/.bash_profile

Step 4: Install the Remaining Packages

You would also need to install some other pre-requisite packages to perform signing using JSign.

brew install log4cxx
brew install curl

Step 5: Download the JSign Tool

Now, you will need to download the latest version of the JSign tool (JAR package) on your MacOS machine using this link.

JSign download mac output

To check whether JSign has been properly installed or not, run the following command:

java -jar <Path of JSign Jar Package>

We are now ready with our MacOS environment to perform the signing using JSign tool and PKCS11 Wrapper.

macOS: Sign the File

As on Linux, the signing command is run from the directory containing your configuration files. On macOS the JAR is invoked through java rather than through an installed launcher.

Step 1: Change to the Working Directory

For signing, change the working directory of the terminal to that folder which contains your “ec_pkcs11client.ini” file.

Step 2: Run the Signing Command

Now, run the signing command from this directory.

java -jar <Path of JSign tool> \
  --keystore <Path of pkcs11properties.cfg> \
  --storepass NONE \
  --storetype PKCS11 \
  --alias <Key alias of the signing certificate> \
  <Path of the file to be signed>

A sample command is provided below:

java -jar jsign-7.0.jar \
  --keystore pkcs11properties.cfg \
  --storepass NONE \
  --storetype PKCS11 \
  --alias gpg2 \
  build_project.ps1
JSign sign output mac

Step 3: Option Reference

The following are the options and their meaning in the command:

OptionDescription
--keystore The path of the pkcs11properties.cfg file, which directs JSign to the PKCS#11 wrapper instead of to a keystore file.
--storepass The keystore password. This is NONE because access is controlled by the wrapper configuration.
--storetype The keystore type, which must be PKCS11.
--alias The key alias of the signing certificate in CodeSign Secure.
<file path> The file to be signed, given as the final argument with no option name.

Step 4: Confirm the Signing Request

NOTE: There is no verification command for the JSign tool.

Open the CodeSign Secure portal and navigate to Reports > Signing Request Report, where every signing request performed through the wrapper is recorded for audit purposes.

Windows: Install and Configure

To perform signing using JSign Tool and our PKCS11 Wrapper in a Windows machine, you would need to follow the below steps.

Step 1: Download the PKCS#11 Wrapper for Windows

Go to EC CodeSign Secure v3.02’s Signing Tools section and download the PKCS11 Wrapper for Windows.

Wrapper download windows output

Step 2: Edit the Configuration Files

Go to your Windows client system and edit the configuration files (ec_pkcs11client.ini and pkcs11properties.cfg) downloaded in the PKCS11 Wrapper.

Config files edit windows output 1
Config files edit windows output 2
Config files edit windows output 3

NOTE: When using Luna HSM, add the slot number in the pkcs11properties.cfg file as shown below.

Luna slot number windows

Step 3: Install and Activate Java 22

Now, let us install some prerequisites in your client system to run the PKCS11 Wrapper.

Install Java 22 from Oracle’s official site, and follow the instructions in the msi file.

Java22 install windows output 1
Java22 install windows output 2
Java22 install windows output 3

Set Java 22 as the active version by storing the bin path in the PATH variable.

Java22 path added windows

NOTE: The Linux and macOS tracks call for Java 17 or lower, while this track installs Java 22. Confirm which version your JSign release supports before deviating from the version shown for your platform.

Step 4: Download the JSign Tool

Now, you will need to download the latest version of the JSign tool (JAR package) on your Windows machine using this link.

JSign download windows output

To check whether JSign has been properly installed or not, run the following command:

java -jar <Path of JSign Jar Package>

We are now ready with our Windows environment to perform the signing using JSign tool and PKCS11 Wrapper.

Windows: Sign the File

As on the other platforms, the signing command is run from the directory containing your configuration files.

Step 1: Change to the Working Directory

For signing, change the working directory of the terminal to that folder which contains your “ec_pkcs11client.ini” file.

Working directory windows output

Step 2: Run the Signing Command

Now, run the signing command from this directory.

java -jar <Path of JSign tool> ^
  --keystore <Path of pkcs11properties.cfg> ^
  --storepass NONE ^
  --storetype PKCS11 ^
  --alias <Key alias of the signing certificate> ^
  <Path of the file to be signed>

A sample command is provided below:

java -jar jsign-7.0.jar ^
  --keystore pkcs11properties.cfg ^
  --storepass NONE ^
  --storetype PKCS11 ^
  --alias gpg2 ^
  build_project.ps1
JSign sign output windows

NOTE: The caret characters are Command Prompt line continuations. You may keep them or join the command onto a single line.

Step 3: Option Reference

The following are the options and their meaning in the command:

OptionDescription
--keystore The path of the pkcs11properties.cfg file, which directs JSign to the PKCS#11 wrapper instead of to a keystore file.
--storepass The keystore password. This is NONE because access is controlled by the wrapper configuration.
--storetype The keystore type, which must be PKCS11.
--alias The key alias of the signing certificate in CodeSign Secure.
<file path> The file to be signed, given as the final argument with no option name.

Step 4: Confirm the Signing Request

NOTE: There is no verification command for the JSign tool.

Open the CodeSign Secure portal and navigate to Reports > Signing Request Report, where every signing request performed through the wrapper is recorded for audit purposes.