35 import java.util.jar.*; |
35 import java.util.jar.*; |
36 |
36 |
37 public class ScanSignedJar { |
37 public class ScanSignedJar { |
38 |
38 |
39 public static void main(String[] args) throws Exception { |
39 public static void main(String[] args) throws Exception { |
40 JarFile file = new JarFile(new File(System.getProperty("test.src","."), |
|
41 "bogus-signerinfo-attr.jar")); |
|
42 byte[] buffer = new byte[8192]; |
|
43 boolean isSigned = false; |
40 boolean isSigned = false; |
|
41 try (JarFile file = new JarFile(new File(System.getProperty("test.src","."), |
|
42 "bogus-signerinfo-attr.jar"))) { |
|
43 byte[] buffer = new byte[8192]; |
44 |
44 |
45 for (Enumeration entries = file.entries(); entries.hasMoreElements();) { |
45 for (Enumeration entries = file.entries(); entries.hasMoreElements();) { |
46 JarEntry entry = (JarEntry) entries.nextElement(); |
46 JarEntry entry = (JarEntry) entries.nextElement(); |
47 InputStream jis = file.getInputStream(entry); |
47 try (InputStream jis = file.getInputStream(entry)) { |
48 while (jis.read(buffer, 0, buffer.length) != -1) { |
48 while (jis.read(buffer, 0, buffer.length) != -1) { |
49 // read the jar entry |
49 // read the jar entry |
|
50 } |
|
51 } |
|
52 if (entry.getCertificates() != null) { |
|
53 isSigned = true; |
|
54 } |
|
55 System.out.println((isSigned ? "[signed] " : "\t ") + |
|
56 entry.getName()); |
50 } |
57 } |
51 jis.close(); |
|
52 if (entry.getCertificates() != null) { |
|
53 isSigned = true; |
|
54 } |
|
55 System.out.println((isSigned ? "[signed] " : "\t ") + |
|
56 entry.getName()); |
|
57 } |
58 } |
58 file.close(); |
|
59 |
59 |
60 if (isSigned) { |
60 if (isSigned) { |
61 System.out.println("\nJAR file has signed entries"); |
61 System.out.println("\nJAR file has signed entries"); |
62 } else { |
62 } else { |
63 throw new Exception("Failed to detect that the JAR file is signed"); |
63 throw new Exception("Failed to detect that the JAR file is signed"); |