Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/RemoveDifferentKeyAlgBlockFile.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
import java.nio.file.Path;
25
import java.util.jar.JarFile;
26
import java.util.jar.Manifest;
27
import java.util.jar.Attributes.Name;
28
import jdk.test.lib.util.JarUtils;
29
import jdk.test.lib.SecurityTools;
30
import org.testng.annotations.Test;
31
import org.testng.annotations.BeforeClass;
32
33
/**
34
* @test
35
* @bug 8217375
36
* @library /test/lib
37
* @run testng RemoveDifferentKeyAlgBlockFile
38
* @summary Checks that if a signed jar file is signed again with the same
39
* signer name and a different algorithm that the signature block file for
40
* the previous signature is removed. Example: the jar had META-INF/A.SF and
41
* META-INF/A.RSA files and is now signed with DSA. So it should contain
42
* an updated META-INF/A.SF and META-INF/A.DSA and the META-INF/A.RSA should
43
* be removed because not valid any longer.
44
*/
45
public class RemoveDifferentKeyAlgBlockFile {
46
47
static final String KEYSTORE_FILENAME = "test.jks";
48
49
@BeforeClass
50
public void prepareCertificates() throws Exception {
51
SecurityTools.keytool("-genkeypair -keyalg RSA -keystore "
52
+ KEYSTORE_FILENAME + " -storepass changeit -keypass changeit"
53
+ " -alias RSA -dname CN=RSA").shouldHaveExitValue(0);
54
SecurityTools.keytool("-genkeypair -keyalg DSA -keystore "
55
+ KEYSTORE_FILENAME + " -storepass changeit -keypass changeit"
56
+ " -alias DSA -dname CN=DSA").shouldHaveExitValue(0);
57
}
58
59
@Test
60
public void testOtherAlgSigBlockFileRemoved() throws Exception {
61
String jarFilename = "test.jar";
62
JarUtils.createJarFile(Path.of(jarFilename), (Manifest) null,
63
Path.of("."));
64
SecurityTools.jarsigner("-keystore " + KEYSTORE_FILENAME +
65
" -storepass changeit -verbose -debug -sigfile A " +
66
jarFilename + " RSA").shouldHaveExitValue(0);
67
68
// change the jar file to invalidate the first signature with RSA
69
String jarFilenameModified = "modified.jar";
70
try (JarFile jar = new JarFile(jarFilename)) {
71
Manifest manifest = jar.getManifest();
72
manifest.getMainAttributes().put(
73
new Name("Some-Key"), "Some-Value");
74
JarUtils.updateManifest(jarFilename, jarFilenameModified, manifest);
75
}
76
77
SecurityTools.jarsigner("-keystore " + KEYSTORE_FILENAME +
78
" -storepass changeit -verbose -debug -sigfile A " +
79
jarFilenameModified + " DSA").shouldHaveExitValue(0);
80
SecurityTools.jarsigner("-verify -keystore " + KEYSTORE_FILENAME +
81
" -storepass changeit -debug -verbose " + jarFilenameModified)
82
.shouldHaveExitValue(0);
83
}
84
85
}
86
87