author | vlivanov |
Wed, 02 Mar 2016 15:42:03 +0300 | |
changeset 36349 | 6cc8e6f596b2 |
parent 36129 | 332b49163fc9 |
child 36219 | 437e72684a42 |
permissions | -rw-r--r-- |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
1 |
/* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
4 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
8 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
13 |
* accompanied this code). |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
14 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
18 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
21 |
* questions. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
22 |
*/ |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
23 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
24 |
/* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
25 |
* @test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
26 |
* @bug 8132734 |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
27 |
* @summary Test potential security related issues |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
28 |
* @library /lib/testlibrary/java/util/jar |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
29 |
* @build Compiler JarBuilder CreateMultiReleaseTestJars |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
30 |
* @run testng MultiReleaseJarSecurity |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
31 |
*/ |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
32 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
33 |
import java.io.File; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
34 |
import java.io.IOException; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
35 |
import java.io.InputStream; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
36 |
import java.nio.file.Files; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
37 |
import java.security.CodeSigner; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
38 |
import java.security.cert.Certificate; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
39 |
import java.util.Arrays; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
40 |
import java.util.jar.JarEntry; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
41 |
import java.util.jar.JarFile; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
42 |
import java.util.zip.ZipFile; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
43 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
44 |
import org.testng.Assert; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
45 |
import org.testng.annotations.AfterClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
46 |
import org.testng.annotations.BeforeClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
47 |
import org.testng.annotations.Test; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
48 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
49 |
public class MultiReleaseJarSecurity { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
50 |
String userdir = System.getProperty("user.dir","."); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
51 |
File multirelease = new File(userdir, "multi-release.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
52 |
File signedmultirelease = new File(userdir, "signed-multi-release.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
53 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
54 |
@BeforeClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
55 |
public void initialize() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
56 |
CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
57 |
creator.compileEntries(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
58 |
creator.buildMultiReleaseJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
59 |
creator.buildSignedMultiReleaseJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
60 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
61 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
62 |
@AfterClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
63 |
public void close() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
64 |
Files.delete(multirelease.toPath()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
65 |
Files.delete(signedmultirelease.toPath()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
66 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
67 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
68 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
69 |
public void testCertsAndSigners() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
70 |
try (JarFile jf = new JarFile(signedmultirelease, true, ZipFile.OPEN_READ, JarFile.Release.RUNTIME)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
71 |
int version = sun.misc.Version.jdkMajorVersion(); // fixme JEP 223 Version |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
72 |
CertsAndSigners vcas = new CertsAndSigners(jf, jf.getJarEntry("version/Version.class")); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
73 |
CertsAndSigners rcas = new CertsAndSigners(jf, jf.getJarEntry("META-INF/versions/" + version + "/version/Version.class")); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
74 |
Assert.assertTrue(Arrays.equals(rcas.getCertificates(), vcas.getCertificates())); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
75 |
Assert.assertTrue(Arrays.equals(rcas.getCodeSigners(), vcas.getCodeSigners())); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
76 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
77 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
78 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
79 |
private static class CertsAndSigners { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
80 |
final private JarFile jf; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
81 |
final private JarEntry je; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
82 |
private boolean readComplete; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
83 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
84 |
CertsAndSigners(JarFile jf, JarEntry je) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
85 |
this.jf = jf; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
86 |
this.je = je; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
87 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
88 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
89 |
Certificate[] getCertificates() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
90 |
readEntry(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
91 |
return je.getCertificates(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
92 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
93 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
94 |
CodeSigner[] getCodeSigners() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
95 |
readEntry(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
96 |
return je.getCodeSigners(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
97 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
98 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
99 |
private void readEntry() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
100 |
if (!readComplete) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
101 |
try (InputStream is = jf.getInputStream(je)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
102 |
is.readAllBytes(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
103 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
104 |
readComplete = true; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
105 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
106 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
107 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
108 |
} |