Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/share/classes/sun/security/validator/SymantecTLSPolicy.java
67766 views
1
/*
2
* Copyright (c) 2018, 2021, 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
package sun.security.validator;
26
27
import java.security.cert.X509Certificate;
28
import java.time.LocalDate;
29
import java.time.Month;
30
import java.time.ZoneOffset;
31
import java.util.Date;
32
import java.util.Map;
33
import java.util.Set;
34
35
import sun.security.util.Debug;
36
import sun.security.x509.X509CertImpl;
37
38
/**
39
* This class checks if Symantec issued TLS Server certificates should be
40
* restricted.
41
*/
42
final class SymantecTLSPolicy {
43
44
private static final Debug debug = Debug.getInstance("certpath");
45
46
// SHA-256 certificate fingerprints of distrusted roots
47
private static final Set<String> FINGERPRINTS = Set.of(
48
// cacerts alias: geotrustglobalca
49
// DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US
50
"FF856A2D251DCD88D36656F450126798CFABAADE40799C722DE4D2B5DB36A73A",
51
// cacerts alias: geotrustprimaryca
52
// DN: CN=GeoTrust Primary Certification Authority,
53
// O=GeoTrust Inc., C=US
54
"37D51006C512EAAB626421F1EC8C92013FC5F82AE98EE533EB4619B8DEB4D06C",
55
// cacerts alias: geotrustprimarycag2
56
// DN: CN=GeoTrust Primary Certification Authority - G2,
57
// OU=(c) 2007 GeoTrust Inc. - For authorized use only,
58
// O=GeoTrust Inc., C=US
59
"5EDB7AC43B82A06A8761E8D7BE4979EBF2611F7DD79BF91C1C6B566A219ED766",
60
// cacerts alias: geotrustprimarycag3
61
// DN: CN=GeoTrust Primary Certification Authority - G3,
62
// OU=(c) 2008 GeoTrust Inc. - For authorized use only,
63
// O=GeoTrust Inc., C=US
64
"B478B812250DF878635C2AA7EC7D155EAA625EE82916E2CD294361886CD1FBD4",
65
// cacerts alias: geotrustuniversalca
66
// DN: CN=GeoTrust Universal CA, O=GeoTrust Inc., C=US
67
"A0459B9F63B22559F5FA5D4C6DB3F9F72FF19342033578F073BF1D1B46CBB912",
68
// cacerts alias: thawteprimaryrootca
69
// DN: CN=thawte Primary Root CA,
70
// OU="(c) 2006 thawte, Inc. - For authorized use only",
71
// OU=Certification Services Division, O="thawte, Inc.", C=US
72
"8D722F81A9C113C0791DF136A2966DB26C950A971DB46B4199F4EA54B78BFB9F",
73
// cacerts alias: thawteprimaryrootcag2
74
// DN: CN=thawte Primary Root CA - G2,
75
// OU="(c) 2007 thawte, Inc. - For authorized use only",
76
// O="thawte, Inc.", C=US
77
"A4310D50AF18A6447190372A86AFAF8B951FFB431D837F1E5688B45971ED1557",
78
// cacerts alias: thawteprimaryrootcag3
79
// DN: CN=thawte Primary Root CA - G3,
80
// OU="(c) 2008 thawte, Inc. - For authorized use only",
81
// OU=Certification Services Division, O="thawte, Inc.", C=US
82
"4B03F45807AD70F21BFC2CAE71C9FDE4604C064CF5FFB686BAE5DBAAD7FDD34C",
83
// cacerts alias: thawtepremiumserverca
84
// DN: [email protected],
85
// CN=Thawte Premium Server CA, OU=Certification Services Division,
86
// O=Thawte Consulting cc, L=Cape Town, ST=Western Cape, C=ZA
87
"3F9F27D583204B9E09C8A3D2066C4B57D3A2479C3693650880505698105DBCE9",
88
// cacerts alias: verisignclass2g2ca
89
// DN: OU=VeriSign Trust Network,
90
// OU="(c) 1998 VeriSign, Inc. - For authorized use only",
91
// OU=Class 2 Public Primary Certification Authority - G2,
92
// O="VeriSign, Inc.", C=US
93
"3A43E220FE7F3EA9653D1E21742EAC2B75C20FD8980305BC502CAF8C2D9B41A1",
94
// cacerts alias: verisignclass3ca
95
// DN: OU=Class 3 Public Primary Certification Authority,
96
// O="VeriSign, Inc.", C=US
97
"A4B6B3996FC2F306B3FD8681BD63413D8C5009CC4FA329C2CCF0E2FA1B140305",
98
// cacerts alias: verisignclass3g2ca
99
// DN: OU=VeriSign Trust Network,
100
// OU="(c) 1998 VeriSign, Inc. - For authorized use only",
101
// OU=Class 3 Public Primary Certification Authority - G2,
102
// O="VeriSign, Inc.", C=US
103
"83CE3C1229688A593D485F81973C0F9195431EDA37CC5E36430E79C7A888638B",
104
// cacerts alias: verisignclass3g3ca
105
// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G3,
106
// OU="(c) 1999 VeriSign, Inc. - For authorized use only",
107
// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US
108
"EB04CF5EB1F39AFA762F2BB120F296CBA520C1B97DB1589565B81CB9A17B7244",
109
// cacerts alias: verisignclass3g4ca
110
// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G4,
111
// OU="(c) 2007 VeriSign, Inc. - For authorized use only",
112
// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US
113
"69DDD7EA90BB57C93E135DC85EA6FCD5480B603239BDC454FC758B2A26CF7F79",
114
// cacerts alias: verisignclass3g5ca
115
// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G5,
116
// OU="(c) 2006 VeriSign, Inc. - For authorized use only",
117
// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US
118
"9ACFAB7E43C8D880D06B262A94DEEEE4B4659989C3D0CAF19BAF6405E41AB7DF",
119
// cacerts alias: verisignuniversalrootca
120
// DN: CN=VeriSign Universal Root Certification Authority,
121
// OU="(c) 2008 VeriSign, Inc. - For authorized use only",
122
// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US
123
"2399561127A57125DE8CEFEA610DDF2FA078B5C8067F4E828290BFB860E84B3C"
124
);
125
126
private static final LocalDate DECEMBER_31_2019 =
127
LocalDate.of(2019, Month.DECEMBER, 31);
128
// SHA-256 certificate fingerprints of subCAs with later distrust dates
129
private static final Map<String, LocalDate> EXEMPT_SUBCAS = Map.of(
130
// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,
131
// CN=Apple IST CA 2 - G1
132
// Issuer DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US
133
"AC2B922ECFD5E01711772FEA8ED372DE9D1E2245FCE3F57A9CDBEC77296A424B",
134
DECEMBER_31_2019,
135
// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,
136
// CN=Apple IST CA 8 - G1
137
// Issuer DN: CN=GeoTrust Primary Certification Authority - G2,
138
// OU=(c) 2007 GeoTrust Inc. - For authorized use only,
139
// O=GeoTrust Inc., C=US
140
"A4FE7C7F15155F3F0AEF7AAA83CF6E06DEB97CA3F909DF920AC1490882D488ED",
141
DECEMBER_31_2019
142
);
143
144
// Any TLS Server certificate that is anchored by one of the Symantec
145
// roots above and is issued after this date will be distrusted.
146
private static final LocalDate APRIL_16_2019 =
147
LocalDate.of(2019, Month.APRIL, 16);
148
149
/**
150
* This method assumes the eeCert is a TLS Server Cert and chains back to
151
* the anchor.
152
*
153
* @param chain the end-entity's certificate chain. The end entity cert
154
* is at index 0, the trust anchor at index n-1.
155
* @throws ValidatorException if the certificate is distrusted
156
*/
157
static void checkDistrust(X509Certificate[] chain)
158
throws ValidatorException {
159
X509Certificate anchor = chain[chain.length-1];
160
String fp = fingerprint(anchor);
161
if (fp == null) {
162
throw new ValidatorException("Cannot generate fingerprint for "
163
+ "trust anchor of TLS server certificate");
164
}
165
if (FINGERPRINTS.contains(fp)) {
166
Date notBefore = chain[0].getNotBefore();
167
LocalDate ldNotBefore = LocalDate.ofInstant(notBefore.toInstant(),
168
ZoneOffset.UTC);
169
// check if chain goes through one of the subCAs
170
if (chain.length > 2) {
171
X509Certificate subCA = chain[chain.length-2];
172
fp = fingerprint(subCA);
173
if (fp == null) {
174
throw new ValidatorException("Cannot generate fingerprint "
175
+ "for intermediate CA of TLS server certificate");
176
}
177
LocalDate distrustDate = EXEMPT_SUBCAS.get(fp);
178
if (distrustDate != null) {
179
// reject if certificate is issued after specified date
180
checkNotBefore(ldNotBefore, distrustDate, anchor);
181
return; // success
182
}
183
}
184
// reject if certificate is issued after April 16, 2019
185
checkNotBefore(ldNotBefore, APRIL_16_2019, anchor);
186
}
187
}
188
189
private static String fingerprint(X509Certificate cert) {
190
return X509CertImpl.getFingerprint("SHA-256", cert, debug);
191
}
192
193
private static void checkNotBefore(LocalDate notBeforeDate,
194
LocalDate distrustDate, X509Certificate anchor)
195
throws ValidatorException {
196
if (notBeforeDate.isAfter(distrustDate)) {
197
throw new ValidatorException
198
("TLS Server certificate issued after " + distrustDate +
199
" and anchored by a distrusted legacy Symantec root CA: "
200
+ anchor.getSubjectX500Principal(),
201
ValidatorException.T_UNTRUSTED_CERT, anchor);
202
}
203
}
204
205
private SymantecTLSPolicy() {}
206
}
207
208