author | jnimeh |
Sat, 14 Mar 2015 09:38:52 -0700 | |
changeset 29488 | 1f25b971e59a |
parent 21342 | 7bbb056a1c23 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
19376
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
1 |
/* |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
4 |
* |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
8 |
* |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
14 |
* |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
18 |
* |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
21 |
* questions. |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
22 |
*/ |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
23 |
|
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
24 |
/* |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
25 |
* @test |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
26 |
* @bug 8021788 |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
27 |
* @summary JarInputStream doesn't provide certificates for some file under META-INF |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
28 |
*/ |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
29 |
|
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
30 |
import java.util.jar.*; |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
31 |
import java.io.*; |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
32 |
import java.util.zip.ZipEntry; |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
33 |
import java.util.zip.ZipOutputStream; |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
34 |
|
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
35 |
public class ExtraFileInMetaInf { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
36 |
public static void main(String args[]) throws Exception { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
37 |
|
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
38 |
// Create a zip file with 2 entries |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
39 |
try (ZipOutputStream zos = |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
40 |
new ZipOutputStream(new FileOutputStream("x.jar"))) { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
41 |
zos.putNextEntry(new ZipEntry("META-INF/SUB/file")); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
42 |
zos.write(new byte[10]); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
43 |
zos.putNextEntry(new ZipEntry("x")); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
44 |
zos.write(new byte[10]); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
45 |
zos.close(); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
46 |
} |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
47 |
|
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
48 |
// Sign it |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
49 |
new File("ks").delete(); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
50 |
sun.security.tools.keytool.Main.main( |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
51 |
("-keystore ks -storepass changeit -keypass changeit " + |
21342
7bbb056a1c23
8027026: Change keytool -genkeypair to use -keyalg RSA
weijun
parents:
19376
diff
changeset
|
52 |
"-keyalg rsa -alias a -dname CN=A -genkeypair").split(" ")); |
19376
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
53 |
sun.security.tools.jarsigner.Main.main( |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
54 |
"-keystore ks -storepass changeit x.jar a".split(" ")); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
55 |
|
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
56 |
// Check if the entries are signed |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
57 |
try (JarInputStream jis = |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
58 |
new JarInputStream(new FileInputStream("x.jar"))) { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
59 |
JarEntry je; |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
60 |
while ((je = jis.getNextJarEntry()) != null) { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
61 |
String name = je.toString(); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
62 |
if (name.equals("META-INF/SUB/file") || name.equals("x")) { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
63 |
while (jis.read(new byte[1000]) >= 0); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
64 |
if (je.getCertificates() == null) { |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
65 |
throw new Exception(name + " not signed"); |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
66 |
} |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
67 |
} |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
68 |
} |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
69 |
} |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
70 |
} |
b8743dfc5d00
8021788: JarInputStream doesn't provide certificates for some file under META-INF
weijun
parents:
diff
changeset
|
71 |
} |