237 if (System.getProperty("java.home").endsWith("jre")) { |
237 if (System.getProperty("java.home").endsWith("jre")) { |
238 cmd = System.getProperty("java.home") + "/../bin/jarsigner" + |
238 cmd = System.getProperty("java.home") + "/../bin/jarsigner" + |
239 " -J-Djava.security.egd=file:/dev/./urandom" + |
239 " -J-Djava.security.egd=file:/dev/./urandom" + |
240 " -debug -keystore " + TSKS + " -storepass changeit" + |
240 " -debug -keystore " + TSKS + " -storepass changeit" + |
241 " -tsa http://localhost:" + port + "/%d" + |
241 " -tsa http://localhost:" + port + "/%d" + |
242 " -signedjar new.jar " + JAR + " old"; |
242 " -signedjar new_%d.jar " + JAR + " old"; |
243 } else { |
243 } else { |
244 cmd = System.getProperty("java.home") + "/bin/jarsigner" + |
244 cmd = System.getProperty("java.home") + "/bin/jarsigner" + |
245 " -J-Djava.security.egd=file:/dev/./urandom" + |
245 " -J-Djava.security.egd=file:/dev/./urandom" + |
246 " -debug -keystore " + TSKS + " -storepass changeit" + |
246 " -debug -keystore " + TSKS + " -storepass changeit" + |
247 " -tsa http://localhost:" + port + "/%d" + |
247 " -tsa http://localhost:" + port + "/%d" + |
248 " -signedjar new.jar " + JAR + " old"; |
248 " -signedjar new_%d.jar " + JAR + " old"; |
249 } |
249 } |
250 |
250 |
251 try { |
251 try { |
252 if (args.length == 0) { // Run this test |
252 if (args.length == 0) { // Run this test |
253 jarsigner(cmd, 0, true); // Success, normal call |
253 jarsigner(cmd, 0, true); // Success, normal call |
278 * @param expected if this command should succeed |
278 * @param expected if this command should succeed |
279 */ |
279 */ |
280 static void jarsigner(String cmd, int path, boolean expected) |
280 static void jarsigner(String cmd, int path, boolean expected) |
281 throws Exception { |
281 throws Exception { |
282 System.err.println("Test " + path); |
282 System.err.println("Test " + path); |
283 Process p = Runtime.getRuntime().exec(String.format(cmd, path)); |
283 Process p = Runtime.getRuntime().exec(String.format(cmd, path, path)); |
284 BufferedReader reader = new BufferedReader( |
284 BufferedReader reader = new BufferedReader( |
285 new InputStreamReader(p.getErrorStream())); |
285 new InputStreamReader(p.getErrorStream())); |
286 while (true) { |
286 while (true) { |
287 String s = reader.readLine(); |
287 String s = reader.readLine(); |
288 if (s == null) break; |
288 if (s == null) break; |
289 System.err.println(s); |
289 System.err.println(s); |
290 } |
290 } |
|
291 |
|
292 // Will not see noTimestamp warning |
|
293 boolean seeWarning = false; |
|
294 reader = new BufferedReader( |
|
295 new InputStreamReader(p.getInputStream())); |
|
296 while (true) { |
|
297 String s = reader.readLine(); |
|
298 if (s == null) break; |
|
299 System.err.println(s); |
|
300 if (s.indexOf("Warning:") >= 0) { |
|
301 seeWarning = true; |
|
302 } |
|
303 } |
291 int result = p.waitFor(); |
304 int result = p.waitFor(); |
292 if (expected && result != 0 || !expected && result == 0) { |
305 if (expected && result != 0 || !expected && result == 0) { |
293 throw new Exception("Failed"); |
306 throw new Exception("Failed"); |
294 } |
307 } |
|
308 if (seeWarning) { |
|
309 throw new Exception("See warning"); |
|
310 } |
295 } |
311 } |
296 } |
312 } |