Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/SignedAgain.java
41152 views
1
/*
2
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8215922
27
* @summary jar spec is not precise when describing jar file re-signing
28
* @library /test/lib
29
*/
30
31
import jdk.test.lib.Asserts;
32
import jdk.test.lib.util.JarUtils;
33
34
import java.io.InputStream;
35
import java.security.MessageDigest;
36
import java.util.Base64;
37
import java.util.jar.JarEntry;
38
import java.util.jar.JarFile;
39
import java.util.jar.Manifest;
40
41
import static jdk.test.lib.SecurityTools.*;
42
43
public class SignedAgain {
44
public static void main(String[] args) throws Exception {
45
46
String opt = "-storepass changeit -keystore ks";
47
48
keytool(opt + " -genkeypair -alias a -dname CN=A -keyalg RSA");
49
keytool(opt + " -genkeypair -alias b -dname CN=B -keyalg RSA");
50
51
JarUtils.createJar("a.jar", "f1");
52
53
// as.jar: signed by a
54
jarsigner(opt + " -signedjar as.jar a.jar a");
55
56
JarUtils.updateJar("as.jar", "b.jar", "f2");
57
58
// bs.jar: signed again by b
59
jarsigner(opt + " -signedjar bs.jar b.jar b");
60
61
// verified
62
jarsigner(opt + " -verify -strict -verbose -certs bs.jar")
63
.shouldHaveExitValue(0);
64
65
try (JarFile ja = new JarFile("as.jar");
66
JarFile jb = new JarFile("bs.jar");
67
InputStream ma = ja.getInputStream(
68
new JarEntry("META-INF/MANIFEST.MF"));
69
InputStream sa = jb.getInputStream(new JarEntry("META-INF/A.SF"));
70
InputStream mb = jb.getInputStream(
71
new JarEntry("META-INF/MANIFEST.MF"));
72
InputStream sb = jb.getInputStream(new JarEntry("META-INF/B.SF"))) {
73
74
// Hash of manifest for 2 signed JAR files
75
String da = Base64.getEncoder().encodeToString(MessageDigest
76
.getInstance("SHA-256").digest(ma.readAllBytes()));
77
String db = Base64.getEncoder().encodeToString(MessageDigest
78
.getInstance("SHA-256").digest(mb.readAllBytes()));
79
80
// They are not the same
81
Asserts.assertNotEquals(da, db);
82
83
// Digest-Manifest in A.SF matches da
84
Asserts.assertEQ(new Manifest(sa).getMainAttributes()
85
.getValue("SHA-256-Digest-Manifest"), da);
86
87
// Digest-Manifest in B.SF matches db
88
Asserts.assertEQ(new Manifest(sb).getMainAttributes()
89
.getValue("SHA-256-Digest-Manifest"), db);
90
}
91
}
92
}
93
94