Class SignJar
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.AbstractJarSignerTask
org.apache.tools.ant.taskdefs.SignJar
- All Implemented Interfaces:
Cloneable
Signs JAR or ZIP files with the javasign command line tool. The tool detailed
dependency checking: files are only signed if they are not signed. The
signjar attribute can point to the file to generate; if this file
exists then its modification date is used as a cue as to whether to resign
any JAR file.
Timestamp signature support is based on Java 8- Since:
- Ant 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Filethe output directory when using paths.static final Stringerror string for unit test verification: "Cannot map source file to anything sensible: "static final Stringerror string for unit test verification: "The destDir attribute is required if a mapper is set"static final Stringerror string for unit test verification: "alias attribute must be set"static final Stringerror string for unit test verification: "storepass attribute must be set"static final Stringerror string for unit test verification "You cannot specify the signed JAR when using paths or filesets"static final Stringerror string for unit test verification: "\'destdir\' and \'signedjar\' cannot both be set"static final Stringerror string for unit test verification: "Too many mappers"protected booleanflag for internal sf signingprotected booleanWhether to assume a jar which has an appropriate .SF file in is already signed.protected booleansign sections only?protected Stringname to a signature fileprotected Filename of a single jarprotected Stringalias for the TSA in the keystoreprotected StringProxy host to be used when connecting to TSA serverprotected StringProxy port to be used when connecting to TSA serverprotected StringURL for a tsa; null implies no tsa supportFields inherited from class AbstractJarSignerTask
alias, ERROR_NO_SOURCE, filesets, jar, JARSIGNER_COMMAND, keypass, keystore, maxMemory, storepass, storetype, strict, verboseModifier and TypeFieldDescriptionprotected StringThe alias of signer.static final Stringerror string for unit test verification: "jar must be set through jar attribute or nested filesets"the filesets of the jars to signprotected FileThe name of the jar file.protected static final Stringname of JDK program we are looking forprotected Stringpassword for the key in the storeprotected StringThe url or path of keystore file.protected StringThe maximum amount of memory to use for Jar signerprotected Stringpassword for the storeprotected Stringtype of store,-storetype paramprotected booleanstrict checkingprotected booleanverbose outputFields inherited from class ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(FileNameMapper newMapper) add a mapper to determine file naming policy.voidexecute()sign the jar(s)Digest Algorithm; optionalget the active mapper; may be nullSignature Algorithm; optionalget the -tsacert optionTSA Digest Algorithm; optionalGet the proxy host to be used when connecting to the TSA urlGet the proxy host to be used when connecting to the TSA urlget the -tsaurl urlbooleanisForce()Should the task force signing of a jar even it is already signed?protected booleantest for a file being signed, by looking for a signature in the META-INF directory with our alias/sigfile.protected booleanisUpToDate(File jarFile, File signedjarFile) Compare a jar file with its corresponding signed jar.voidsetDestDir(File destDir) Optionally sets the output directory to be used.voidsetDigestAlg(String digestAlg) Digest Algorithm; optionalvoidsetForce(boolean b) Whether to force signing of a jar even it is already signed.voidsetInternalsf(boolean internalsf) Flag to include the .SF file inside the signature; optional; default falsevoidsetLazy(boolean lazy) flag to control whether the presence of a signature file means a JAR is signed; optional, default falsevoidsetPreserveLastModified(boolean preserveLastModified) true to indicate that the signed jar modification date remains the same as the original.voidsetSectionsonly(boolean sectionsonly) flag to compute hash of entire manifest; optional, default falsevoidSignature Algorithm; optionalvoidsetSigfile(String sigfile) name of .SF/.DSA file; optionalvoidsetSignedjar(File signedjar) name of signed JAR file; optionalvoidsetTsacert(String tsacert) set the alias in the keystore of the TSA to use;voidsetTSADigestAlg(String digestAlg) TSA Digest Algorithm; optionalvoidsetTsaproxyhost(String tsaproxyhost) voidsetTsaproxyport(String tsaproxyport) voidMethods inherited from class AbstractJarSignerTask
addArg, addArgument, addFileset, addSysproperty, addValue, beginExecution, bindToKeystore, createJarSigner, createPath, createUnifiedSourcePath, createUnifiedSources, declareSysProperty, endExecution, getRedirector, hasResources, setAlias, setCommonOptions, setExecutable, setJar, setKeypass, setKeystore, setMaxmemory, setProviderArg, setProviderClass, setProviderName, setStorepass, setStoretype, setStrict, setVerboseModifier and TypeMethodDescriptionvoidAdds a nested <arg> element that can be used to specify command line arguments not supported via specific attributes.protected voidaddArgument(ExecTask cmd, Commandline.Argument arg) add an argument to a commandvoidaddFileset(FileSet set) Adds a set of files to signvoidAdd a system property.protected voidadd a value argument to a commandprotected voidinit processing logic; this is retained through our execution(s)protected voidbindToKeystore(ExecTask cmd) bind to a keystore if the attributes are thereprotected ExecTaskcreate the jarsigner executable taskAdds a path of files to sign.protected Pathclone our path and add all explicitly specified FileSets as well, patch in the jar attribute as a new fileset if it is defined.clone our filesets vector, and patch in the jar attribute as a new fileset, if is definedprotected voiddeclareSysProperty(ExecTask cmd, Environment.Variable property) protected voidany cleanup logicget the redirector.protected booleanHas either a path or a fileset been specified?voidthe alias to sign under; requiredprotected voidsetCommonOptions(ExecTask cmd) these are options common to signing and verifyingvoidsetExecutable(String executable) Sets the actual executable command to invoke, instead of the binaryjarsignerfound in Ant's JDK.voidthe jar file to sign; requiredvoidsetKeypass(String keypass) password for private key (if different); optionalvoidsetKeystore(String keystore) keystore location; requiredvoidsetMaxmemory(String max) Set the maximum memory to be used by the jarsigner processvoidsetProviderArg(String providerArg) Sets the value for the -providerArg command line argument.voidsetProviderClass(String providerClass) Sets the value for the -providerClass command line argument.voidsetProviderName(String providerName) Sets the value for the -providerName command line argument.voidsetStorepass(String storepass) password for keystore integrity; requiredvoidsetStoretype(String storetype) keystore type; optionalvoidsetStrict(boolean strict) do strict checkingvoidsetVerbose(boolean verbose) Enable verbose output when signing; optional: default falseMethods inherited from class Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeModifier and TypeMethodDescriptionfinal voidbindToOwner(Task owner) Bind a task to another; use this when configuring a newly created task to do work on behalf of another.Returns the container target of this task.Returns the wrapper used for runtime configuration.Returns the name to use in logging messages.Return the type of task.protected RuntimeConfigurableReturn the runtime configurable structure for this task.protected voidhandleErrorFlush(String output) Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(String output) Handles an error output by logging it with the WARN priority.protected voidhandleFlush(String output) Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length) Handle an input request by this task.protected voidhandleOutput(String output) Handles output by logging it with the INFO priority.voidinit()Called by the project to let the task initialize properly.protected final booleanHas this task been marked invalid?voidLogs a message with the default (INFO) priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidConfigures this task - if it hasn't been done already.final voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidForce the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target) Sets the target container of this task.voidSets the wrapper to be used for runtime configuration.voidsetTaskName(String name) Sets the name to use in logging messages.voidsetTaskType(String type) Sets the name with which the task has been invoked.Methods inherited from class ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProjectModifier and TypeMethodDescriptionclone()Returns the description of the current action.Returns the file/location where this task was defined.Returns the project to which this component belongs.voidsetDescription(String desc) Sets a description of the current action.voidsetLocation(Location location) Sets the file/location where this task was defined.voidsetProject(Project project) Sets the project object of this component.
-
Field Details
-
ERROR_TODIR_AND_SIGNEDJAR
error string for unit test verification: "\'destdir\' and \'signedjar\' cannot both be set"- See Also:
-
ERROR_TOO_MANY_MAPPERS
error string for unit test verification: "Too many mappers"- See Also:
-
ERROR_SIGNEDJAR_AND_PATHS
error string for unit test verification "You cannot specify the signed JAR when using paths or filesets"- See Also:
-
ERROR_BAD_MAP
error string for unit test verification: "Cannot map source file to anything sensible: "- See Also:
-
ERROR_MAPPER_WITHOUT_DEST
error string for unit test verification: "The destDir attribute is required if a mapper is set"- See Also:
-
ERROR_NO_ALIAS
error string for unit test verification: "alias attribute must be set"- See Also:
-
ERROR_NO_STOREPASS
error string for unit test verification: "storepass attribute must be set"- See Also:
-
sigfile
name to a signature file -
signedjar
name of a single jar -
internalsf
protected boolean internalsfflag for internal sf signing -
sectionsonly
protected boolean sectionsonlysign sections only? -
lazy
protected boolean lazyWhether to assume a jar which has an appropriate .SF file in is already signed. -
destDir
the output directory when using paths. -
tsaurl
URL for a tsa; null implies no tsa support -
tsaproxyhost
Proxy host to be used when connecting to TSA server -
tsaproxyport
Proxy port to be used when connecting to TSA server -
tsacert
alias for the TSA in the keystore
-
-
Constructor Details
-
SignJar
public SignJar()
-
-
Method Details
-
setSigfile
name of .SF/.DSA file; optional- Parameters:
sigfile- the name of the .SF/.DSA file
-
setSignedjar
name of signed JAR file; optional- Parameters:
signedjar- the name of the signed jar file
-
setInternalsf
public void setInternalsf(boolean internalsf) Flag to include the .SF file inside the signature; optional; default false- Parameters:
internalsf- if true include the .SF file inside the signature
-
setSectionsonly
public void setSectionsonly(boolean sectionsonly) flag to compute hash of entire manifest; optional, default false- Parameters:
sectionsonly- flag to compute hash of entire manifest
-
setLazy
public void setLazy(boolean lazy) flag to control whether the presence of a signature file means a JAR is signed; optional, default false- Parameters:
lazy- flag to control whether the presence of a signature
-
setDestDir
Optionally sets the output directory to be used.- Parameters:
destDir- the directory in which to place signed jars- Since:
- Ant 1.7
-
add
add a mapper to determine file naming policy. Only used with toDir processing.- Parameters:
newMapper- the mapper to add.- Since:
- Ant 1.7
-
getMapper
get the active mapper; may be null- Returns:
- mapper or null
- Since:
- Ant 1.7
-
getTsaurl
-
setTsaurl
- Parameters:
tsaurl- the tsa url.- Since:
- Ant 1.7
-
getTsaproxyhost
Get the proxy host to be used when connecting to the TSA url- Returns:
- url or null
- Since:
- Ant 1.9.5
-
setTsaproxyhost
- Parameters:
tsaproxyhost- the proxy host to be used when connecting to the TSA.- Since:
- Ant 1.9.5
-
getTsaproxyport
Get the proxy host to be used when connecting to the TSA url- Returns:
- url or null
- Since:
- Ant 1.9.5
-
setTsaproxyport
- Parameters:
tsaproxyport- the proxy port to be used when connecting to the TSA.- Since:
- Ant 1.9.5
-
getTsacert
get the -tsacert option- Returns:
- a certificate alias or null
- Since:
- Ant 1.7
-
setTsacert
set the alias in the keystore of the TSA to use;- Parameters:
tsacert- the cert alias.
-
setForce
public void setForce(boolean b) Whether to force signing of a jar even it is already signed.- Parameters:
b- boolean- Since:
- Ant 1.8.0
-
isForce
public boolean isForce()Should the task force signing of a jar even it is already signed?- Returns:
- boolean
- Since:
- Ant 1.8.0
-
setSigAlg
Signature Algorithm; optional- Parameters:
sigAlg- the signature algorithm
-
getSigAlg
-
setDigestAlg
Digest Algorithm; optional- Parameters:
digestAlg- the digest algorithm
-
getDigestAlg
-
setTSADigestAlg
TSA Digest Algorithm; optional- Parameters:
digestAlg- the tsa digest algorithm- Since:
- Ant 1.10.2
-
getTSADigestAlg
-
execute
sign the jar(s)- Overrides:
executein classTask- Throws:
BuildException- on errors
-
isUpToDate
Compare a jar file with its corresponding signed jar. The logic for this is complex, and best explained in the source itself. Essentially if either file doesn't exist, or the destfile has an out of date timestamp, then the return value is false.
If we are signing ourself, the check
isSigned(File)is used to trigger the process.- Parameters:
jarFile- the unsigned jar filesignedjarFile- the result signed jar file- Returns:
- true if the signedjarFile is considered up to date
-
isSigned
test for a file being signed, by looking for a signature in the META-INF directory with our alias/sigfile.- Parameters:
file- the file to be checked- Returns:
- true if the file is signed
- See Also:
-
setPreserveLastModified
public void setPreserveLastModified(boolean preserveLastModified) true to indicate that the signed jar modification date remains the same as the original. Defaults to false- Parameters:
preserveLastModified- if true preserve the last modified time
-