Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/x509/AlgorithmId/OmitAlgIdParam.java
41153 views
1
/*
2
* Copyright (c) 2020, 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 8252377
27
* @library /test/lib
28
* @modules java.base/sun.security.util
29
* java.base/sun.security.x509
30
* @summary The AlgorithmIdentifier for ECDSA should omit the parameters field
31
*/
32
33
import jdk.test.lib.Asserts;
34
import jdk.test.lib.SecurityTools;
35
import jdk.test.lib.process.OutputAnalyzer;
36
import static jdk.test.lib.security.DerUtils.*;
37
38
import java.io.File;
39
import java.security.KeyStore;
40
import java.security.cert.X509Certificate;
41
import sun.security.util.*;
42
43
public class OmitAlgIdParam {
44
45
public static void main(String[] args) throws Exception {
46
keytool("-genkeypair -keyalg ec -dname CN=EC1 -alias ecsha224 "
47
+ "-sigalg SHA224withECDSA -keystore ks -storepass changeit");
48
49
keytool("-genkeypair -keyalg ec -dname CN=EC2 -alias ecsha256 "
50
+ "-sigalg SHA256withECDSA -keystore ks -storepass changeit");
51
52
keytool("-genkeypair -keyalg ec -dname CN=EC3 -alias ecsha384 "
53
+ "-sigalg SHA384withECDSA -keystore ks -storepass changeit");
54
55
keytool("-genkeypair -keyalg ec -dname CN=EC4 -alias ecsha512 "
56
+ "-sigalg SHA512withECDSA -keystore ks -storepass changeit");
57
58
KeyStore kstore = KeyStore.getInstance(
59
new File("ks"), "changeit".toCharArray());
60
61
// SHA224withECDSA
62
checkAlgId(kstore, "ecsha224", "SHA224withECDSA",
63
ObjectIdentifier.of(KnownOIDs.SHA224withECDSA));
64
65
// SHA256withECDSA
66
checkAlgId(kstore, "ecsha256", "SHA256withECDSA",
67
ObjectIdentifier.of(KnownOIDs.SHA256withECDSA));
68
69
// SHA384withECDSA
70
checkAlgId(kstore, "ecsha384", "SHA384withECDSA",
71
ObjectIdentifier.of(KnownOIDs.SHA384withECDSA));
72
73
// SHA512withECDSA
74
checkAlgId(kstore, "ecsha512", "SHA512withECDSA",
75
ObjectIdentifier.of(KnownOIDs.SHA512withECDSA));
76
}
77
78
private static void checkAlgId(KeyStore ks, String alias, String alg,
79
ObjectIdentifier oid) throws Exception {
80
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
81
System.out.println("SigAlgName = " + cert.getSigAlgName());
82
83
Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), "EC");
84
Asserts.assertEQ(cert.getSigAlgName(), alg);
85
86
byte[] data = cert.getEncoded();
87
// Parameters field in the specified AlgorithmIdentifier should be omitted
88
// Checking the first signature AlgorithmIdentifier in the cert
89
checkAlg(data, "020", oid);
90
shouldNotExist(data, "021");
91
// Checking the second signature AlgorithmIdentifier in the cert
92
checkAlg(data, "10", oid);
93
shouldNotExist(data, "11");
94
}
95
96
static OutputAnalyzer keytool(String cmd) throws Exception {
97
return SecurityTools.keytool(cmd).shouldHaveExitValue(0);
98
}
99
}
100
101