Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/cert/PolicyNode/GetPolicyQualifiers.java
41153 views
1
/*
2
* Copyright (c) 2001, 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 4414263
27
* @summary Make sure PolicyNode.getPolicyQualifiers() returns
28
* Set of PolicyQualifierInfos.
29
*/
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.security.cert.*;
33
import java.text.DateFormat;
34
import java.util.Collections;
35
import java.util.Iterator;
36
import java.util.List;
37
import java.util.Locale;
38
import java.util.Set;
39
40
public class GetPolicyQualifiers {
41
42
public static void main(String[] args) throws Exception {
43
44
CertificateFactory cf = CertificateFactory.getInstance("X.509", "SUN");
45
File f = new File(System.getProperty("test.src", "."), "speech2speech");
46
X509Certificate mostTrustedCaCert = (X509Certificate)
47
cf.generateCertificate(new FileInputStream(f));
48
Set trustAnchors = Collections.singleton(
49
new TrustAnchor(mostTrustedCaCert, null));
50
f = new File(System.getProperty("test.src", "."), "speech2eve");
51
X509Certificate eeCert = (X509Certificate)
52
cf.generateCertificate(new FileInputStream(f));
53
CertPathValidator cpv = CertPathValidator.getInstance("PKIX", "SUN");
54
PKIXParameters params = new PKIXParameters(trustAnchors);
55
params.setPolicyQualifiersRejected(false);
56
params.setRevocationEnabled(false);
57
// Certificates expired on Oct 6th, 2020
58
params.setDate(DateFormat.getDateInstance(DateFormat.MEDIUM,
59
Locale.US).parse("July 01, 2020"));
60
List certList = Collections.singletonList(eeCert);
61
CertPath cp = cf.generateCertPath(certList);
62
PKIXCertPathValidatorResult result =
63
(PKIXCertPathValidatorResult) cpv.validate(cp, params);
64
65
PolicyNode policyTree = result.getPolicyTree();
66
Iterator children = policyTree.getChildren();
67
PolicyNode child = (PolicyNode) children.next();
68
Set policyQualifiers = child.getPolicyQualifiers();
69
Iterator i = policyQualifiers.iterator();
70
while (i.hasNext()) {
71
Object next = i.next();
72
if (!(next instanceof PolicyQualifierInfo))
73
throw new Exception("not a PolicyQualifierInfo");
74
}
75
76
params.setPolicyQualifiersRejected(true);
77
try {
78
result = (PKIXCertPathValidatorResult) cpv.validate(cp, params);
79
throw new Exception("Validation of CertPath containing critical " +
80
"qualifiers should have failed when policyQualifiersRejected " +
81
"flag is true");
82
} catch (CertPathValidatorException cpve) {
83
if (cpve.getReason() != PKIXReason.INVALID_POLICY) {
84
throw new Exception("unexpected reason: " + cpve.getReason());
85
}
86
}
87
}
88
}
89
90