JARSIGNER(1)
π JARSIGNER(1) β JDK Commands, bestie edition π
okay so real quick, this is the page for jarsigner, and it lives in the JDK Commands manual. grab a lil snack, we're getting into it β¨
β¨ NAME β¨
jarsigner β sign and verify Java Archive (JAR) files π«Ά
πΈ SYNOPSIS πΈ
jarsigner [options] jar-file alias
jarsigner -verify [options] jar-file [alias ...]
jarsigner -version
so let's break those down, no cap:
optionsβ the command-line options, duh. See Options forjarsigner. π-verifyβ okay so-verifycan take zero or more keystore alias names 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 the keystore aliases. those aliases are defined in the keystore you named with-keystore, or in the default keystore. πjar-fileβ the JAR file you're signing.aliasβ the aliases, defined in the keystore specified by-keystoreor the default keystore. π
and the messages, because these matter π:
If you also specify the-strictoption, andjarsignerdetects severe warnings, the message "jar verified, with signer errors" is displayed.
If you also specified the-strictoption, andjarsignerdetected severe warnings, the message "jar signed, with signer errors" is displayed.
-versionβ prints the program version ofjarsigner. that's it, that's the whole vibe β¨
π¦ DESCRIPTION π¦
jarsigner has two whole purposes, and honestly? both iconic:
- to sign Java Archive (JAR) files π
- to verify the signatures and integrity of signed JAR files β
so the JAR feature is what lets you package class files, images, sounds, and other digital data into a single file for faster and easier distribution. there's a tool called 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 jarsigner, JAR files also contain a META-INF/MANIFEST.MF file. iykyk π¦)
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 many 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 can't be forged, assuming the private key is kept secret π
- it is a function of the data signed and thus can't be claimed to be the signature for other data as well
- the signed data can't be changed. if the data is changed, then the signature can't be verified as authentic π
to generate an entity's signature for a file, that entity first needs 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. π
jarsigner 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. and 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. then jarsigner can verify the digital signature of the signed JAR file using the certificate inside it (in its signature block file). π
jarsigner can also generate signatures that include a time stamp, which lets a systems or deployer check whether the JAR file was signed while the signing certificate was still valid. β°
plus, APIs let applications obtain the timestamp information.
at this time (yes, "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. ποΈ
default behavior? jarsigner signs a JAR or zip file. that's the main character energy. use the -verify option to verify a signed JAR file instead. π
jarsigner also attempts to validate the signer's certificate after signing or verifying. during validation, it checks the revocation status of each certificate in the signer's certificate chain when the -revCheck option is specified. if there's a validation error or any other problem, the command generates warning messages. and if you specify the -strict option, then the command treats severe warnings as errors. see Errors and Warnings. β οΈ
π KEYSTORE ALIASES π
all keystore entities are accessed with unique aliases.
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. and if no output file is specified, it overwrites the original JAR file with the signed JAR file. (yes, it just does that, bestie π)
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 β and you get 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. π
Linux and macOS: 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 isn't 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.
the default keystore implementation is PKCS12. this is a cross platform keystore based on the RSA PKCS12 Personal Information Exchange Syntax Standard. that standard is primarily meant for storing or transporting a user's private keys, certificates, and miscellaneous secrets. there's another built-in implementation provided by Oracle, too: it implements the keystore as a file with a proprietary keystore type (format) named JKS. it protects each private key with its individual password, and also 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 (https://www.oracle.com/pls/topic/lookup?ctx=en/java/javase&id=security_guide_implement_provider_jca). π§
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 and the algorithms used to protect private keys in the keystore and the integrity of the keystore itself. keystore implementations of different types aren't compatible. periodt π
jarsigner can read file-based keystores from any location that can be specified using a URL. in addition, it 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. π οΈ
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/conf/security. π
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 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 pkcs12, which is a cross platform keystore based on the RSA PKCS12 Personal Information Exchange Syntax Standard. this is specified by the following line in the security properties file:
keystore.type=pkcs12
case doesn't matter in keystore type designations, okay? for example, JKS is the same as jks. π
to have the tools utilize a keystore implementation other than the default, you can change that line to specify a different keystore type. for example, if you want to use Oracle's jks keystore implementation, then change the line to the following:
keystore.type=jks
π SUPPORTED ALGORITHMS π
okay so by default, jarsigner signs a JAR file using one of these algorithms and block file extensions, and which one it picks depends on the type and size of the private key. no cap, it's just vibes-based on your key:
Default Signature Algorithms and Block File Extensions β¨
DSA- any size β
SHA256withDSA - block file extension β
.DSA
- any size β
RSA< 624βSHA256withRSA<= 7680βSHA384withRSA> 7680βSHA512withRSA- block file extension β
.RSA
EC< 512βSHA384withECDSA>= 512βSHA512withECDSA- block file extension β
.EC
RSASSA-PSS< 624βRSASSA-PSS (with SHA-256)<= 7680βRSASSA-PSS (with SHA-384)> 7680βRSASSA-PSS (with SHA-512)- block file extension β
.RSA
EdDSA255βEd25519448βEd448- block file extension β
.EC
- if an
RSASSA-PSSkey is encoded with parameters, thenjarsignerwill use the same parameters in the signature. otherwise,jarsigneruses parameters determined by the size of the key, exactly like the table above says. for example, a3072-bitRSASSA-PSSkey will useRSASSA-PSSas the signature algorithm andSHA-384as the hash and MGF1 algorithms. π«Ά - if a key algorithm isn't listed in this table, the
.DSAextension is used when signing a JAR file. that's just the rule, iykyk.
these default signature algorithms can be overridden by using the -sigalg option. π
the jarsigner command uses the jdk.jar.disabledAlgorithms and jdk.security.legacyAlgorithms security properties to figure out which algorithms are considered a security risk. so:
- if the JAR file was signed with any algorithms that are disabled, it will be treated as an unsigned JAR file. π
- if the JAR file was signed with any legacy algorithms, it will be treated as signed, but with an informational warning telling users that the legacy algorithm will be disabled in a future update.
for detailed verification output, include -J-Djava.security.debug=jar. the jdk.jar.disabledAlgorithms and jdk.security.legacyAlgorithms security properties are defined in the java.security file (located in the JDK's $JAVA_HOME/conf/security directory). πΈ
Note: π§ in order to improve out of the box security, default key size and signature algorithm names are periodically updated to stronger values with each release of the JDK. if interoperability with older releases of the JDK is important, please make sure the defaults are supported by those releases, or alternatively use the -sigalg option to override the default values at your own risk. π₯
π THE SIGNED JAR FILE
when jarsigner signs a JAR file, the output signed JAR file is exactly the same as the input JAR file, except it has two extra files dropped into the META-INF directory:
- 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.RSA. in this document, we assume the signer always uses an RSA key. β¨
if no -sigfile option appears on the command line, then the base file name for the .SF and the signature block 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
8characters, then the full alias name is used. - if the alias name contains any characters that aren't 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.
π SIGNATURE FILE
a signature file (.SF file) looks similar to the manifest file that's always included in a JAR file when jarsigner is used to sign the file. for each source file included in the JAR file, the .SF file has two lines β just like in the manifest file β that list the following:
- file name
- name of the digest algorithm (
SHA) SHAdigest value
Note: π the name of the digest algorithm (SHA) and theSHAdigest value are on the same line.
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 two lines in the manifest file for the source file. yes, it's hashes all the way down, bestie. π
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 key algorithm used. see the table in Supported Algorithms. π
β° SIGNATURE TIME STAMP
jarsigner used with the following options generates and stores a signature time stamp when signing a JAR file:
-tsaurl-tsacertalias-tsapolicyidpolicyid-tsadigestalgalgorithm
see Options for jarsigner. π°οΈ
π JAR FILE VERIFICATION
a successful JAR file verification happens 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. iconic behaviour only. β
JAR file verification involves the following steps:
- Verify the signature of the
.SFfile. ποΈ
the verification ensures that the signature stored in each signature block file was generated using the private key corresponding to the public key whose certificate (or certificate chain) also appears in the signature block file. it also ensures that the signature is a valid signature of the corresponding signature (.SF) file β and therefore that the .SF file wasn't tampered with. π
- 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 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. π
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 stored in the .SF file header might not equal the hash of the current manifest file is that it might contain sections for newly added files added after the file was signed. for example: suppose one or more files were added to the signed JAR file (using the jar tool) that already contains a signature and a .SF file. if the JAR file is signed again by a different signer, then the manifest file is changed (sections are added to it for the new files by the jarsigner tool) and a new .SF file is created β but the original .SF file is unchanged. a verification is still considered successful if none of the files that were in the JAR file when the original signature was generated have been changed since then. this is because the hashes in the non-header sections of the .SF file equal the hashes of the corresponding sections in the manifest file. π€―
- 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. π¨
- Check for disabled algorithm usage. see Supported Algorithms. π«
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 this, fr fr.
π― MULTIPLE SIGNATURES FOR A JAR FILE
a JAR file can be signed by multiple people β just run jarsigner on the file multiple times and specify the alias for a different person each time, like this:
jarsigner myBundle.jar susan
jarsigner myBundle.jar kevin
when a JAR file is signed multiple times, there are multiple .SF and signature block 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.RSA
KEVIN.SF
KEVIN.RSA
βοΈ OPTIONS FOR JARSIGNER
the following sections describe the options for jarsigner. but first, be aware of the following standards, bestie:
- all option names are preceded by a hyphen 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 aren't 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 doesn't exist, or if you want to use one other than the default. π
a keystore isn't 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. π΅οΈββοΈ
Okay so, about the -keystore argument: it can be a file name and path specification instead of a URL, and in that case it's treated exactly the same as a file: URL. For example, these two are equivalent, no cap:
-keystore filePathAndName-keystore file:filePathAndName
If the Sun PKCS #11 provider was configured in the java.security security properties file (located in the JDK's $JAVA_HOME/conf/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
-storepass [:env | :file] argumentβ Specifies the password that's required to access the keystore π . This is only needed when signing (not verifying) a JAR file. In that case, if a-storepassoption isn't provided at the command line, then the user is prompted for the password.
If the modifier env or file isn't specified, then the password has the value argument. Otherwise, the password is retrieved like this:
env: Retrieve the password from the environment variable named argument.file: Retrieve the password from the file named argument.
β οΈ Note: the password shouldn't be specified on the command line or in a script unless it's for testing purposes, or you're on a secure system. Bestie, please do not put your password in a script for funsies.
-storetype storetypeβ Specifies the type of keystore to be instantiated β¨. The default keystore type is the one that's 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 PKCS #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.
-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 isn't specified, then the password has the value argument. Otherwise, the password is retrieved like this:
env: Retrieve the password from the environment variable named argument.file: Retrieve the password from the file named argument.
β οΈ Note: the password shouldn't be specified on the command line or in a script unless it's for testing purposes, or you're on a secure system. Same warning, same energy: don't leak the keys, bestie π.
-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 isn't complete π. This can happen when the keystore is located on a hardware token where there isn't enough capacity to hold a complete certificate chain. The file can be a sequence of concatenated X.509 certificates, or a single PKCS#7 formatted data block, either in binary encoding format or in printable encoding format (also known as Base64 encoding) as defined by Internet RFC 1421 Certificate Encoding Standard [http://tools.ietf.org/html/rfc1421].-sigfile fileβ Specifies the base file name to be used for the generated.SFand signature block files π¦. For example, if file isDUKESIGN, then the generated.SFand signature block files are namedDUKESIGN.SFandDUKESIGN.RSA, and placed in theMETA-INFdirectory of the signed JAR file.
The characters in the file must come from the set a-zA-Z0-9_-. Only letters, numbers, underscore, and hyphen characters are allowed. All lowercase characters are converted to uppercase for the .SF and signature block file names.
If no -sigfile option appears on the command line, then the base file name for the .SF and signature block files 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 aren't valid in a signature file name, then each such character is converted to an underscore (_) character to form the file name. Slay, but make it filesystem-safe π
.
-signedjar fileβ Specifies the name of signed JAR file. Literally that's the whole vibe β¨.-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 the Java Security Standard Algorithm Names Specification.
If this option isn't specified, then SHA-384 is used. There must either be a statically installed provider supplying an implementation of the specified algorithm or the user must specify one with the -addprovider or -providerClass options; otherwise, the command will not succeed.
-sigalg algorithmβ Specifies the name of the signature algorithm to use to sign the JAR file π.
This algorithm must be compatible with the private key used to sign the JAR file. If this option isn't specified, then use a default algorithm matching the private key as described in the Supported Algorithms section. There must either be a statically installed provider supplying an implementation of the specified algorithm or you must specify one with the -addprovider or -providerClass option; otherwise, the command doesn't succeed.
For a list of standard signature algorithm names, see the Java Security Standard Algorithm Names Specification.
-verifyβ Verifies a signed JAR file. That's it. That's the whole thing β .-verbose[:suboptions]β When the-verboseoption appears on the command line, it indicates thatjarsigneruses the verbose mode when signing or verifying, with the suboptions determining how much information is shown π. This causes the verbose behavior, which causesjarsignerto output extra information about the progress of the JAR signing or verification. The suboptions can beall,grouped, orsummary.
If the -certs option is also specified, then the default mode (or suboption all) displays each entry as it's being processed, and after that, the certificate information for each signer of the JAR file.
If the -certs and the -verbose:grouped suboptions are specified, then entries with the same signer info are grouped and displayed together with their certificate information.
If -certs and the -verbose:summary suboptions are specified, then entries with the same signer information are grouped and displayed together with their certificate information.
Details about each entry are summarized and displayed as one entry (and more). See Example of Verifying a Signed JAR File and Example of Verification with Certificate Information.
-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 signature block file) that certifies the signer's public key, and if the certificate is an X.509 certificate (an instance of thejava.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.
-revCheckβ This option enables revocation checking of certificates when signing or verifying a JAR file π΅οΈ. Thejarsignercommand attempts to make network connections to fetch OCSP responses and CRLs if the-revCheckoption is specified on the command line. Note that revocation checks are not enabled unless this option is specified. Lowkey important: no-revCheck, no revocation checking, periodt.-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 doesn't require the TSA public key certificate to be present in the keystore.
To generate the time stamp, jarsigner communicates 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. Iconic timestamp behavior, honestly π«Ά.
-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 -tsacert option. No certificate, no timestamp vibes π.
-tsapolicyid policyidβ Specifies the object identifier (OID) that identifies the policy ID to be sent to the TSA server πΈ. If this option isn't 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 like 1.2.3.4, for example.
-tsadigestalg algorithmβ Specifies the message digest algorithm that is used to generate the message imprint to be sent to the TSA server π. If this option isn't specified,SHA-384will be used.
See Supported Algorithms.
For a list of standard message digest algorithm names, see the Java Security Standard Algorithm Names Specification.
-internalsfβ okay so back in the day π΅, when a JAR got signed, the signature block file it spat out also carried a whole encoded copy of the.SFfile (the signature file) it generated. That's so not the vibe anymore. To keep the output JAR from being a chonky mess, the signature block file by default does not include a copy of the.SFfile now. But if-internalsfshows up on the command line? Boom, old behavior is back, bestie. This one's for testing only β in practice, don't use-internalsfbecause it incurs higher overhead. π-sectionsonlyβ if-sectionsonlyis on the command line, then the.SFfile (signature file) generated when a JAR file is signed doesn't include a header containing a hash of the whole manifest file. It only contains the info and hashes related to each individual source file included in the JAR file. See Signature File. π
By default, that header is added, as an optimization. When the header's present, whenever the JAR file is verified, verification can first check whether the hash in the header matches the hash of the whole manifest file. Match? Verification proceeds to the next step, slay. No match? Then it's necessary to do a less optimized verification 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 JAR File Verification. π
The -sectionsonly option is primarily used for testing. It shouldn't be used other than for testing because using it incurs higher overhead. Like, just don't, okay? π«Ά
-protectedβ values can be eithertrueorfalse. Specifytruewhen a password must be specified through a protected authentication path, such as a dedicated PIN reader. Very "main character security" of you. π-providerNameproviderName β 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 Oracle PKCS #11 provider, providerName is of the form SunPKCS11-TokenName, where TokenName is 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 the PKCS #11 keystore provider instance with name suffix SmartCard:
jarsigner -keystore NONE -storetype PKCS11 -providerName SunPKCS11-SmartCard -list
-addprovidername [-providerArgarg] β adds a security provider by name (such asSunPKCS11) and an optional configure argument. The value of the security provider is the name of a security provider that is defined in a module. β¨
Used with the -providerArg ConfigFilePath option, the keytool and jarsigner tools install the provider dynamically and use ConfigFilePath for the path to the token configuration file. The following example shows a command to list a PKCS #11 keystore when the Oracle PKCS #11 provider wasn't configured in the security properties file:
jarsigner -keystore NONE -storetype PKCS11 -addprovider SunPKCS11 -providerArg /mydir1/mydir2/token.config
-providerClassprovider-class-name [-providerArgarg] β used to specify the name of a cryptographic service provider's master class file when the service provider isn't listed in thejava.securitysecurity properties file. Adds a security provider by fully-qualified class name and an optional configure argument. π§©
Note: the preferred way to load PKCS11 is by using modules. See -addprovider. (Like, that's the glow-up version, fr fr.)
-providerPathclasspath β used to specify the classpath for providers specified by the-providerClassoption. Multiple paths should be separated by the system-dependent path-separator character. π€οΈ-Jjavaoptionβ passes through the specified javaoption string directly to the Java interpreter. Thejarsignercommand is a wrapper around the interpreter. This option shouldn't contain any spaces. It's useful for adjusting the execution environment or memory usage. For a list of possible interpreter options, typejava -horjava -Xat the command line. π»-strictβ during the signing or verifying process, the command may issue warning messages. If you specify this option, the exit code of the tool reflects the severe warning messages that this command found. See Errors and Warnings. β οΈ-confurl β specifies a pre-configured options file. Read thekeytooldocumentation for details. The property keys supported are"jarsigner.all"for all actions,"jarsigner.sign"for signing, and"jarsigner.verify"for verification.jarsignerarguments including the JAR file name and alias name(s) cannot be set in this file. π-versionβ prints the program version. That's it, that's the whole job. π
π ERRORS AND WARNINGS π
During the signing or verifying process, the jarsigner command may issue various errors or warnings. Buckle up, bestie.
If there is a failure, the jarsigner command exits with code 1. If there is 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 the -strict is specified. If there is 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.
Note: Exit codes are reused because only the values from0to255are legal on Linux and macOS. Budget constraints, honestly. π
The following sections describes 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 aren't 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 day all around.
failureβ Code1. The signing or verifying fails. F in the chat. π
π₯ SEVERE WARNINGS π₯
Note: severe warnings are reported as errors if you specify the -strict option. π
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. She's past her prime, bestie. πhasExpiredTsaCertβ Code4. The timestamp has expired.notYetValidCertβ Code4. This JAR contains entries whose signer certificate isn't yet valid. Baby's not ready yet. πΌchainNotValidatedβ Code4. This JAR contains entries whose certificate chain isn't validated.tsaChainNotValidatedβ Code64. The timestamp is invalid.signerSelfSignedβ Code4. This JAR contains entries whose signer certificate is self signed. She vetted herself, icon behavior honestly, but also not validated. πdisabledAlgβ Code4. An algorithm used is considered a security risk and is disabled. Hard no.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. Not the vibe.hasUnsignedEntryβ Code16. This JAR contains unsigned entries which haven't been integrity-checked. Ma'am, who let you in? πͺnotSignedByAliasβ Code32. This JAR contains signed entries which aren't signed by the specified alias(es).aliasNotInStoreβ Code32. This JAR contains signed entries that aren't signed by alias in this keystore.tsaChainNotValidatedβ Code64. This JAR contains entries whose TSA certificate chain is invalid.
πΈ INFORMATIONAL WARNINGS πΈ
Informational warnings include those that aren't errors but regarded as bad practice. They don't have a code. (No code, no drama β well, some drama.)
extraAttributesDetectedβ the POSIX file permissions and/or symlink attributes are detected during signing or verifying a JAR file. Thejarsignertool preserves these attributes in the newly signed file but warns that these attributes are unsigned and not protected by the signature. πhasExpiringCertβ this JAR contains entries whose signer certificate expires within six months. Tick tock, bestie. β°hasExpiringTsaCertβ the timestamp will expire within one year on YYYY-MM-DD.legacyAlgβ an algorithm used is considered a security risk but not disabled. She's on thin ice. π§noTimestampβ this JAR contains signatures that doesn't 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.
π EXAMPLE OF SIGNING 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 is no -sigfile specified in the previous command so the generated .SF and signature block files to be placed in the signed JAR file have default names based on the alias name. They are named JANE.SF and JANE.RSA. Cute, right? π
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 don't need to specify a keystore, as follows:
jarsigner -signedjar sbundle.jar bundle.jar jane
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
Look at you go. Signed and slayed. π
β¨ EXAMPLE OF VERIFYING A SIGNED JAR FILE β¨
okay bestie, so youβve got a signed JAR and you need to make sure the signature is valid and nobody tampered with it? say less. run something like this:
jarsigner -verify ButtonDemo.jar
if 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 ButtonDemo.jar
s 866 Tue Sep 12 20:08:48 EDT 2017 META-INF/MANIFEST.MF
825 Tue Sep 12 20:08:48 EDT 2017 META-INF/ORACLE_C.SF
7475 Tue Sep 12 20:08:48 EDT 2017 META-INF/ORACLE_C.RSA
0 Tue Sep 12 20:07:54 EDT 2017 META-INF/
0 Tue Sep 12 20:07:16 EDT 2017 components/
0 Tue Sep 12 20:07:16 EDT 2017 components/images/
sm 523 Tue Sep 12 20:07:16 EDT 2017 components/ButtonDemo$1.class
sm 3440 Tue Sep 12 20:07:16 EDT 2017 components/ButtonDemo.class
sm 2346 Tue Sep 12 20:07:16 EDT 2017 components/ButtonDemo.jnlp
sm 172 Tue Sep 12 20:07:16 EDT 2017 components/images/left.gif
sm 235 Tue Sep 12 20:07:16 EDT 2017 components/images/middle.gif
sm 172 Tue Sep 12 20:07:16 EDT 2017 components/images/right.gif
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
- Signed by "CN="Oracle America, Inc.", OU=Software Engineering, O="Oracle America, Inc.", L=Redwood City, ST=California, C=US"
Digest algorithm: SHA-256
Signature algorithm: SHA256withRSA, 2048-bit key
Timestamped by "CN=Symantec Time Stamping Services Signer - G4, O=Symantec Corporation, C=US" on Tue Sep 12 20:08:49 UTC 2017
Timestamp digest algorithm: SHA-1
Timestamp signature algorithm: SHA1withRSA, 2048-bit key
jar verified.
The signer certificate expired on 2018-02-01. However, the JAR will be valid until the timestamp expires on 2020-12-29.
π EXAMPLE OF VERIFICATION WITH CERTIFICATE INFORMATION π
if you specify the -certs option with the -verify and -verbose options, then the output includes certificate information for each signer of the JAR file. the information includes the certificate type, the signer distinguished name information (when it is 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 $JAVA_HOME/lib/security/cacerts -verify -verbose -certs ButtonDemo.jar
and the output is giving:
s k 866 Tue Sep 12 20:08:48 EDT 2017 META-INF/MANIFEST.MF
>>> Signer
X.509, CN="Oracle America, Inc.", OU=Software Engineering, O="Oracle America, Inc.", L=Redwood City, ST=California, C=US
[certificate is valid from 2017-01-30, 7:00 PM to 2018-02-01, 6:59 PM]
X.509, CN=Symantec Class 3 SHA256 Code Signing CA, OU=Symantec Trust Network, O=Symantec Corporation, C=US
[certificate is valid from 2013-12-09, 7:00 PM to 2023-12-09, 6:59 PM]
X.509, CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU="(c) 2006 VeriSign, Inc. - For authorized use only", OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US (verisignclass3g5ca [jdk])
[trusted certificate]
>>> TSA
X.509, CN=Symantec Time Stamping Services Signer - G4, O=Symantec Corporation, C=US
[certificate is valid from 2012-10-17, 8:00 PM to 2020-12-29, 6:59 PM]
X.509, CN=Symantec Time Stamping Services CA - G2, O=Symantec Corporation, C=US
[certificate is valid from 2012-12-20, 7:00 PM to 2020-12-30, 6:59 PM]
825 Tue Sep 12 20:08:48 EDT 2017 META-INF/ORACLE_C.SF
7475 Tue Sep 12 20:08:48 EDT 2017 META-INF/ORACLE_C.RSA
0 Tue Sep 12 20:07:54 EDT 2017 META-INF/
0 Tue Sep 12 20:07:16 EDT 2017 components/
0 Tue Sep 12 20:07:16 EDT 2017 components/images/
smk 523 Tue Sep 12 20:07:16 EDT 2017 components/ButtonDemo$1.class
[entry was signed on 2017-09-12, 4:08 PM]
>>> Signer
X.509, CN="Oracle America, Inc.", OU=Software Engineering, O="Oracle America, Inc.", L=Redwood City, ST=California, C=US
[certificate is valid from 2017-01-30, 7:00 PM to 2018-02-01, 6:59 PM]
X.509, CN=Symantec Class 3 SHA256 Code Signing CA, OU=Symantec Trust Network, O=Symantec Corporation, C=US
[certificate is valid from 2013-12-09, 7:00 PM to 2023-12-09, 6:59 PM]
X.509, CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU="(c) 2006 VeriSign, Inc. - For authorized use only", OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US (verisignclass3g5ca [jdk])
[trusted certificate]
>>> TSA
X.509, CN=Symantec Time Stamping Services Signer - G4, O=Symantec Corporation, C=US
[certificate is valid from 2012-10-17, 8:00 PM to 2020-12-29, 6:59 PM]
X.509, CN=Symantec Time Stamping Services CA - G2, O=Symantec Corporation, C=US
[certificate is valid from 2012-12-20, 7:00 PM to 2020-12-30, 6:59 PM]
smk 3440 Tue Sep 12 20:07:16 EDT 2017 components/ButtonDemo.class
...
smk 2346 Tue Sep 12 20:07:16 EDT 2017 components/ButtonDemo.jnlp
...
smk 172 Tue Sep 12 20:07:16 EDT 2017 components/images/left.gif
...
smk 235 Tue Sep 12 20:07:16 EDT 2017 components/images/middle.gif
...
smk 172 Tue Sep 12 20:07:16 EDT 2017 components/images/right.gif
...
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
- Signed by "CN="Oracle America, Inc.", OU=Software Engineering, O="Oracle America, Inc.", L=Redwood City, ST=California, C=US"
Digest algorithm: SHA-256
Signature algorithm: SHA256withRSA, 2048-bit key
Timestamped by "CN=Symantec Time Stamping Services Signer - G4, O=Symantec Corporation, C=US" on Tue Sep 12 20:08:49 UTC 2017
Timestamp digest algorithm: SHA-1
Timestamp signature algorithm: SHA1withRSA, 2048-bit key
jar verified.
The signer certificate expired on 2018-02-01. However, the JAR will be valid until the timestamp expires on 2020-12-29.
if the certificate for a signer isnβt an X.509 certificate, then there is 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).
later, bestie! this page is from JDK 23, dated 2024, and itβs the JARSIGNER(1) man page β iconic, honestly. π
β¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: java-23-openjdk-devel 23.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-23-openjdk-devel 23.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-23-openjdk-devel 23.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-23-openjdk-devel 23.0.2.0-160000.1.1 Β· Apache-1.1 AND Apache-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND SUSE-Public-Domain AND W3C
- Copyright (c) 1998, 2023, 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