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 9.3 kB

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