Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/security/provider/certpath/CertPathConstraintsParameters.java
41161 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.security.provider.certpath;
27
28
import java.security.Key;
29
import java.security.cert.TrustAnchor;
30
import java.security.cert.X509Certificate;
31
import java.util.Date;
32
import java.util.Set;
33
34
import sun.security.util.ConstraintsParameters;
35
import sun.security.validator.Validator;
36
37
/**
38
* This class contains parameters for checking certificates against
39
* constraints specified in the jdk.certpath.disabledAlgorithms security
40
* property.
41
*/
42
class CertPathConstraintsParameters implements ConstraintsParameters {
43
// The public key of the certificate
44
private final Key key;
45
// The certificate's trust anchor which will be checked against the
46
// jdkCA constraint, if specified.
47
private final TrustAnchor anchor;
48
// The PKIXParameter validity date or the timestamp of the signed JAR
49
// file, if this chain is associated with a timestamped signed JAR.
50
private final Date date;
51
// The variant or usage of this certificate
52
private final String variant;
53
// The certificate being checked (may be null if a CRL or OCSPResponse is
54
// being checked)
55
private final X509Certificate cert;
56
57
public CertPathConstraintsParameters(X509Certificate cert,
58
String variant, TrustAnchor anchor, Date date) {
59
this(cert.getPublicKey(), variant, anchor, date, cert);
60
}
61
62
public CertPathConstraintsParameters(Key key, String variant,
63
TrustAnchor anchor) {
64
this(key, variant, anchor, null, null);
65
}
66
67
private CertPathConstraintsParameters(Key key, String variant,
68
TrustAnchor anchor, Date date, X509Certificate cert) {
69
this.key = key;
70
this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
71
this.anchor = anchor;
72
this.date = date;
73
this.cert = cert;
74
}
75
76
@Override
77
public boolean anchorIsJdkCA() {
78
return CertPathHelper.isJdkCA(anchor);
79
}
80
81
@Override
82
public Set<Key> getKeys() {
83
return (key == null) ? Set.of() : Set.of(key);
84
}
85
86
@Override
87
public Date getDate() {
88
return date;
89
}
90
91
@Override
92
public String getVariant() {
93
return variant;
94
}
95
96
@Override
97
public String extendedExceptionMsg() {
98
return (cert == null ? "."
99
: " used with certificate: " +
100
cert.getSubjectX500Principal());
101
}
102
103
@Override
104
public String toString() {
105
StringBuilder sb = new StringBuilder("[\n");
106
sb.append("\n Variant: ").append(variant);
107
if (anchor != null) {
108
sb.append("\n Anchor: ").append(anchor);
109
}
110
if (cert != null) {
111
sb.append("\n Cert Issuer: ")
112
.append(cert.getIssuerX500Principal());
113
sb.append("\n Cert Subject: ")
114
.append(cert.getSubjectX500Principal());
115
}
116
if (key != null) {
117
sb.append("\n Key: ").append(key.getAlgorithm());
118
}
119
if (date != null) {
120
sb.append("\n Date: ").append(date);
121
}
122
sb.append("\n]");
123
return sb.toString();
124
}
125
}
126
127