You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

signjar.html 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>SignJar Task</title>
  20. </head>
  21. <body>
  22. <h2 id="signjar">SignJar</h2>
  23. <h3>Description</h3>
  24. <p>Signing a jar allows users to authenticate the publisher.</p>
  25. <p>Signs JAR files with
  26. the <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jarsigner.html"
  27. target="_top"><kbd>jarsigner</kbd></a> command line tool. It will take a named file in
  28. the <var>jar</var> attribute, and an optional <var>destDir</var> or <var>signedJar</var>
  29. attribute. Nested paths are also supported; here only an (optional) <var>destDir</var> is
  30. allowed. If a destination directory or explicit JAR file name is not provided, JARs are signed in
  31. place.</p>
  32. <p>Dependency rules</p>
  33. <ul>
  34. <li>Nonexistent destination JARs are created/signed</li>
  35. <li>Out of date destination JARs are created/signed</li>
  36. <li>If a destination file and a source file are the same, and <var>lazy</var> is <q>true</q>, the
  37. JAR is only signed if it does not contain a signature by this alias.</li>
  38. <li>If a destination file and a source file are the same, and <var>lazy</var> is <q>false</q>, the
  39. JAR is signed.</li>
  40. </ul>
  41. <h3>Parameters</h3>
  42. <table class="attr">
  43. <tr>
  44. <th scope="col">Attribute</th>
  45. <th scope="col">Description</th>
  46. <th scope="col">Required</th>
  47. </tr>
  48. <tr>
  49. <td>jar</td>
  50. <td>the jar file to sign</td>
  51. <td>Yes, unless nested paths have been used</td>
  52. </tr>
  53. <tr>
  54. <td>alias</td>
  55. <td>the alias to sign under</td>
  56. <td>Yes</td>
  57. </tr>
  58. <tr>
  59. <td>storepass</td>
  60. <td>password for keystore integrity. Ant will not use
  61. the <code>-storepass</code> command line argument but send the
  62. password to jarsigner when it prompts for it.</td>
  63. <td>Yes</td>
  64. </tr>
  65. <tr>
  66. <td>keystore</td>
  67. <td>keystore location</td>
  68. <td>No</td>
  69. </tr>
  70. <tr>
  71. <td>storetype</td>
  72. <td>keystore type</td>
  73. <td>No</td>
  74. </tr>
  75. <tr>
  76. <td>keypass</td>
  77. <td>password for private key (if different)</td>
  78. <td>No</td>
  79. </tr>
  80. <tr>
  81. <td>sigfile</td>
  82. <td>name of <samp>.SF</samp>/<samp>.DSA</samp> file</td>
  83. <td>No</td>
  84. </tr>
  85. <tr>
  86. <td>signedjar</td>
  87. <td>name of signed JAR file. This can only be set when the <var>jar</var> attribute is set.</td>
  88. <td>No</td>
  89. </tr>
  90. <tr>
  91. <td>verbose</td>
  92. <td>(<q>true|false</q>) verbose output when signing</td>
  93. <td>No; default <q>false</q></td>
  94. </tr>
  95. <tr>
  96. <td>strict</td>
  97. <td>(<q>true|false</q>) strict checking when signing.<br/><em>since Ant 1.9.1</em>.</td>
  98. <td>No; default <q>false</q></td>
  99. </tr>
  100. <tr>
  101. <td>internalsf</td>
  102. <td>(<q>true|false</q>) include the <samp>.SF</samp> file inside the signature block</td>
  103. <td>No; default <q>false</q></td>
  104. </tr>
  105. <tr>
  106. <td>sectionsonly</td>
  107. <td>(<q>true|false</q>) don't compute hash of entire manifest</td>
  108. <td>No; default <q>false</q></td>
  109. </tr>
  110. <tr>
  111. <td>lazy</td>
  112. <td>flag to control whether the presence of a signature file means a JAR is signed. This is only
  113. used when the target JAR matches the source JAR</td>
  114. <td>No; default <q>false</q></td>
  115. </tr>
  116. <tr>
  117. <td>maxmemory</td>
  118. <td>Specifies the maximum memory the <kbd>jarsigner</kbd> JVM will use. Specified in the style
  119. of standard Java memory specs (e.g. <q>128m</q> = 128 MBytes)</td>
  120. <td>No</td>
  121. </tr>
  122. <tr>
  123. <td>preservelastmodified</td>
  124. <td>Give the signed files the same last modified time as the original jar files.</td>
  125. <td>No; default <q>false</q>.</td>
  126. </tr>
  127. <tr>
  128. <td>tsaurl</td>
  129. <td>URL for a timestamp authority for timestamped JAR files in Java 5+</td>
  130. <td>No</td>
  131. </tr>
  132. <tr>
  133. <td>tsacert</td>
  134. <td>alias in the keystore for a timestamp authority for timestamped JAR files in Java 5+</td>
  135. <td>No</td>
  136. </tr>
  137. <tr>
  138. <td>tsaproxyhost</td>
  139. <td>proxy host to be used when connecting to TSA server</td>
  140. <td>No</td>
  141. </tr>
  142. <tr>
  143. <td>tsaproxyport</td>
  144. <td>proxy port to be used when connecting to TSA server</td>
  145. <td>No</td>
  146. </tr>
  147. <tr>
  148. <td>executable</td>
  149. <td>Specify a particular <kbd>jarsigner</kbd> executable to use in place of the default binary
  150. (found in the same JDK as Apache Ant is running in).<br/>Must support the same command line
  151. options as the Sun JDK <kbd>jarsigner</kbd> command. <em>since Ant 1.8.0</em>.</td>
  152. <td>No</td>
  153. </tr>
  154. <tr>
  155. <td>force</td>
  156. <td>Whether to force signing of the jar file even if it doesn't seem to be out of date or
  157. already signed. <em>since Ant 1.8.0</em>.</td>
  158. <td>No; default <q>false</q></td>
  159. </tr>
  160. <tr>
  161. <td>sigalg</td>
  162. <td>name of signature algorithm</td>
  163. <td>No</td>
  164. </tr>
  165. <tr>
  166. <td>digestalg</td>
  167. <td>name of digest algorithm</td>
  168. <td>No</td>
  169. </tr>
  170. <tr>
  171. <td>tsadigestalg</td>
  172. <td>name of TSA digest algorithm. <em>since Ant 1.10.2</em></td>
  173. <td>No</td>
  174. </tr>
  175. <tr>
  176. <td>providername</td>
  177. <td>name of a cryptographic service provider's name
  178. when listed in the security properties file.
  179. <em>since Ant 1.10.6</em>.</td>
  180. <td>No</td>
  181. </tr>
  182. <tr>
  183. <td>providerclass</td>
  184. <td>name of a cryptographic service provider's master
  185. class file when the service provider is not listed in the security
  186. properties file.
  187. <em>since Ant 1.10.6</em>.</td>
  188. <td>No</td>
  189. </tr>
  190. <tr>
  191. <td>providerarg</td>
  192. <td>Represents an optional string input argument for
  193. the constructor of provider_class_name. Ignored
  194. if <code>providerclass</code> is not set.
  195. <em>since Ant 1.10.6</em>.</td>
  196. <td>No</td>
  197. </tr>
  198. </table>
  199. <h3>Parameters as nested elements</h3>
  200. <table class="attr">
  201. <tr>
  202. <th scope="col">Attribute</th>
  203. <th scope="col">Description</th>
  204. <th scope="col">Required</th>
  205. </tr>
  206. <tr>
  207. <td>path</td>
  208. <td>path of JAR files to sign. <em>since Ant 1.7</em></td>
  209. <td>No</td>
  210. </tr>
  211. <tr>
  212. <td>fileset</td>
  213. <td>fileset of JAR files to sign.</td>
  214. <td>No</td>
  215. </tr>
  216. <tr>
  217. <td>mapper</td>
  218. <td>A mapper to rename jar files during signing</td>
  219. <td>No, and only one can be supplied</td>
  220. </tr>
  221. <tr>
  222. <td>sysproperty</td>
  223. <td>JVM system properties, with the syntax of Ant <a href="exec.html#env">environment
  224. variables</a></td>
  225. <td>No, and only one can be supplied</td>
  226. </tr>
  227. <tr>
  228. <td>arg</td>
  229. <td>Use this to specify a <kbd>keytool</kbd>
  230. <a href="../using.html#arg">command line argument</a> not
  231. explicitly supported via an attribute.
  232. <em>since Ant 1.10.6</em>.</td>
  233. <td>No</td>
  234. </tr>
  235. </table>
  236. <h3>Examples</h3>
  237. <p>For instructions on generating a code signing certificate, see
  238. the <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html"
  239. target="_top">keytool documentation</a> and/or instructions from your certificate authority.</p>
  240. <p>Sign the <samp>ant.jar</samp> with alias <q>apache-group</q> accessing the keystore and private
  241. key via <q>secret</q> password.</p>
  242. <pre>
  243. &lt;signjar jar=&quot;${dist}/lib/ant.jar&quot;
  244. alias=&quot;apache-group&quot; storepass=&quot;secret&quot;/&gt;</pre>
  245. <p>Sign all JAR files matching the <samp>dist/**/*.jar</samp> pattern, copying them to the
  246. directory <samp>signed</samp> afterwards. The flatten mapper means that they will all be copied to
  247. this directory, not to subdirectories.</p>
  248. <pre>
  249. &lt;signjar destDir="signed"
  250. alias="testonly" keystore="testkeystore"
  251. storepass="apacheant"
  252. preservelastmodified="true"&gt;
  253. &lt;path&gt;
  254. &lt;fileset dir="dist" includes="**/*.jar"/&gt;
  255. &lt;/path&gt;
  256. &lt;flattenmapper/&gt;
  257. &lt;/signjar&gt;</pre>
  258. <p>Sign all the JAR files in <samp>dist/**/*.jar</samp> <em>in-situ</em>. Lazy signing is used, so
  259. the files will only be signed if they are not already signed.</p>
  260. <pre>
  261. &lt;signjar alias="testonly" keystore="testkeystore"
  262. storepass="apacheant"
  263. lazy="true"&gt;
  264. &lt;path&gt;
  265. &lt;fileset dir="dist" includes="**/*.jar"/&gt;
  266. &lt;/path&gt;
  267. &lt;/signjar&gt;</pre>
  268. <p>Sign all the JAR files in <samp>dist/**/*.jar</samp> using the digest algorithm SHA1 and the
  269. signature algorithm MD5withRSA. This is especially useful when you want to use the JDK
  270. 7 <kbd>jarsigner</kbd> (which uses SHA256 and SHA256withRSA as default) to create signed jars that
  271. will be deployed on platforms not supporting SHA256 and SHA256withRSA.</p>
  272. <pre>
  273. &lt;signjar alias="testonly" keystore="testkeystore"
  274. storepass="apacheant"
  275. sigalg="MD5withRSA"
  276. digestalg="SHA1"&gt;
  277. &lt;path&gt;
  278. &lt;fileset dir="dist" includes="**/*.jar"/&gt;
  279. &lt;/path&gt;
  280. &lt;/signjar&gt;</pre>
  281. <h3>About timestamp signing</h3>
  282. <p>Timestamps record the date and time that a signature took place, allowing the signature to be
  283. verified as of that point in time. With trusted timestamping, users can verify that signing
  284. occurred before a certificate's expiration or revocation. Without this timestamp, users can only
  285. verify the signature as of their current date.</p>
  286. <p>Timestamped JAR files were introduced in Java 5; they are supported <em>since Ant
  287. 1.7</em>. Unauthenticated proxies can be used to access TSAs <em>since Ant 1.9.5</em>.</p>
  288. <p>Common public timestamp authorities include</p>
  289. <ul>
  290. <li>http://timestamp.verisign.com</li>
  291. <li>http://tsa.starfieldtech.com</li>
  292. <li>https://timestamp.geotrust.com/tsa</li>
  293. <li>Others (see your certificate authority)</li>
  294. </ul>
  295. </body>
  296. </html>