jarsigner(1)
โจ NAME โจ
okay so like, this is jarsigner(1) from the Security Tools manual, and it does exactly two (2) iconic things: it signs Java Archive (JAR) files, and it verifies them. that's the whole gig. ๐
โจ SYNOPSIS โจ
bestie, here's the shape of it:
jarsigner [ options ] jar-file alias
jarsigner -verify [ options ] jar-file [alias ...]
optionsโ the command-line options. See Options.-verifyโ this one can take zero or more keystore alias names, and they go after the JAR file name. When you pass-verify,jarsignerchecks that the certificate used to verify each signed entry in the JAR file matches one of those keystore aliases. Those aliases live in the keystore you point at with-keystore, or in the default keystore.
and listen โ if you also passed -strict, and jarsigner caught severe warnings, it hits you with the message "jar verified, with signer errors". ๐ญ
jar-fileโ the JAR file that's getting signed.
same deal here: if you also passed -strict and jarsigner detected severe warnings, the message "jar signed, with signer errors" gets displayed. ๐ซถ
aliasโ the aliases, which are defined in the keystore specified by-keystoreor in the default keystore. simple as that.
โจ DESCRIPTION โจ
so the jarsigner tool has two purposes, and I'm listing them because the manpage insists:
- to sign Java Archive (JAR) files ๐
- to verify the signatures and integrity of signed JAR files ๐
the JAR feature is literally the moment where class files, images, sounds, and other digital data get packaged into a single file so distribution is faster and easier. there's a tool named jar that lets developers produce JAR files. (technically, any zip file can also be considered a JAR file, although when it's created by the jar command or processed by the jarsigner command, JAR files also contain a META-INF/MANIFEST.MF file.) no cap.
a digital signature is a string of bits computed from some data (the data being signed) and the private key of an entity (a person, a company, whatever). and similar to a handwritten signature, a digital signature has a bunch of genuinely useful characteristics:
- its authenticity can be verified by a computation that uses the public key corresponding to the private key used to generate the signature โ
- it cannot be forged, assuming the private key is kept secret ๐
- it's a function of the data signed, so it can't be claimed to be the signature for other data as well ๐
- the signed data cannot be changed โ if the data is changed, then the signature cannot be verified as authentic ๐
to generate an entity's signature for a file, the entity must first have a public/private key pair associated with it, plus one or more certificates that authenticate its public key. a certificate is a digitally signed statement from one entity saying that the public key of another entity has a particular value. periodt.
the jarsigner command uses key and certificate info from a keystore to generate digital signatures for JAR files. a keystore is a database of private keys and their associated X.509 certificate chains that authenticate the corresponding public keys. the keytool command is what you use to create and administer keystores. ๐๏ธ
jarsigner uses an entity's private key to generate a signature. the signed JAR file contains, among other things, a copy of the certificate from the keystore for the public key corresponding to the private key used to sign the file. and jarsigner can verify the digital signature of the signed JAR file using the certificate inside it (in its signature block file). she's self-sufficient like that ๐
jarsigner can also generate signatures that include a time stamp, which lets a systems or deployer (including Java Plug-in) check whether the JAR file was signed while the signing certificate was still valid. plus, APIs allow applications to obtain the timestamp information. โฐ
at this time, jarsigner can only sign JAR files created by the jar command or zip files. JAR files are the same as zip files, except they also have a META-INF/MANIFEST.MF file. and a META-INF/MANIFEST.MF file gets created when jarsigner signs a zip file. ๐
the default jarsigner behavior is to sign a JAR or zip file. use the -verify option when you wanna verify a signed JAR file instead.
jarsigner also attempts to validate the signer's certificate after signing or verifying. if there's a validation error or any other problem, the command generates warning messages. and if you specify -strict, then the command treats severe warnings as errors. see Errors and Warnings. โ ๏ธ
๐ KEYSTORE ALIASES ๐
all keystore entities are accessed with unique aliases. that's the rule.
when you use jarsigner to sign a JAR file, you must specify the alias for the keystore entry that contains the private key needed to generate the signature. for example, this command signs the JAR file named MyJARFile.jar with the private key associated with the alias duke in the keystore named mystore in the working directory. and because no output file is specified, it overwrites MyJARFile.jar with the signed JAR file. ๐ฅ
jarsigner -keystore /working/mystore -storepass <keystore password>
-keypass <private key password> MyJARFile.jar duke
keystores are protected with a password, so the store password must be specified. you get prompted for it when you don't specify it on the command line. similarly, private keys are protected in a keystore with a password, so the private key's password must be specified too โ and you're prompted for it when you don't specify it on the command line and it isn't the same as the store password. ๐
๐ KEYSTORE LOCATION ๐
jarsigner has a -keystore option for specifying the URL of the keystore to be used. by default, the keystore is stored in a file named .keystore in the user's home directory, as determined by the user.home system property. ๐
on Oracle Solaris systems, user.home defaults to the user's home directory.
the input stream from the -keystore option is passed to the KeyStore.load method. if NONE is specified as the URL, then a null stream is passed to the KeyStore.load method. NONE should be specified when the KeyStore class is not file based โ for example, when it resides on a hardware token device. ๐ช
๐๏ธ KEYSTORE IMPLEMENTATION ๐๏ธ
the KeyStore class provided in the java.security package supplies a number of well-defined interfaces to access and modify the information in a keystore. you can have multiple different concrete implementations, where each implementation is for a particular type of keystore.
currently there are two command-line tools that use keystore implementations (keytool and jarsigner), plus a GUI-based tool named Policy Tool. and because the KeyStore class is publicly available, JDK users can write additional security applications that use it. โจ
there's a built-in default implementation provided by Oracle that implements the keystore as a file, using a proprietary keystore type (format) named JKS. the built-in implementation protects each private key with its individual password, and protects the integrity of the entire keystore with a (possibly different) password. ๐ง
keystore implementations are provider-based, which means the application interfaces supplied by the KeyStore class are implemented in terms of a Service Provider Interface (SPI). there's a corresponding abstract KeystoreSpi class, also in the java.security package, that defines the Service Provider Interface methods that providers must implement. the term provider refers to a package or a set of packages that supply a concrete implementation of a subset of services that can be accessed by the Java Security API. to provide a keystore implementation, clients must implement a provider and supply a KeystoreSpi subclass implementation, as described in How to Implement a Provider in the Java Cryptography Architecture at http://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/HowToImplAProvider.html
applications can choose different types of keystore implementations from different providers, using the getInstance factory method in the KeyStore class. a keystore type defines the storage and data format of the keystore information, plus the algorithms used to protect private keys in the keystore and the integrity of the keystore itself. keystore implementations of different types are not compatible. like, at all. ๐
jarsigner can read file-based keystores from any location that can be specified using a URL. in addition, the command can read non-file-based keystores such as those provided by MSCAPI on Windows and PKCS11 on all platforms. ๐
for the jarsigner and keytool commands, you can specify a keystore type at the command line with the -storetype option. for Policy Tool, you can specify a keystore type with the Edit command in the KeyStore menu. ๐ฑ๏ธ
if you don't explicitly specify a keystore type, then the tools choose a keystore implementation based on the value of the keystore.type property specified in the security properties file. that security properties file is called java.security, and it resides in the JDK security properties directory, java.home/lib/security, where java.home is the runtime environment's directory โ the jre directory in the JDK, or the top-level directory of the Java Runtime Environment (JRE).
each tool gets the keystore.type value and then examines all the installed providers until it finds one that implements keystores of that type. then it uses the keystore implementation from that provider. ๐ต๏ธ
the KeyStore class defines a static method named getDefaultType that lets applications and applets retrieve the value of the keystore.type property. this line of code creates an instance of the default keystore type as specified in the keystore.type property:
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
the default keystore type is jks (the proprietary type of the keystore implementation provided by Oracle). this is specified by the following line in the security properties file:
keystore.type=jks
case does not matter in keystore type designations โ for example, JKS is the same as jks. iykyk. ๐
to have the tools use a keystore implementation other than the default, change that line to specify a different keystore type. for example, if you have a provider package that supplies a keystore implementation for a keystore type called pkcs12, then change the line to this:
keystore.type=pkcs12
Note: if you use the PKCS 11 provider package, then see"KeyTool"and"JarSigner"in Java PKCS #11 Reference Guide athttp://docs.oracle.com/javase/8/docs/technotes/guides/security/p11guide.html
๐งช SUPPORTED ALGORITHMS ๐งช
by default, jarsigner signs a JAR file using one of the following algorithms:
- Digital Signature Algorithm (DSA) with the SHA1 digest algorithm ๐
- RSA algorithm with the SHA256 digest algorithm ๐
- Elliptic Curve (EC) cryptography algorithm with the
SHA256with Elliptic Curve Digital Signature Algorithm (ECDSA) โ yes bestie, that's a whole mouthful, but it's just EC + SHA256 + ECDSA, iconic combo โจ
So here's the tea on defaults: if the signer's public and private keys are DSA keys, then jarsigner signs the JAR file with the SHA1withDSA algorithm. If the signer's keys are RSA keys, then jarsigner attempts to sign the JAR file with the SHA256withRSA algorithm. And if the signer's keys are EC keys, then jarsigner signs the JAR file with the SHA256withECDSA algorithm. ๐
These default signature algorithms can be overridden using the -sigalg option. Periodt โ you're in charge.
๐ THE SIGNED JAR FILE ๐
When the jarsigner command is used to sign a JAR file, the output signed JAR file is exactly the same as the input JAR file, except that it has two additional files placed in the META-INF directory โ like a little surprise gift in the packaging, no cap:
- A signature file with an
.SFextension - A signature block file with a
.DSA,.RSA, or.ECextension
The base file names for these two files come from the value of the -sigFile option. For example, when the option is -sigFile MKSIGN, the files are named MKSIGN.SF and MKSIGN.DSA โ see how that works? Chef's kiss. ๐
If no -sigfile option appears on the command line, then the base file name for the .SF and .DSA files is the first 8 characters of the alias name specified on the command line, all converted to uppercase. If the alias name has fewer than 8 characters, then the full alias name is used. And if the alias name contains any characters that are not allowed in a signature file name, then each such character is converted to an underscore (_) character in forming the file name. Valid characters include letters, digits, underscores, and hyphens โ that's the whole guest list, bestie. ๐ฆ
๐ Signature File ๐
A signature file (.SF file) looks similar to the manifest file that is always included in a JAR file when the jarsigner command is used to sign the file. For each source file included in the JAR file, the .SF file has three lines, such as in the manifest file, that list the following:
- File name
- Name of the digest algorithm (
SHA) SHAdigest value
In the manifest file, the SHA digest value for each source file is the digest (hash) of the binary data in the source file. In the .SF file, the digest value for a specified source file is the hash of the three lines in the manifest file for the source file. It's giving inception, but make it cryptographic. ๐ง
The signature file, by default, includes a header with a hash of the whole manifest file. The header also contains a hash of the manifest header. The presence of the header enables verification optimization. See JAR File Verification. โญ
๐ Signature Block File ๐
The .SF file is signed and the signature is placed in the signature block file. This file also contains, encoded inside it, the certificate or certificate chain from the keystore that authenticates the public key corresponding to the private key used for signing. The file has the extension .DSA, .RSA, or .EC, depending on the digest algorithm used. So it's literally carrying the whole proof-of-identity situation. ๐
โฐ SIGNATURE TIME STAMP โฐ
The jarsigner command can generate and store a signature time stamp when signing a JAR file. In addition, jarsigner supports alternative signing mechanisms. This behavior is optional and is controlled by the user at the time of signing through these options. See Options. ๐ฐ๏ธ
-tsa url-tsacert alias-altsigner class-altsignerpath classpathlist-tsapolicyid policyid
๐ JAR FILE VERIFICATION ๐
A successful JAR file verification occurs when the signatures are valid, and none of the files that were in the JAR file when the signatures were generated have changed since then. JAR file verification involves the following steps โ vibe check, but for signatures:
- Verify the signature of the
.SFfile.
The verification ensures that the signature stored in each signature block (.DSA) file was generated using the private key corresponding to the public key whose certificate (or certificate chain) also appears in the .DSA file. It also ensures that the signature is a valid signature of the corresponding signature (.SF) file, and thus the .SF file was not tampered with. No sneaky edits allowed. ๐
- Verify the digest listed in each entry in the
.SFfile with each corresponding section in the manifest.
The .SF file by default includes a header that contains a hash of the entire manifest file. When the header is present, the verification can check to see whether or not the hash in the header matches the hash of the manifest file. If there is a match, then verification proceeds to the next step. Slay, moving on. โ
If there is no match, then a less optimized verification is required to ensure that the hash in each source file information section in the .SF file equals the hash of its corresponding section in the manifest file. See Signature File.
One reason the hash of the manifest file that is stored in the .SF file header might not equal the hash of the current manifest file is that one or more files were added to the JAR file (with the jar tool) after the signature and .SF file were generated. When the jar tool is used to add files, the manifest file is changed by adding sections to it for the new files, but the .SF file is not changed. A verification is still considered successful when none of the files that were in the JAR file when the signature was generated have been changed since then. This happens when the hashes in the non-header sections of the .SF file equal the hashes of the corresponding sections in the manifest file. So like, new friends can join the party, the OGs just have to still be exactly who they were. ๐ซถ
- Read each file in the JAR file that has an entry in the
.SFfile. While reading, compute the file's digest and compare the result with the digest for this file in the manifest section. The digests should be the same or verification fails.
If any serious verification failures occur during the verification process, then the process is stopped and a security exception is thrown. The jarsigner command catches and displays the exception. ๐ญ
Note: You should read any addition warnings (or errors if you specified the-strictoption), as well as the content of the certificate (by specifying the-verboseand-certsoptions) to determine if the signature can be trusted. Don't skip the fine print bestie, it's there for a reason. ๐
๐ฏ MULTIPLE SIGNATURES FOR A JAR FILE ๐ฏ
A JAR file can be signed by multiple people by running the jarsigner command on the file multiple times and specifying the alias for a different person each time, as follows โ collab era:
jarsigner myBundle.jar susan
jarsigner myBundle.jar kevin
When a JAR file is signed multiple times, there are multiple .SF and .DSA files in the resulting JAR file, one pair for each signature. In the previous example, the output JAR file includes files with the following names:
SUSAN.SF
SUSAN.DSA
KEVIN.SF
KEVIN.DSA
Two besties, two signature pairs, zero drama. ๐ธ
โจ OPTIONS โจ
The following sections describe the various jarsigner options. Be aware of the following standards, queen:
- All option names are preceded by a minus sign (
-). - The options can be provided in any order.
- Items that are in italics or underlined (option values) represent the actual values that must be supplied.
- The
-storepass,-keypass,-sigfile,-sigalg,-digestalg,-signedjar, and TSA-related options are only relevant when signing a JAR file; they are not relevant when verifying a signed JAR file. The-keystoreoption is relevant for signing and verifying a JAR file. In addition, aliases are specified when signing and verifying a JAR file.
-keystoreurl โ Specifies the URL that tells the keystore location. This defaults to the file.keystorein the user's home directory, as determined by theuser.homesystem property.
A keystore is required when signing. You must explicitly specify a keystore when the default keystore does not exist or if you want to use one other than the default.
A keystore is not required when verifying, but if one is specified or the default exists and the -verbose option was also specified, then additional information is output regarding whether or not any of the certificates used to verify the JAR file are contained in that keystore.
The -keystore argument can be a file name and path specification rather than a URL, in which case it is treated the same as a file: URL, for example, the following are equivalent:
-keystore filePathAndName
-keystore file:filePathAndName
If the Sun PKCS #11 provider was configured in the java.security security properties file (located in the JRE's $JAVA_HOME/lib/security directory), then the keytool and jarsigner tools can operate on the PKCS #11 token by specifying these options:
-keystore NONE
-storetype PKCS11
For example, the following command lists the contents of the configured PKCS#11 token:
keytool -keystore NONE -storetype PKCS11 -list
-storetypestoretype โ Specifies the type of keystore to be instantiated. The default keystore type is the one that is specified as the value of thekeystore.typeproperty in the security properties file, which is returned by the staticgetDefaultTypemethod injava.security.KeyStore.
The PIN for a PCKS #11 token can also be specified with the -storepass option. If none is specified, then the keytool and jarsigner commands prompt for the token PIN. If the token has a protected authentication path (such as a dedicated PIN-pad or a biometric reader), then the -protected option must be specified and no password options can be specified. Rules are rules, bestie. ๐ซ
-storepass[:env | :file]argument โ Specifies the password that is required to access the keystore. This is only needed when signing (not verifying) a JAR file. In that case, if a-storepassoption is not provided at the command line, then the user is prompted for the password.
If the modifier env or file is not specified, then the password has the value argument. Otherwise, the password is retrieved as follows:
env: Retrieve the password from the environment variable named argument.file: Retrieve the password from the file named argument.
Note: The password should not be specified on the command line or in a script unless it is for testing purposes, or you are on a secure system. Like, seriously, don't be out here leaking your passwords in plaintext, that's not the flex you think it is. ๐๐
-keypass[:env | :file]argument โ Specifies the password used to protect the private key of the keystore entry addressed by the alias specified on the command line. The password is required when usingjarsignerto sign a JAR file. If no password is provided on the command line, and the required password is different from the store password, then the user is prompted for it.
If the modifier env or file is not specified, then the password has the value argument. Otherwise, the password is retrieved as follows:
env: Retrieve the password from the environment variable named argument.file: Retrieve the password from the file named argument.
โ ๏ธ Note: The password should not be specified on the command line or in a script unless it is for testing purposes, or you are on a secure system. Periodt. ๐
-sigfile fileโ okay so this one sets the base file name for the generated.SFand.DSAfiles. For example, if file isDUKESIGN, then the generated.SFand.DSAfiles are namedDUKESIGN.SFandDUKESIGN.DSA, and they get placed in theMETA-INFdirectory of the signed JAR file. The characters in the file must come from the seta-zA-Z0-9_-. Only letters, numbers, underscore, and hyphen characters are allowed. All lowercase characters are converted to uppercase for the.SFand.DSAfile names. If no-sigfileoption appears on the command line, then the base file name for the.SFand.DSAfiles is the first 8 characters of the alias name specified on the command line, all converted to upper case. If the alias name has fewer than 8 characters, then the full alias name is used. If the alias name contains any characters that are not valid in a signature file name, then each such character is converted to an underscore (_) character to form the file name. Slay, naming rules handled. ๐-sigalg algorithmโ specifies the name of the signature algorithm to use to sign the JAR file. For a list of standard signature algorithm names, see"Appendix A: Standard Names"in the Java Cryptography Architecture (JCA) Reference Guide athttp://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA. This algorithm must be compatible with the private key used to sign the JAR file. If this option is not specified, thenSHA1withDSA,SHA256withRSA, orSHA256withECDSAare used depending on the type of private key. There must either be a statically installed provider supplying an implementation of the specified algorithm or the user must specify one with the-providerClassoption; otherwise, the command will not succeed. Algorithm vibe check: must match the key, no cap. โจ-digestalg algorithmโ specifies the name of the message digest algorithm to use when digesting the entries of a JAR file. For a list of standard message digest algorithm names, see"Appendix A: Standard Names"in the Java Cryptography Architecture (JCA) Reference Guide athttp://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA. If this option is not specified, thenSHA256is used. There must either be a statically installed provider supplying an implementation of the specified algorithm or the user must specify one with the-providerClassoption; otherwise, the command will not succeed. Digest it, bestie. ๐ฆ-certsโ if the-certsoption appears on the command line with the-verifyand-verboseoptions, then the output includes certificate information for each signer of the JAR file. This information includes the name of the type of certificate (stored in the.DSAfile) that certifies the signer's public key, and if the certificate is an X.509 certificate (an instance ofjava.security.cert.X509Certificate), then the distinguished name of the signer. The keystore is also examined. If no keystore value is specified on the command line, then the default keystore file (if any) is checked. If the public key certificate for a signer matches an entry in the keystore, then the alias name for the keystore entry for that signer is displayed in parentheses. Certificate tea, served with parentheses. ๐ซถ-certchain fileโ specifies the certificate chain to be used when the certificate chain associated with the private key of the keystore entry that is addressed by the alias specified on the command line is not complete. This can happen when the keystore is located on a hardware token where there is not enough capacity to hold a complete certificate chain. The file can be a sequence of concatenated X.509 certificates, or a singlePKCS#7formatted data block, either in binary encoding format or in printable encoding format (also known as Base64 encoding) as defined by the Internet RFC 1421 standard. See Internet RFC 1421 Certificate Encoding Standard andhttp://tools.ietf.org/html/rfc1421. Chain complete? If not, this is the patch-in. ๐ง-verboseโ when the-verboseoption appears on the command line, it indicates verbose mode, which causesjarsignerto output extra information about the progress of the JAR signing or verification. Not me loving extra progress tea. ๐ญ-internalsfโ in the past, the.DSA(signature block) file generated when a JAR file was signed included a complete encoded copy of the.SFfile (signature file) also generated. This behavior has been changed. To reduce the overall size of the output JAR file, the.DSAfile by default does not contain a copy of the.SFfile anymore. If-internalsfappears on the command line, then the old behavior is utilized. This option is useful for testing. In practice, do not use the-internalsfoption because it incurs higher overhead. Old behavior warning: testing only, bestie. Itโs giving extra overhead. ๐-sectionsonlyโ if the-sectionsonlyoption appears on the command line, then the.SFfile (signature file) generated when a JAR file is signed does not include a header that contains a hash of the whole manifest file. It contains only the information and hashes related to each individual source file included in the JAR file. See Signature File. By default, this header is added, as an optimization. When the header is present, whenever the JAR file is verified, the verification can first check to see whether the hash in the header matches the hash of the whole manifest file. When there is a match, verification proceeds to the next step. When there is no match, it is necessary to do a less optimized verification that the hash in each source file information section in the.SFfile equals the hash of its corresponding section in the manifest file. See JAR File Verification. The-sectionsonlyoption is primarily used for testing. It should not be used other than for testing because using it incurs higher overhead. Header skipped = slower vibe later. Iconic warning. ๐-protectedโ values can be eithertrueorfalse. Specifytruewhen a password must be specified through a protected authentication path such as a dedicated PIN reader. Protected path, protected password, protected main character energy. ๐-providerClass provider-class-nameโ used to specify the name of cryptographic service provider's master class file when the service provider is not listed in thejava.securitysecurity properties file. Used with the-providerArg ConfigFilePathoption, thekeytoolandjarsignertools install the provider dynamically and useConfigFilePathfor the path to the token configuration file. The following example shows a command to list aPKCS #11keystore when the OraclePKCS #11provider was not configured in the security properties file.
jarsigner -keystore NONE -storetype PKCS11 \
-providerClass sun.security.pkcs11.SunPKCS11 \
-providerArg /mydir1/mydir2/token.config \
-list
-providerName providerNameโ if more than one provider was configured in thejava.securitysecurity properties file, then you can use the-providerNameoption to target a specific provider instance. The argument to this option is the name of the provider. For the OraclePKCS #11provider,providerNameis of the formSunPKCS11-TokenName, whereTokenNameis the name suffix that the provider instance has been configured with, as detailed in the configuration attributes table. For example, the following command lists the contents of thePKCS #11keystore provider instance with name suffixSmartCard:
jarsigner -keystore NONE -storetype PKCS11 \
-providerName SunPKCS11-SmartCard \
-list
-Jjavaoptionโ passes through the specifiedjavaoptionstring directly to the Java interpreter. Thejarsignercommand is a wrapper around the interpreter. This option should not contain any spaces. It is useful for adjusting the execution environment or memory usage. For a list of possible interpreter options, typejava -horjava -Xat the command line. No spaces, bestie โ itโs a direct pass-through. ๐-tsa urlโ if-tsa http://example.tsa.urlappears on the command line when signing a JAR file then a time stamp is generated for the signature. The URL,http://example.tsa.url, identifies the location of the Time Stamping Authority (TSA) and overrides any URL found with the-tsacertoption. The-tsaoption does not require the TSA public key certificate to be present in the keystore. To generate the time stamp,jarsignercommunicates with the TSA with the Time-Stamp Protocol (TSP) defined in RFC 3161. When successful, the time stamp token returned by the TSA is stored with the signature in the signature block file. Time stamp era: certified. โญ-tsacert aliasโ when-tsacert aliasappears on the command line when signing a JAR file, a time stamp is generated for the signature. The alias identifies the TSA public key certificate in the keystore that is in effect. The entry's certificate is examined for a Subject Information Access extension that contains a URL identifying the location of the TSA. The TSA public key certificate must be present in the keystore when using the-tsacertoption. TSA cert has to be in the keystore for this one โ no skipping. ๐ฆ-tsapolicyid policyidโ specifies the object identifier (OID) that identifies the policy ID to be sent to the TSA server. If this option is not specified, no policy ID is sent and the TSA server will choose a default policy ID. Object identifiers are defined by X.696, which is an ITU Telecommunication Standardization Sector (ITU-T) standard. These identifiers are typically period-separated sets of non-negative digits like1.2.3.4, for example. OID? More like OMG-ID, but make it policy. ๐-altsigner classโ this option specifies an alternative signing mechanism. The fully qualified class name identifies a class file that extends thecom.sun.jarsigner.ContentSignerabstract class. The path to this class file is defined by the-altsignerpathoption. If the-altsigneroption is used, then thejarsignercommand uses the signing mechanism provided by the specified class. Otherwise, thejarsignercommand uses its default signing mechanism. For example, to use the signing mechanism provided by a class namedcom.sun.sun.jarsigner.AuthSigner, use thejarsigneroption-altsigner com.sun.jarsigner.AuthSigner. Alternative signer? Main character energy, but keep the class name exact. ๐-altsignerpath classpathlistโ specifies the path to the class file and any JAR file it depends on. The class file name is specified with the-altsigneroption. If the class file is in a JAR file, then this option specifies the path to that JAR file. An absolute path or a path relative to the current directory can be specified. Ifclasspathlistcontains multiple paths or JAR files, then they should be separated with a colon (:) on Oracle Solaris and a semicolon (;) on Windows. This option is not necessary when the class is already in the search path. Path separator tea: colon on Oracle Solaris, semicolon on Windows. Iykyk. ๐ซถ
The following example shows you how to point at the path of a JAR file that contains the class file โ note that the JAR file name is included:
-altsignerpath /home/user/lib/authsigner.jar
And the next one shows the path to the JAR file that contains the class file, but this time the JAR file name is left out:
-altsignerpath /home/user/classes/com/sun/tools/jarsigner/
-strictโ okay so during signing or verifying, the command might throw warning messages at you. If you pass this option, the exit code of the tool actually reflects the severe warning messages it found. Head down to Errors and Warnings for the deets.-verbosesuboptions โ for the verifying process,-verbosetakes suboptions that decide how much info gets shown ๐. If-certsis also specified, then the default mode (aka suboptionall) displays each entry as it's being processed, and after that, the certificate information for each signer of the JAR file. If-certsand the-verbose:groupedsuboptions are specified, then entries with the same signer info are grouped and displayed together with their certificate information. And if-certsand the-verbose:summarysuboptions are specified, then entries with the same signer information are grouped and displayed together with their certificate information โ only the details about each entry get summarized and displayed as one entry (and more). Peep Examples for the visual ๐.
๐ญ ERRORS AND WARNINGS ๐ญ
During the signing or verifying process, the jarsigner command may issue various errors or warnings. It's giving "we need to talk" energy but it's honestly for your own good.
If there's a failure, the jarsigner command exits with code 1. If there's no failure but there are one or more severe warnings, the jarsigner command exits with code 0 when the -strict option is not specified โ or exits with the OR-value of the warning codes when -strict is specified โจ. If there are only informational warnings, or no warning at all, the command always exits with code 0.
For example, if a certificate used to sign an entry is expired and has a KeyUsage extension that doesn't allow it to sign a file, the jarsigner command exits with code 12 (=4+8) when the -strict option is specified. Math ate, honestly ๐งฎ๐
Note: exit codes are reused because only the values from0to255are legal on Unix-based operating systems. Like, that's the whole budget, bestie.
The following sections describe the names, codes, and descriptions of the errors and warnings that the jarsigner command can issue.
๐ FAILURE ๐
Reasons why the jarsigner command fails include (but are not limited to) a command line parsing error, the inability to find a keypair to sign the JAR file, or the verification of a signed JAR fails. Rough.
failureโ Code1. The signing or verifying fails. That's it, that's the whole vibe ๐ญ
๐ฅ SEVERE WARNINGS ๐ฅ
Note: severe warnings are reported as errors if you specify the -strict option. So like, they get promoted. Main character energy, honestly ๐
Reasons why the jarsigner command issues a severe warning include the certificate used to sign the JAR file has an error, or the signed JAR file has other problems.
hasExpiredCertโ Code4. This jar contains entries whose signer certificate has expired. Girl, it's expired ๐notYetValidCertโ Code4. This jar contains entries whose signer certificate is not yet valid.chainNotValidatedโ Code4. This jar contains entries whose certificate chain cannot be correctly validated.badKeyUsageโ Code8. This jar contains entries whose signer certificate'sKeyUsageextension doesn't allow code signing.badExtendedKeyUsageโ Code8. This jar contains entries whose signer certificate'sExtendedKeyUsageextension doesn't allow code signing.badNetscapeCertTypeโ Code8. This jar contains entries whose signer certificate'sNetscapeCertTypeextension doesn't allow code signing.hasUnsignedEntryโ Code16. This jar contains unsigned entries which have not been integrity-checked. Not me trusting unverified content ๐ฌnotSignedByAliasโ Code32. This jar contains signed entries which are not signed by the specified alias(es).aliasNotInStoreโ Code32. This jar contains signed entries that are not signed by alias in this keystore.
๐ธ INFORMATIONAL WARNINGS ๐ธ
Informational warnings include those that are not errors but are regarded as bad practice. They do not have a code. They're the "not mad, just disappointed" tier ๐ซถ
hasExpiringCertโ This jar contains entries whose signer certificate will expire within six months. Clock's ticking bestie โฐnoTimestampโ This jar contains signatures that does not include a timestamp. Without a timestamp, users may not be able to validate this JAR file after the signer certificate's expiration date (YYYY-MM-DD) or after any future revocation date.
โจ EXAMPLES โจ
๐ SIGN A JAR FILE ๐
Use the following command to sign bundle.jar with the private key of a user whose keystore alias is jane in a keystore named mystore in the working directory โ and name the signed JAR file sbundle.jar:
jarsigner -keystore /working/mystore
-storepass <keystore password>
-keypass <private key password>
-signedjar sbundle.jar bundle.jar jane
There's no -sigfile specified in the previous command, so the generated .SF and .DSA files that get placed in the signed JAR file have default names based on the alias name. They're named JANE.SF and JANE.DSA ๐
(yes, uppercase, she's loud and proud).
If you want to be prompted for the store password and the private key password, then you could shorten the previous command to the following:
jarsigner -keystore /working/mystore
-signedjar sbundle.jar bundle.jar jane
If the keystore is the default keystore (.keystore in your home directory), then you do not need to specify a keystore, as follows:
jarsigner -signedjar sbundle.jar bundle.jar jane
And if you want the signed JAR file to overwrite the input JAR file (bundle.jar), then you don't need to specify a -signedjar option, as follows:
jarsigner bundle.jar jane
๐ฆ VERIFY A SIGNED JAR FILE ๐ฆ
To verify a signed JAR file โ to ensure the signature is valid and the JAR file was not tampered with โ use a command such as the following:
jarsigner -verify sbundle.jar
When the verification is successful, jar verified is displayed ๐. Otherwise, an error message is displayed. You can get more information when you use the -verbose option. A sample use of jarsigner with the -verbose option follows:
jarsigner -verify -verbose sbundle.jar
198 Fri Sep 26 16:14:06 PDT 1997 META-INF/MANIFEST.MF
199 Fri Sep 26 16:22:10 PDT 1997 META-INF/JANE.SF
1013 Fri Sep 26 16:22:10 PDT 1997 META-INF/JANE.DSA
smk 2752 Fri Sep 26 16:12:30 PDT 1997 AclEx.class
smk 849 Fri Sep 26 16:12:46 PDT 1997 test.class
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
jar verified.
๐ VERIFICATION WITH CERTIFICATE INFORMATION ๐
If you specify the -certs option together with the -verify and -verbose options, then the output includes certificate information for each signer of the JAR file. That info includes the certificate type, the signer distinguished name information (when it's an X.509 certificate), and in parentheses, the keystore alias for the signer when the public key certificate in the JAR file matches the one in a keystore entry. For example:
jarsigner -keystore /working/mystore -verify -verbose -certs myTest.jar
198 Fri Sep 26 16:14:06 PDT 1997 META-INF/MANIFEST.MF
199 Fri Sep 26 16:22:10 PDT 1997 META-INF/JANE.SF
1013 Fri Sep 26 16:22:10 PDT 1997 META-INF/JANE.DSA
208 Fri Sep 26 16:23:30 PDT 1997 META-INF/JAVATEST.SF
1087 Fri Sep 26 16:23:30 PDT 1997 META-INF/JAVATEST.DSA
smk 2752 Fri Sep 26 16:12:30 PDT 1997 Tst.class
X.509, CN=Test Group, OU=Java Software, O=Oracle, L=CUP, S=CA, C=US (javatest)
X.509, CN=Jane Smith, OU=Java Software, O=Oracle, L=cup, S=ca, C=us (jane)
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
jar verified.
If the certificate for a signer is not an X.509 certificate, then there's no distinguished name information. In that case, just the certificate type and the alias are shown. For example, if the certificate is a PGP certificate, and the alias is bob, then you would get: PGP, (bob) ๐ซถ
๐ SEE ALSO ๐
jar(1)keytool(1)- Trail: Security Features in Java SE at
http://docs.oracle.com/javase/tutorial/security/index.html
okay that's the whole page bestie, go forth and sign things responsibly ๐ง๐
This icon of a manual page is brought to you by JDK 8, dated 21 November 2013 โ yeah she's an older queen but she still ate, periodt ๐ โจ
๐ฆ where this page comes from
- centos-stream 9: java-11-openjdk-devel-slowdebug 1:11.0.20.1.1-2.el9 ยท ASL 1.1 and ASL 2.0 and BSD and BSD with advertising and GPL+ and GPLv2 and GPLv2 with exceptions and IJG and LGPLv2+ and MIT and MPLv2.0 and Public Domain and W3C and zlib and ISC and FTL and RSA
- Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms