Path: blob/master/src/java.base/share/classes/sun/security/validator/SymantecTLSPolicy.java
41159 views
/*1* Copyright (c) 2018, 2019, 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.x509.X509CertImpl;3536/**37* This class checks if Symantec issued TLS Server certificates should be38* restricted.39*/40final class SymantecTLSPolicy {4142// SHA-256 certificate fingerprints of distrusted roots43private static final Set<String> FINGERPRINTS = Set.of(44// cacerts alias: geotrustglobalca45// DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US46"FF856A2D251DCD88D36656F450126798CFABAADE40799C722DE4D2B5DB36A73A",47// cacerts alias: geotrustprimaryca48// DN: CN=GeoTrust Primary Certification Authority,49// O=GeoTrust Inc., C=US50"37D51006C512EAAB626421F1EC8C92013FC5F82AE98EE533EB4619B8DEB4D06C",51// cacerts alias: geotrustprimarycag252// DN: CN=GeoTrust Primary Certification Authority - G2,53// OU=(c) 2007 GeoTrust Inc. - For authorized use only,54// O=GeoTrust Inc., C=US55"5EDB7AC43B82A06A8761E8D7BE4979EBF2611F7DD79BF91C1C6B566A219ED766",56// cacerts alias: geotrustprimarycag357// DN: CN=GeoTrust Primary Certification Authority - G3,58// OU=(c) 2008 GeoTrust Inc. - For authorized use only,59// O=GeoTrust Inc., C=US60"B478B812250DF878635C2AA7EC7D155EAA625EE82916E2CD294361886CD1FBD4",61// cacerts alias: geotrustuniversalca62// DN: CN=GeoTrust Universal CA, O=GeoTrust Inc., C=US63"A0459B9F63B22559F5FA5D4C6DB3F9F72FF19342033578F073BF1D1B46CBB912",64// cacerts alias: thawteprimaryrootca65// DN: CN=thawte Primary Root CA,66// OU="(c) 2006 thawte, Inc. - For authorized use only",67// OU=Certification Services Division, O="thawte, Inc.", C=US68"8D722F81A9C113C0791DF136A2966DB26C950A971DB46B4199F4EA54B78BFB9F",69// cacerts alias: thawteprimaryrootcag270// DN: CN=thawte Primary Root CA - G2,71// OU="(c) 2007 thawte, Inc. - For authorized use only",72// O="thawte, Inc.", C=US73"A4310D50AF18A6447190372A86AFAF8B951FFB431D837F1E5688B45971ED1557",74// cacerts alias: thawteprimaryrootcag375// DN: CN=thawte Primary Root CA - G3,76// OU="(c) 2008 thawte, Inc. - For authorized use only",77// OU=Certification Services Division, O="thawte, Inc.", C=US78"4B03F45807AD70F21BFC2CAE71C9FDE4604C064CF5FFB686BAE5DBAAD7FDD34C",79// cacerts alias: thawtepremiumserverca80// DN: [email protected],81// CN=Thawte Premium Server CA, OU=Certification Services Division,82// O=Thawte Consulting cc, L=Cape Town, ST=Western Cape, C=ZA83"3F9F27D583204B9E09C8A3D2066C4B57D3A2479C3693650880505698105DBCE9",84// cacerts alias: verisignclass2g2ca85// DN: OU=VeriSign Trust Network,86// OU="(c) 1998 VeriSign, Inc. - For authorized use only",87// OU=Class 2 Public Primary Certification Authority - G2,88// O="VeriSign, Inc.", C=US89"3A43E220FE7F3EA9653D1E21742EAC2B75C20FD8980305BC502CAF8C2D9B41A1",90// cacerts alias: verisignclass3ca91// DN: OU=Class 3 Public Primary Certification Authority,92// O="VeriSign, Inc.", C=US93"A4B6B3996FC2F306B3FD8681BD63413D8C5009CC4FA329C2CCF0E2FA1B140305",94// cacerts alias: verisignclass3g2ca95// DN: OU=VeriSign Trust Network,96// OU="(c) 1998 VeriSign, Inc. - For authorized use only",97// OU=Class 3 Public Primary Certification Authority - G2,98// O="VeriSign, Inc.", C=US99"83CE3C1229688A593D485F81973C0F9195431EDA37CC5E36430E79C7A888638B",100// cacerts alias: verisignclass3g3ca101// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G3,102// OU="(c) 1999 VeriSign, Inc. - For authorized use only",103// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US104"EB04CF5EB1F39AFA762F2BB120F296CBA520C1B97DB1589565B81CB9A17B7244",105// cacerts alias: verisignclass3g4ca106// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G4,107// OU="(c) 2007 VeriSign, Inc. - For authorized use only",108// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US109"69DDD7EA90BB57C93E135DC85EA6FCD5480B603239BDC454FC758B2A26CF7F79",110// cacerts alias: verisignclass3g5ca111// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G5,112// OU="(c) 2006 VeriSign, Inc. - For authorized use only",113// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US114"9ACFAB7E43C8D880D06B262A94DEEEE4B4659989C3D0CAF19BAF6405E41AB7DF",115// cacerts alias: verisignuniversalrootca116// DN: CN=VeriSign Universal Root Certification Authority,117// OU="(c) 2008 VeriSign, Inc. - For authorized use only",118// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US119"2399561127A57125DE8CEFEA610DDF2FA078B5C8067F4E828290BFB860E84B3C"120);121122private static final LocalDate DECEMBER_31_2019 =123LocalDate.of(2019, Month.DECEMBER, 31);124// SHA-256 certificate fingerprints of subCAs with later distrust dates125private static final Map<String, LocalDate> EXEMPT_SUBCAS = Map.of(126// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,127// CN=Apple IST CA 2 - G1128// Issuer DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US129"AC2B922ECFD5E01711772FEA8ED372DE9D1E2245FCE3F57A9CDBEC77296A424B",130DECEMBER_31_2019,131// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,132// CN=Apple IST CA 8 - G1133// Issuer DN: CN=GeoTrust Primary Certification Authority - G2,134// OU=(c) 2007 GeoTrust Inc. - For authorized use only,135// O=GeoTrust Inc., C=US136"A4FE7C7F15155F3F0AEF7AAA83CF6E06DEB97CA3F909DF920AC1490882D488ED",137DECEMBER_31_2019138);139140// Any TLS Server certificate that is anchored by one of the Symantec141// roots above and is issued after this date will be distrusted.142private static final LocalDate APRIL_16_2019 =143LocalDate.of(2019, Month.APRIL, 16);144145/**146* This method assumes the eeCert is a TLS Server Cert and chains back to147* the anchor.148*149* @param chain the end-entity's certificate chain. The end entity cert150* is at index 0, the trust anchor at index n-1.151* @throws ValidatorException if the certificate is distrusted152*/153static void checkDistrust(X509Certificate[] chain)154throws ValidatorException {155X509Certificate anchor = chain[chain.length-1];156if (FINGERPRINTS.contains(fingerprint(anchor))) {157Date notBefore = chain[0].getNotBefore();158LocalDate ldNotBefore = LocalDate.ofInstant(notBefore.toInstant(),159ZoneOffset.UTC);160// check if chain goes through one of the subCAs161if (chain.length > 2) {162X509Certificate subCA = chain[chain.length-2];163LocalDate distrustDate = EXEMPT_SUBCAS.get(fingerprint(subCA));164if (distrustDate != null) {165// reject if certificate is issued after specified date166checkNotBefore(ldNotBefore, distrustDate, anchor);167return; // success168}169}170// reject if certificate is issued after April 16, 2019171checkNotBefore(ldNotBefore, APRIL_16_2019, anchor);172}173}174175private static String fingerprint(X509Certificate cert) {176return (cert instanceof X509CertImpl)177? ((X509CertImpl)cert).getFingerprint("SHA-256")178: X509CertImpl.getFingerprint("SHA-256", cert);179}180181private static void checkNotBefore(LocalDate notBeforeDate,182LocalDate distrustDate, X509Certificate anchor)183throws ValidatorException {184if (notBeforeDate.isAfter(distrustDate)) {185throw new ValidatorException186("TLS Server certificate issued after " + distrustDate +187" and anchored by a distrusted legacy Symantec root CA: "188+ anchor.getSubjectX500Principal(),189ValidatorException.T_UNTRUSTED_CERT, anchor);190}191}192193private SymantecTLSPolicy() {}194}195196197