Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/DiffEnd.java
41152 views
1
/*
2
* Copyright (c) 2010, 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 6948909 8217375
27
* @summary Jarsigner removes MANIFEST.MF info for badly packages jar's
28
* @library /test/lib
29
*/
30
/*
31
* See also InsufficientSectionDelimiter.java for similar tests including cases
32
* without or with different line breaks.
33
*/
34
35
import jdk.test.lib.Asserts;
36
import jdk.test.lib.SecurityTools;
37
import jdk.test.lib.process.OutputAnalyzer;
38
39
import java.io.FileOutputStream;
40
import java.nio.charset.StandardCharsets;
41
import java.nio.file.Files;
42
import java.nio.file.Path;
43
import java.util.jar.Attributes;
44
import java.util.jar.JarFile;
45
import java.util.zip.ZipEntry;
46
import java.util.zip.ZipOutputStream;
47
48
public class DiffEnd {
49
50
static void check() throws Exception {
51
String ksArgs = "-keystore " + Path.of(System.getProperty("test.src"))
52
.resolve("JarSigning.keystore") + " -storepass bbbbbb";
53
54
SecurityTools.jarsigner(ksArgs + " -digestalg SHA1 "
55
+ "-signedjar diffend.signed.jar diffend.jar c")
56
.shouldHaveExitValue(0);
57
SecurityTools.jarsigner(" -verify " + ksArgs + " -verbose "
58
+ "diffend.signed.jar c")
59
.stdoutShouldMatch("^smk .* 1$").shouldHaveExitValue(0);
60
61
try (JarFile jf = new JarFile("diffend.signed.jar")) {
62
Asserts.assertTrue(jf.getManifest().getMainAttributes()
63
.containsKey(new Attributes.Name("Today")));
64
}
65
}
66
67
public static void main(String[] args) throws Exception {
68
// A MANIFEST.MF using \n as newlines and no double newlines at the end
69
byte[] manifest = ("Manifest-Version: 1.0\n"
70
+ "Created-By: 1.7.0-internal (Sun Microsystems Inc.)\n"
71
+ "Today: Monday\n").getBytes(StandardCharsets.UTF_8);
72
73
// Without the fake .RSA file, to trigger the if (wasSigned) else block
74
try (FileOutputStream fos = new FileOutputStream("diffend.jar");
75
ZipOutputStream zos = new ZipOutputStream(fos)) {
76
zos.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME));
77
zos.write(manifest);
78
zos.putNextEntry(new ZipEntry("1"));
79
zos.write(new byte[10]);
80
}
81
check();
82
83
// With the fake .RSA file, to trigger the if (wasSigned) block
84
try (FileOutputStream fos = new FileOutputStream("diffend.jar");
85
ZipOutputStream zos = new ZipOutputStream(fos)) {
86
zos.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME));
87
zos.write(manifest);
88
zos.putNextEntry(new ZipEntry("META-INF/x.RSA")); // fake .RSA
89
zos.putNextEntry(new ZipEntry("1"));
90
zos.write(new byte[10]);
91
}
92
check();
93
}
94
}
95
96