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 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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><a name="signjar">SignJar</a></h2>
  23. <h3>Description</h3>
  24. <p>Signing a jar allows users to authenticate the publisher.</p>
  25. <p>Signs JAR files with the <a target="_blank" href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jarsigner.html"><tt>jarsigner</tt> command line tool</a>.
  26. It will take a named file in the <tt>jar</tt> attribute, and an optional
  27. <tt>destDir</tt> or <tt>signedJar</tt> attribute. Nested paths are also
  28. supported; here only an (optional) <tt>destDir</tt> is allowed. If a destination
  29. directory or explicit JAR file name is not provided, JARs are signed in place.
  30. </p>
  31. <p>
  32. Dependency rules
  33. </p>
  34. <ul>
  35. <li>Nonexistent destination JARs are created/signed</li>
  36. <li>Out of date destination JARs are created/signed</li>
  37. <li>If a destination file and a source file are the same,
  38. and <tt>lazy</tt> is true, the JAR is only signed if it does not
  39. contain a signature by this alias.</li>
  40. <li>If a destination file and a source file are the same,
  41. and <tt>lazy</tt> is false, the JAR is signed.</li>
  42. </ul>
  43. <h3>Parameters</h3>
  44. <table border="1" cellpadding="2" cellspacing="0">
  45. <tr>
  46. <td valign="top"><b>Attribute</b></td>
  47. <td valign="top"><b>Description</b></td>
  48. <td align="center" valign="top"><b>Required</b></td>
  49. </tr>
  50. <tr>
  51. <td valign="top">jar</td>
  52. <td valign="top">the jar file to sign</td>
  53. <td valign="top" align="center">Yes, unless nested paths have
  54. been used.</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">alias</td>
  58. <td valign="top">the alias to sign under</td>
  59. <td valign="top" align="center">Yes.</td>
  60. </tr>
  61. <tr>
  62. <td valign="top">storepass</td>
  63. <td valign="top">password for keystore integrity. Ant will not use
  64. the <code>-storepass</code> command line argument but send the
  65. password to jarsigner when it prompts for it.</td>
  66. <td valign="top" align="center">Yes.</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">keystore</td>
  70. <td valign="top">keystore location</td>
  71. <td valign="top" align="center">No</td>
  72. </tr>
  73. <tr>
  74. <td valign="top">storetype</td>
  75. <td valign="top">keystore type</td>
  76. <td valign="top" align="center">No</td>
  77. </tr>
  78. <tr>
  79. <td valign="top">keypass</td>
  80. <td valign="top">password for private key (if different)</td>
  81. <td valign="top" align="center">No</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">sigfile</td>
  85. <td valign="top">name of .SF/.DSA file</td>
  86. <td valign="top" align="center">No</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">signedjar</td>
  90. <td valign="top">name of signed JAR file. This can only be set when
  91. the <tt>jar</tt> attribute is set.</td>
  92. <td valign="top" align="center">No.</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">verbose</td>
  96. <td valign="top">(true | false) verbose output when signing</td>
  97. <td valign="top" align="center">No; default false</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">strict</td>
  101. <td valign="top">(true | false) strict checking when signing.<br/><em>since Ant 1.9.1</em>.</td>
  102. <td valign="top" align="center">No; default false</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">internalsf</td>
  106. <td valign="top">(true | false) include the .SF file inside the signature
  107. block</td>
  108. <td valign="top" align="center">No; default false</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">sectionsonly</td>
  112. <td valign="top">(true | false) don't compute hash of entire manifest</td>
  113. <td valign="top" align="center">No; default false</td>
  114. </tr>
  115. <tr>
  116. <td valign="top">lazy</td>
  117. <td valign="top">flag to control whether the presence of a signature
  118. file means a JAR is signed. This is only used when the target JAR matches
  119. the source JAR</td>
  120. <td valign="top" align="center">No; default false</td>
  121. </tr>
  122. <tr>
  123. <td valign="top">maxmemory</td>
  124. <td valign="top">Specifies the maximum memory the jarsigner VM will use. Specified in the
  125. style of standard java memory specs (e.g. 128m = 128 MBytes)</td>
  126. <td valign="top" align="center">No</td>
  127. </tr>
  128. <tr>
  129. <td valign="top">preservelastmodified</td>
  130. <td valign="top">Give the signed files the same last modified
  131. time as the original jar files.</td>
  132. <td valign="top" align="center">No; default false.</td>
  133. </tr>
  134. <tr>
  135. <td valign="top">tsaurl</td>
  136. <td valign="top">URL for a timestamp authority for timestamped
  137. JAR files in Java1.5+</td>
  138. <td valign="top" align="center">No</td>
  139. </tr>
  140. <tr>
  141. <td valign="top">tsacert</td>
  142. <td valign="top">alias in the keystore for a timestamp authority for
  143. timestamped JAR files in Java1.5+</td>
  144. <td valign="top" align="center">No</td>
  145. </tr>
  146. <tr>
  147. <td valign="top">tsaproxyhost</td>
  148. <td valign="top">proxy host to be used when connecting to TSA server</td>
  149. <td valign="top" align="center">No</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">tsaproxyport</td>
  153. <td valign="top">proxy port to be used when connecting to TSA server</td>
  154. <td valign="top" align="center">No</td>
  155. </tr>
  156. <tr>
  157. <td valign="top">executable</td>
  158. <td valign="top">Specify a particular <code>jarsigner</code> executable
  159. to use in place of the default binary (found in the same JDK as
  160. Apache Ant is running in).<br/>
  161. Must support the same command line options as the Sun JDK
  162. jarsigner command.
  163. <em>since Ant 1.8.0</em>.</td>
  164. <td align="center" valign="top">No</td>
  165. </tr>
  166. <tr>
  167. <td valign="top">force</td>
  168. <td valign="top">Whether to force signing of the jar file even if
  169. it doesn't seem to be out of date or already signed.
  170. <em>since Ant 1.8.0</em>.</td>
  171. <td align="center" valign="top">No; default false</td>
  172. </tr>
  173. <tr>
  174. <td valign="top">sigalg</td>
  175. <td valign="top">name of signature algorithm</td>
  176. <td valign="top" align="center">No</td>
  177. </tr>
  178. <tr>
  179. <td valign="top">digestalg</td>
  180. <td valign="top">name of digest algorithm</td>
  181. <td valign="top" align="center">No</td>
  182. </tr>
  183. </table>
  184. <h3>Parameters as nested elements</h3>
  185. <table border="1" cellpadding="2" cellspacing="0">
  186. <tr>
  187. <td valign="top"><b>Attribute</b></td>
  188. <td valign="top"><b>Description</b></td>
  189. <td align="center" valign="top"><b>Required</b></td>
  190. </tr>
  191. <tr>
  192. <td valign="top">path</td>
  193. <td valign="top">path of JAR files to sign. <em>since Ant 1.7</em></td>
  194. <td valign="top" align="center">No</td>
  195. </tr>
  196. <tr>
  197. <td valign="top">fileset</td>
  198. <td valign="top">fileset of JAR files to sign. </td>
  199. <td valign="top" align="center">No</td>
  200. </tr>
  201. <tr>
  202. <td valign="top">mapper</td>
  203. <td valign="top">A mapper to rename jar files during signing</td>
  204. <td valign="top" align="center">No, and only one can be supplied</td>
  205. </tr>
  206. <tr>
  207. <td valign="top">sysproperty</td>
  208. <td valign="top">JVM system properties, with the syntax of Ant
  209. <a href="exec.html#env">environment variables</a> </td>
  210. <td valign="top" align="center">No, and only one can be supplied</td>
  211. </tr>
  212. </table>
  213. <h3>Examples</h3>
  214. <p>For instructions on generating a code signing certificate, see the <a target="_blank" href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/keytool.html">keytool documentation</a> and/or instructions from your certificate authority.</p>
  215. <blockquote><pre>
  216. &lt;signjar jar=&quot;${dist}/lib/ant.jar&quot;
  217. alias=&quot;apache-group&quot; storepass=&quot;secret&quot;/&gt;
  218. </pre></blockquote>
  219. <p>
  220. signs the ant.jar with alias &quot;apache-group&quot; accessing the
  221. keystore and private key via &quot;secret&quot; password.
  222. </p>
  223. <blockquote><pre>
  224. &lt;signjar destDir="signed"
  225. alias="testonly" keystore="testkeystore"
  226. storepass="apacheant"
  227. preservelastmodified="true"&gt;
  228. &lt;path&gt;
  229. &lt;fileset dir="dist" includes="**/*.jar" /&gt;
  230. &lt;/path&gt;
  231. &lt;flattenmapper /&gt;
  232. &lt;/signjar&gt;
  233. </pre></blockquote>
  234. <p>
  235. Sign all JAR files matching the dist/**/*.jar pattern, copying them to the
  236. directory "signed" afterwards. The flatten mapper means that they will
  237. all be copied to this directory, not to subdirectories.
  238. </p>
  239. <blockquote><pre>
  240. &lt;signjar
  241. alias="testonly" keystore="testkeystore"
  242. storepass="apacheant"
  243. lazy="true"
  244. &gt;
  245. &lt;path&gt;
  246. &lt;fileset dir="dist" includes="**/*.jar" /&gt;
  247. &lt;/path&gt;
  248. &lt;/signjar&gt;
  249. </pre></blockquote>
  250. <p>
  251. Sign all the JAR files in dist/**/*.jar <i>in-situ</i>. Lazy signing is used,
  252. so the files will only be signed if they are not already signed.
  253. </p>
  254. <blockquote><pre>
  255. &lt;signjar
  256. alias="testonly" keystore="testkeystore"
  257. storepass="apacheant"
  258. sigalg="MD5withRSA"
  259. digestalg="SHA1"&gt;
  260. &lt;path&gt;
  261. &lt;fileset dir="dist" includes="**/*.jar" /&gt;
  262. &lt;/path&gt;
  263. &lt;/signjar&gt;
  264. </pre></blockquote>
  265. <p>
  266. Sign all the JAR files in dist/**/*.jar using the digest algorithm SHA1 and the
  267. signature algorithm MD5withRSA. This is especially useful when you want to use
  268. the JDK 7 jarsigner (which uses SHA256 and SHA256withRSA as default) to create
  269. signed jars that will be deployed on platforms not supporting SHA256 and
  270. SHA256withRSA.
  271. </p>
  272. <h3>About timestamp signing</h3>
  273. <p>Timestamps record the date and time that a signature took place, allowing the signature to be verified as of that point in time.
  274. With trusted timestamping, users can verify that signing occurred before a certificate's expiration or revocation. Without this timestamp, users can only verify the signature as of their current date.</p>
  275. <p>
  276. Timestamped JAR files were introduced in Java1.5 and supported in Ant since
  277. Ant 1.7. Since Ant 1.9.5, Ant can use unauthenticated proxies for this signing process.
  278. </p>
  279. <p>Common public timestamp authorities include
  280. <ul>
  281. <li>http://timestamp.verisign.com</li>
  282. <li>http://tsa.starfieldtech.com</li>
  283. <li>https://timestamp.geotrust.com/tsa</li>
  284. <li>Others (see your certificate authority)</li>
  285. </ul></p>
  286. </body>
  287. </html>