Path: blob/master/src/java.base/share/classes/sun/security/validator/SymantecTLSPolicy.java
67766 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.security.validator;2526import java.security.cert.X509Certificate;27import java.time.LocalDate;28import java.time.Month;29import java.time.ZoneOffset;30import java.util.Date;31import java.util.Map;32import java.util.Set;3334import sun.security.util.Debug;35import sun.security.x509.X509CertImpl;3637/**38* This class checks if Symantec issued TLS Server certificates should be39* restricted.40*/41final class SymantecTLSPolicy {4243private static final Debug debug = Debug.getInstance("certpath");4445// SHA-256 certificate fingerprints of distrusted roots46private static final Set<String> FINGERPRINTS = Set.of(47// cacerts alias: geotrustglobalca48// DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US49"FF856A2D251DCD88D36656F450126798CFABAADE40799C722DE4D2B5DB36A73A",50// cacerts alias: geotrustprimaryca51// DN: CN=GeoTrust Primary Certification Authority,52// O=GeoTrust Inc., C=US53"37D51006C512EAAB626421F1EC8C92013FC5F82AE98EE533EB4619B8DEB4D06C",54// cacerts alias: geotrustprimarycag255// DN: CN=GeoTrust Primary Certification Authority - G2,56// OU=(c) 2007 GeoTrust Inc. - For authorized use only,57// O=GeoTrust Inc., C=US58"5EDB7AC43B82A06A8761E8D7BE4979EBF2611F7DD79BF91C1C6B566A219ED766",59// cacerts alias: geotrustprimarycag360// DN: CN=GeoTrust Primary Certification Authority - G3,61// OU=(c) 2008 GeoTrust Inc. - For authorized use only,62// O=GeoTrust Inc., C=US63"B478B812250DF878635C2AA7EC7D155EAA625EE82916E2CD294361886CD1FBD4",64// cacerts alias: geotrustuniversalca65// DN: CN=GeoTrust Universal CA, O=GeoTrust Inc., C=US66"A0459B9F63B22559F5FA5D4C6DB3F9F72FF19342033578F073BF1D1B46CBB912",67// cacerts alias: thawteprimaryrootca68// DN: CN=thawte Primary Root CA,69// OU="(c) 2006 thawte, Inc. - For authorized use only",70// OU=Certification Services Division, O="thawte, Inc.", C=US71"8D722F81A9C113C0791DF136A2966DB26C950A971DB46B4199F4EA54B78BFB9F",72// cacerts alias: thawteprimaryrootcag273// DN: CN=thawte Primary Root CA - G2,74// OU="(c) 2007 thawte, Inc. - For authorized use only",75// O="thawte, Inc.", C=US76"A4310D50AF18A6447190372A86AFAF8B951FFB431D837F1E5688B45971ED1557",77// cacerts alias: thawteprimaryrootcag378// DN: CN=thawte Primary Root CA - G3,79// OU="(c) 2008 thawte, Inc. - For authorized use only",80// OU=Certification Services Division, O="thawte, Inc.", C=US81"4B03F45807AD70F21BFC2CAE71C9FDE4604C064CF5FFB686BAE5DBAAD7FDD34C",82// cacerts alias: thawtepremiumserverca83// DN: [email protected],84// CN=Thawte Premium Server CA, OU=Certification Services Division,85// O=Thawte Consulting cc, L=Cape Town, ST=Western Cape, C=ZA86"3F9F27D583204B9E09C8A3D2066C4B57D3A2479C3693650880505698105DBCE9",87// cacerts alias: verisignclass2g2ca88// DN: OU=VeriSign Trust Network,89// OU="(c) 1998 VeriSign, Inc. - For authorized use only",90// OU=Class 2 Public Primary Certification Authority - G2,91// O="VeriSign, Inc.", C=US92"3A43E220FE7F3EA9653D1E21742EAC2B75C20FD8980305BC502CAF8C2D9B41A1",93// cacerts alias: verisignclass3ca94// DN: OU=Class 3 Public Primary Certification Authority,95// O="VeriSign, Inc.", C=US96"A4B6B3996FC2F306B3FD8681BD63413D8C5009CC4FA329C2CCF0E2FA1B140305",97// cacerts alias: verisignclass3g2ca98// DN: OU=VeriSign Trust Network,99// OU="(c) 1998 VeriSign, Inc. - For authorized use only",100// OU=Class 3 Public Primary Certification Authority - G2,101// O="VeriSign, Inc.", C=US102"83CE3C1229688A593D485F81973C0F9195431EDA37CC5E36430E79C7A888638B",103// cacerts alias: verisignclass3g3ca104// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G3,105// OU="(c) 1999 VeriSign, Inc. - For authorized use only",106// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US107"EB04CF5EB1F39AFA762F2BB120F296CBA520C1B97DB1589565B81CB9A17B7244",108// cacerts alias: verisignclass3g4ca109// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G4,110// OU="(c) 2007 VeriSign, Inc. - For authorized use only",111// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US112"69DDD7EA90BB57C93E135DC85EA6FCD5480B603239BDC454FC758B2A26CF7F79",113// cacerts alias: verisignclass3g5ca114// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G5,115// OU="(c) 2006 VeriSign, Inc. - For authorized use only",116// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US117"9ACFAB7E43C8D880D06B262A94DEEEE4B4659989C3D0CAF19BAF6405E41AB7DF",118// cacerts alias: verisignuniversalrootca119// DN: CN=VeriSign Universal Root Certification Authority,120// OU="(c) 2008 VeriSign, Inc. - For authorized use only",121// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US122"2399561127A57125DE8CEFEA610DDF2FA078B5C8067F4E828290BFB860E84B3C"123);124125private static final LocalDate DECEMBER_31_2019 =126LocalDate.of(2019, Month.DECEMBER, 31);127// SHA-256 certificate fingerprints of subCAs with later distrust dates128private static final Map<String, LocalDate> EXEMPT_SUBCAS = Map.of(129// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,130// CN=Apple IST CA 2 - G1131// Issuer DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US132"AC2B922ECFD5E01711772FEA8ED372DE9D1E2245FCE3F57A9CDBEC77296A424B",133DECEMBER_31_2019,134// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,135// CN=Apple IST CA 8 - G1136// Issuer DN: CN=GeoTrust Primary Certification Authority - G2,137// OU=(c) 2007 GeoTrust Inc. - For authorized use only,138// O=GeoTrust Inc., C=US139"A4FE7C7F15155F3F0AEF7AAA83CF6E06DEB97CA3F909DF920AC1490882D488ED",140DECEMBER_31_2019141);142143// Any TLS Server certificate that is anchored by one of the Symantec144// roots above and is issued after this date will be distrusted.145private static final LocalDate APRIL_16_2019 =146LocalDate.of(2019, Month.APRIL, 16);147148/**149* This method assumes the eeCert is a TLS Server Cert and chains back to150* the anchor.151*152* @param chain the end-entity's certificate chain. The end entity cert153* is at index 0, the trust anchor at index n-1.154* @throws ValidatorException if the certificate is distrusted155*/156static void checkDistrust(X509Certificate[] chain)157throws ValidatorException {158X509Certificate anchor = chain[chain.length-1];159String fp = fingerprint(anchor);160if (fp == null) {161throw new ValidatorException("Cannot generate fingerprint for "162+ "trust anchor of TLS server certificate");163}164if (FINGERPRINTS.contains(fp)) {165Date notBefore = chain[0].getNotBefore();166LocalDate ldNotBefore = LocalDate.ofInstant(notBefore.toInstant(),167ZoneOffset.UTC);168// check if chain goes through one of the subCAs169if (chain.length > 2) {170X509Certificate subCA = chain[chain.length-2];171fp = fingerprint(subCA);172if (fp == null) {173throw new ValidatorException("Cannot generate fingerprint "174+ "for intermediate CA of TLS server certificate");175}176LocalDate distrustDate = EXEMPT_SUBCAS.get(fp);177if (distrustDate != null) {178// reject if certificate is issued after specified date179checkNotBefore(ldNotBefore, distrustDate, anchor);180return; // success181}182}183// reject if certificate is issued after April 16, 2019184checkNotBefore(ldNotBefore, APRIL_16_2019, anchor);185}186}187188private static String fingerprint(X509Certificate cert) {189return X509CertImpl.getFingerprint("SHA-256", cert, debug);190}191192private static void checkNotBefore(LocalDate notBeforeDate,193LocalDate distrustDate, X509Certificate anchor)194throws ValidatorException {195if (notBeforeDate.isAfter(distrustDate)) {196throw new ValidatorException197("TLS Server certificate issued after " + distrustDate +198" and anchored by a distrusted legacy Symantec root CA: "199+ anchor.getSubjectX500Principal(),200ValidatorException.T_UNTRUSTED_CERT, anchor);201}202}203204private SymantecTLSPolicy() {}205}206207208