APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.security.tools.jarsigner

public Class Main

extends Object
Class Inheritance
Imports
java.io.*, java.net.UnknownHostException, .URLClassLoader, .URI, .SocketTimeoutException, .URL, java.nio.file.Files, .Path, java.security.cert.CertPathValidatorException, .PKIXBuilderParameters, .Certificate, .X509Certificate, .CertificateException, .CertPath, .CertificateExpiredException, .CertificateFactory, .CertificateNotYetValidException, .TrustAnchor, java.security.spec.ECParameterSpec, .NamedParameterSpec, java.util.*, .Map.Entry, java.util.stream.Collectors, java.util.zip.*, java.util.jar.*, java.text.Collator, .MessageFormat, java.security.*, jdk.internal.access.JavaUtilZipFileAccess, .SharedSecrets, jdk.security.jarsigner.JarSigner, .JarSignerException, sun.security.pkcs.PKCS7, .SignerInfo, sun.security.provider.certpath.CertPathConstraintsParameters, sun.security.timestamp.TimestampToken, sun.security.tools.KeyStoreUtil, .PathList, sun.security.validator.Validator, .ValidatorException, sun.security.x509.*, sun.security.util.*

The jarsigner utility. The exit codes for the main method are: 0: success 1: any error that the jar cannot be signed or verified, including: keystore loading error TSP communication error jarsigner command line error... otherwise: error codes from -strict

Authors
Roland Schemers, Jan Luehe

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv String
private boolean
private boolean
pack-priv String
private boolean
private boolean
private boolean
private Map<CodeSigner, Integer>
pack-priv Map<CodeSigner, String>
pack-priv X509Certificate[]
private static final DisabledAlgorithmConstraints
private boolean
private Throwable
pack-priv List<String>
private static final Collator
private List<String>
pack-priv boolean
private static final Set<CryptoPrimitive>
pack-priv String
private int
private boolean
private Date
private static MessageFormat
private static MessageFormat
private static boolean
pack-priv boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
pack-priv boolean
private boolean
pack-priv static final int
private static final DisabledAlgorithmConstraints
pack-priv String
pack-priv static final JavaUtilZipFileAccess
pack-priv char[]
pack-priv String
private static final DisabledAlgorithmConstraints
private int
private String
private String
private String
private static final String
pack-priv static final int
private boolean
private boolean
private static MessageFormat
private boolean
pack-priv boolean
private static final long
private static final String
pack-priv String
pack-priv PKIXBuilderParameters
pack-priv PrivateKey
pack-priv boolean
pack-priv HashMap<String, String>
pack-priv List<String>
pack-priv String
pack-priv List<String>
private static final ResourceBundle
pack-priv String
pack-priv boolean
pack-priv boolean
private static final Set<CryptoPrimitive>
pack-priv String
pack-priv String
pack-priv static final int
pack-priv String
private boolean
pack-priv boolean
private static MessageFormat
private static final long
pack-priv static final int
pack-priv KeyStore
pack-priv Hashtable<Certificate, String>
storeHash

Maps certificates (as keys) to alias names associated in the keystore keystore (as values).

pack-priv char[]
pack-priv String
pack-priv boolean
pack-priv boolean
pack-priv Set<X509Certificate>
pack-priv String
private boolean
private Throwable
pack-priv String
private Date
pack-priv String
pack-priv String
private static MessageFormat
pack-priv String
pack-priv boolean
pack-priv static final String
pack-priv boolean
private boolean
private PublicKey
private ZipFile

Constructor Summary

AccessConstructor and Description
public
Main()

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

the info as a string
certsAndTSInfo
(String
spaces before the ">>> Signer" line
tab1
,
String
spaces before the other lines
tab2
,
List<? extends Certificate>
the signer cert
certs
,
Timestamp
the timestamp, can be null
ts
)

Fills info on certs and timestamp into a StringBuilder, sets warning flags (through printCert) and validates cert chains.

pack-priv void
checkCertUsage(X509Certificate
the certificate to be examined
userCert
,
boolean[]
3 booleans to show if the KeyUsage, ExtendedKeyUsage, NetscapeCertType has codeSigning flag turned on. If null, the class field badKeyUsage, badExtendedKeyUsage, badNetscapeCertType will be set.
bad
)

Check if userCert is designed to be a code signer

private static String
private static String
private void
checkWeakSign(String alg, Set<CryptoPrimitive> primitiveSet, boolean tsa, JarConstraintsParameters jcp)

private void
private void
compareManifest(Manifest cenManifest, Manifest locManifest)

private void
compareSigners(JarEntry cenEntry, JarEntry locEntry)

private void
private void
private void
displayMessagesAndResult(boolean isSigning)

pack-priv static void
pack-priv void
error(String message)

pack-priv void
error(String message, Throwable e)

private TrustAnchor
private static String

Returns:

the full name
fullDisplayKeyName
(Key
the key object, cannot be null
key
)

Returns the full display name of the given key object.

pack-priv static void
pack-priv void
pack-priv static char[]
getPass(String modifier, String arg)

pack-priv char[]
getPass(String prompt)

pack-priv X509Certificate
pack-priv int
private int
pack-priv void
loadKeyStore(String keyStoreName, boolean prompt)

public static void
main(String[] args)

pack-priv String[]
parseArgs(String[] args)

pack-priv String
printCert(boolean
true if c is in the TSA cert chain, false otherwise.
isTsCert
,
String tab, Certificate c, Date timestamp, boolean
true to check code signer keyUsage
checkUsage
,
CertPathConstraintsParameters cpcp)

Returns a string about a certificate: [<tab>] <cert-type> [", " <subject-dn>] [" (" <keystore-entry-alias> ")"] [<validity-period> | <expiry-warning>] [<key-usage-warning>] Note: no newline character at the end.

private String
private void
public int
run(String[] args)

private boolean
signatureRelated(String name)

signature-related files include: .

private String
signerInfo(CodeSigner signer, String tab)

Returns a string of signer info, with a newline at the end.

pack-priv void
signJar(String jarName, String alias)

pack-priv static void
pack-priv static void
pack-priv void
validateCertChain(String variant, List<? extends Certificate> certs, Timestamp
this might be a timestamp
parameter
)

Validates a cert chain.

pack-priv void
verifyJar(String jarName)

private String
verifyWithWeak(String alg, Set<CryptoPrimitive> primitiveSet, boolean tsa, JarConstraintsParameters jcp, AlgorithmParameters algParams)

private String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aliasback to summary
pack-priv String alias
aliasNotInStoreback to summary
private boolean aliasNotInStore
allAliasesFoundback to summary
private boolean allAliasesFound
altCertChainback to summary
pack-priv String altCertChain
badExtendedKeyUsageback to summary
private boolean badExtendedKeyUsage
badKeyUsageback to summary
private boolean badKeyUsage
badNetscapeCertTypeback to summary
private boolean badNetscapeCertType
cacheForInKSback to summary
private Map<CodeSigner, Integer> cacheForInKS
cacheForSignerInfoback to summary
pack-priv Map<CodeSigner, String> cacheForSignerInfo
certChainback to summary
pack-priv X509Certificate[] certChain
CERTPATH_DISABLED_CHECKback to summary
private static final DisabledAlgorithmConstraints CERTPATH_DISABLED_CHECK
chainNotValidatedback to summary
private boolean chainNotValidated
chainNotValidatedReasonback to summary
private Throwable chainNotValidatedReason
ckaliasesback to summary
pack-priv List<String> ckaliases
collatorback to summary
private static final Collator collator
crossChkWarningsback to summary
private List<String> crossChkWarnings
debugback to summary
pack-priv boolean debug
DIGEST_PRIMITIVE_SETback to summary
private static final Set<CryptoPrimitive> DIGEST_PRIMITIVE_SET
digestalgback to summary
pack-priv String digestalg
disabledAlgback to summary
private int disabledAlg
disabledAlgFoundback to summary
private boolean disabledAlgFound
expireDateback to summary
private Date expireDate
expiredTimeFormback to summary
private static MessageFormat expiredTimeForm
expiringTimeFormback to summary
private static MessageFormat expiringTimeForm
externalFileAttributesDetectedback to summary
private static boolean externalFileAttributesDetected
externalSFback to summary
pack-priv boolean externalSF
hasExpiredCertback to summary
private boolean hasExpiredCert
hasExpiredTsaCertback to summary
private boolean hasExpiredTsaCert
hasExpiringCertback to summary
private boolean hasExpiringCert
hasExpiringTsaCertback to summary
private boolean hasExpiringTsaCert
hasMultipleManifestsback to summary
private boolean hasMultipleManifests
hasNonexistentEntriesback to summary
private boolean hasNonexistentEntries
hasTimestampBlockback to summary
pack-priv boolean hasTimestampBlock
hasUnsignedEntryback to summary
private boolean hasUnsignedEntry
IN_KEYSTOREback to summary
pack-priv static final int IN_KEYSTORE
JAR_DISABLED_CHECKback to summary
private static final DisabledAlgorithmConstraints JAR_DISABLED_CHECK
jarfileback to summary
pack-priv String jarfile
JUZFAback to summary
pack-priv static final JavaUtilZipFileAccess JUZFA
keypassback to summary
pack-priv char[] keypass
keystoreback to summary
pack-priv String keystore
LEGACY_CHECKback to summary
private static final DisabledAlgorithmConstraints LEGACY_CHECK
legacyAlgback to summary
private int legacyAlg
legacyDigestAlgback to summary
private String legacyDigestAlg
legacySigAlgback to summary
private String legacySigAlg
legacyTsaDigestAlgback to summary
private String legacyTsaDigestAlg
NONEback to summary
private static final String NONE
NOT_ALIASback to summary
pack-priv static final int NOT_ALIAS
noTimestampback to summary
private boolean noTimestamp
notSignedByAliasback to summary
private boolean notSignedByAlias
notYetTimeFormback to summary
private static MessageFormat notYetTimeForm
notYetValidCertback to summary
private boolean notYetValidCert
nullStreamback to summary
pack-priv boolean nullStream
ONE_YEARback to summary
private static final long ONE_YEAR
P11KEYSTOREback to summary
private static final String P11KEYSTORE
pathlistback to summary
pack-priv String pathlist
pkixParametersback to summary
pack-priv PKIXBuilderParameters pkixParameters
privateKeyback to summary
pack-priv PrivateKey privateKey
protectedPathback to summary
pack-priv boolean protectedPath
providerArgsback to summary
pack-priv HashMap<String, String> providerArgs
providerClassesback to summary
pack-priv List<String> providerClasses
providerNameback to summary
pack-priv String providerName
providersback to summary
pack-priv List<String> providers
rbback to summary
private static final ResourceBundle rb
realStoreTypeback to summary
pack-priv String realStoreType
revocationCheckback to summary
pack-priv boolean revocationCheck
showcertsback to summary
pack-priv boolean showcerts
SIG_PRIMITIVE_SETback to summary
private static final Set<CryptoPrimitive> SIG_PRIMITIVE_SET
sigalgback to summary
pack-priv String sigalg
sigfileback to summary
pack-priv String sigfile
SIGNED_BY_ALIASback to summary
pack-priv static final int SIGNED_BY_ALIAS
signedjarback to summary
pack-priv String signedjar
signerSelfSignedback to summary
private boolean signerSelfSigned
signManifestback to summary
pack-priv boolean signManifest
signTimeFormback to summary
private static MessageFormat signTimeForm
SIX_MONTHSback to summary
private static final long SIX_MONTHS
SOME_ALIASES_NOT_FOUNDback to summary
pack-priv static final int SOME_ALIASES_NOT_FOUND
storeback to summary
pack-priv KeyStore store
storeHashback to summary
pack-priv Hashtable<Certificate, String> storeHash

Maps certificates (as keys) to alias names associated in the keystore keystore (as values).

storepassback to summary
pack-priv char[] storepass
storetypeback to summary
pack-priv String storetype
strictback to summary
pack-priv boolean strict
tokenback to summary
pack-priv boolean token
trustedCertsback to summary
pack-priv Set<X509Certificate> trustedCerts
tsaAliasback to summary
pack-priv String tsaAlias
tsaChainNotValidatedback to summary
private boolean tsaChainNotValidated
tsaChainNotValidatedReasonback to summary
private Throwable tsaChainNotValidatedReason
tSADigestAlgback to summary
pack-priv String tSADigestAlg
tsaExpireDateback to summary
private Date tsaExpireDate
tSAPolicyIDback to summary
pack-priv String tSAPolicyID
tsaUrlback to summary
pack-priv String tsaUrl
validityTimeFormback to summary
private static MessageFormat validityTimeForm
verboseback to summary
pack-priv String verbose
verifyback to summary
pack-priv boolean verify
VERSIONback to summary
pack-priv static final String VERSION
versionback to summary
pack-priv boolean version
weakKeyStoreback to summary
private boolean weakKeyStore
weakPublicKeyback to summary
private PublicKey weakPublicKey
zipFileback to summary
private ZipFile zipFile

Constructor Detail

Mainback to summary
public Main()

Method Detail

certsAndTSInfoback to summary
private String certsAndTSInfo(String tab1, String tab2, List<? extends Certificate> certs, Timestamp ts) throws Exception

Fills info on certs and timestamp into a StringBuilder, sets warning flags (through printCert) and validates cert chains.

Parameters
tab1:String

spaces before the ">>> Signer" line

tab2:String

spaces before the other lines

certs:List<? extends Certificate>

the signer cert

ts:Timestamp

the timestamp, can be null

Returns:String

the info as a string

checkCertUsageback to summary
pack-priv void checkCertUsage(X509Certificate userCert, boolean[] bad)

Check if userCert is designed to be a code signer

Parameters
userCert:X509Certificate

the certificate to be examined

bad:boolean[]

3 booleans to show if the KeyUsage, ExtendedKeyUsage, NetscapeCertType has codeSigning flag turned on. If null, the class field badKeyUsage, badExtendedKeyUsage, badNetscapeCertType will be set.

checkWeakAlgback to summary
private static String checkWeakAlg(String alg, CertPathConstraintsParameters cpcp)
checkWeakKeyback to summary
private static String checkWeakKey(PublicKey key, CertPathConstraintsParameters cpcp)
checkWeakSignback to summary
private void checkWeakSign(String alg, Set<CryptoPrimitive> primitiveSet, boolean tsa, JarConstraintsParameters jcp)
checkWeakSignback to summary
private void checkWeakSign(PrivateKey key, JarConstraintsParameters jcp)
compareManifestback to summary
private void compareManifest(Manifest cenManifest, Manifest locManifest)
compareSignersback to summary
private void compareSigners(JarEntry cenEntry, JarEntry locEntry)
crossCheckEntriesback to summary
private void crossCheckEntries(String jarName) throws Exception
displayCrossChkWarningsback to summary
private void displayCrossChkWarnings()
displayMessagesAndResultback to summary
private void displayMessagesAndResult(boolean isSigning)
doPrintVersionback to summary
pack-priv static void doPrintVersion()
errorback to summary
pack-priv void error(String message)
errorback to summary
pack-priv void error(String message, Throwable e)
findTrustAnchorback to summary
private TrustAnchor findTrustAnchor(List<X509Certificate> chain)
fullDisplayKeyNameback to summary
private static String fullDisplayKeyName(Key key)

Returns the full display name of the given key object. Could be - "X25519", if its getParams() is NamedParameterSpec - "EC (secp256r1)", if it's an EC key - "1024-bit RSA", other known keys - plain algorithm name, otherwise Note: the same method appears in keytool and jarsigner which uses same resource string defined in their own Resources.java.

Parameters
key:Key

the key object, cannot be null

Returns:String

the full name

fullusageback to summary
pack-priv static void fullusage()
getAliasInfoback to summary
pack-priv void getAliasInfo(String alias) throws Exception
getPassback to summary
pack-priv static char[] getPass(String modifier, String arg)
getPassback to summary
pack-priv char[] getPass(String prompt)
getTsaCertback to summary
pack-priv X509Certificate getTsaCert(String alias)
inKeyStoreback to summary
pack-priv int inKeyStore(CodeSigner[] signers)
inKeyStoreForOneSignerback to summary
private int inKeyStoreForOneSigner(CodeSigner signer)
loadKeyStoreback to summary
pack-priv void loadKeyStore(String keyStoreName, boolean prompt)
mainback to summary
public static void main(String[] args) throws Exception
parseArgsback to summary
pack-priv String[] parseArgs(String[] args) throws Exception
printCertback to summary
pack-priv String printCert(boolean isTsCert, String tab, Certificate c, Date timestamp, boolean checkUsage, CertPathConstraintsParameters cpcp) throws Exception

Returns a string about a certificate: [] [", " ] [" (" ")"] [ | ] [] Note: no newline character at the end. This method sets global flags like hasExpiringCert, hasExpiredCert, notYetValidCert, badKeyUsage, badExtendedKeyUsage, badNetscapeCertType, hasExpiringTsaCert, hasExpiredTsaCert.

Parameters
isTsCert:boolean

true if c is in the TSA cert chain, false otherwise.

checkUsage:boolean

true to check code signer keyUsage

printTimestampback to summary
private String printTimestamp(String tab, Timestamp timestamp)
readEntryback to summary
private void readEntry(InputStream is) throws IOException
runback to summary
public int run(String[] args)
signatureRelatedback to summary
private boolean signatureRelated(String name)

signature-related files include: . META-INF/MANIFEST.MF . META-INF/SIG-* . META-INF/*.SF . META-INF/*.DSA . META-INF/*.RSA . META-INF/*.EC

signerInfoback to summary
private String signerInfo(CodeSigner signer, String tab) throws Exception

Returns a string of signer info, with a newline at the end. Called by verifyJar().

signJarback to summary
pack-priv void signJar(String jarName, String alias) throws Exception
usageback to summary
pack-priv static void usage()
usageNoArgback to summary
pack-priv static void usageNoArg()
validateCertChainback to summary
pack-priv void validateCertChain(String variant, List<? extends Certificate> certs, Timestamp parameter) throws Exception

Validates a cert chain.

Parameters
parameter:Timestamp

this might be a timestamp

verifyJarback to summary
pack-priv void verifyJar(String jarName) throws Exception
verifyWithWeakback to summary
private String verifyWithWeak(String alg, Set<CryptoPrimitive> primitiveSet, boolean tsa, JarConstraintsParameters jcp, AlgorithmParameters algParams)
verifyWithWeakback to summary
private String verifyWithWeak(PublicKey key, JarConstraintsParameters jcp)
sun.security.tools.jarsigner back to summary

private Class Main.ExitException

extends RuntimeException
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
pack-priv static final long

Constructor Summary

AccessConstructor and Description
public
ExitException(int errorCode)

Field Detail

errorCodeback to summary
private final int errorCode
serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Annotations
@Serial

Constructor Detail

ExitExceptionback to summary
public ExitException(int errorCode)