Signing Java .jar Files with the CLI (Command Line Interface) Command Jarsigner
These instructions are for signing Java .jar files with a code signing or EV code signing installed on a hardware token.
When you use your certificate to sign code, a digital signature is applied to your code. This digital signature boosts customer confidence in the code they are about to download and helps to improve the adoption of your Java applications. Many end-users cancel downloads or installations when they receive a warning that an unknown publisher signed the code.
name=eToken library=c:\WINDOWS\system32\eTPKCS11.dll |
Keytool -list -keystore NONE -storetype PKCS11 -providerclass sun.security.pkcs11.SunPKCS11 -providerArg ./eToken.cfg enter keystore password: [enter password] |
Keystore type: PKCS11 Keystore provider: SunPKCS11-eToken Your keystore contains 1 entry 7800FA4C81523ACA, PrivateKeyEntry, Certificate fingerprint (SHA2): XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX |
Note: with newer versions of SafeNet Authentication Client (SAC) driver the “Certificate Alias Value” is going to be the organization name.
Here is sample output from a Code Signing token using the newer SAC drivers (sceenshot 1):
Solution:
The “Certificate Alias Value” may not be a random string of alpha-numerical characters. It may be that it is the organization name as listed in the Keytool command output. It will be the string prior to the comma of “PrivateKeyEntry”. In our case it is “Win the Customer, LLC” instead of a random value.
ALTERNATIVE SOLUTIONS:
It is totally possible that there is no value associated with the certificate alias: organization name or otherwise. In this case the customer should try running the Keytool command on a different network/machine because there could be group policy settings or something that is prohibiting Keytool from communicating with the token and accessing the value necessary for signing.
If the incorrect Certificate alias is specified you will the following error message: java.security.KeyStoreException: PKCS11 not found.
To fix the above error you need to add slot=0 and to find the correct slot used by the token, please set the slot number to zero in your eToken.cfg file (slot=0).
Attempt to run the list command again, incrementing the slot number by 1 with each iteration of the error.
You should eventually receive the Enter KeyStore Password prompt that will accept your SafeNet Token passphrase.
etoken.cfg:
”name=eToken
library=c:\WINDOWS\system32\eTPKCS11.dll
slot=0”
5. To use the code signing certificate on the token to sign file.jar, run the following command from the command prompt:
jarsigner -tsa http://timestamp.digicert.com -verbose -keystore NONE - storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 - providerArg ./eToken.cfg "C:\path\to\file.jar" "7800FA4C81523ACA" |
6. If the command executed successfully, you should see something similar to the following sample output:
Enter Passphrase for keystore: adding: META-INF/7800FA4C.SF requesting a signature timestamp TSA location: http://timestamp.digicert.com adding: META-INF/7800FA4C.RSA signing: DigiCertTest.class jar signed. |