Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/validator/SymantecTLSPolicy.java
38831 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.Arrays;31import java.util.Date;32import java.util.HashMap;33import java.util.HashSet;34import java.util.Map;35import java.util.Set;3637import sun.security.x509.X509CertImpl;3839/**40* This class checks if Symantec issued TLS Server certificates should be41* restricted.42*/43final class SymantecTLSPolicy {44private static final LocalDate DECEMBER_31_2019 =45LocalDate.of(2019, Month.DECEMBER, 31);46// SHA-256 certificate fingerprints of subCAs with later distrust dates47private static final Map<String, LocalDate> EXEMPT_SUBCAS = new HashMap();48static {49// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,50// CN=Apple IST CA 2 - G151// Issuer DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US52EXEMPT_SUBCAS.put("AC2B922ECFD5E01711772FEA8ED372DE9D1E2245FCE3F57A9CDBEC77296A424B",53DECEMBER_31_2019);545556// Subject DN: C=US, O=Apple Inc., OU=Certification Authority,57// CN=Apple IST CA 8 - G158// Issuer DN: CN=GeoTrust Primary Certification Authority - G2,59// OU=(c) 2007 GeoTrust Inc. - For authorized use only,60// O=GeoTrust Inc., C=US61EXEMPT_SUBCAS.put("A4FE7C7F15155F3F0AEF7AAA83CF6E06DEB97CA3F909DF920AC1490882D488ED",62DECEMBER_31_2019);63}6465// SHA-256 certificate fingerprints of distrusted roots66private static final Set<String> FINGERPRINTS = new HashSet<>(Arrays.asList(67// cacerts alias: geotrustglobalca68// DN: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US69"FF856A2D251DCD88D36656F450126798CFABAADE40799C722DE4D2B5DB36A73A",70// cacerts alias: geotrustprimaryca71// DN: CN=GeoTrust Primary Certification Authority,72// O=GeoTrust Inc., C=US73"37D51006C512EAAB626421F1EC8C92013FC5F82AE98EE533EB4619B8DEB4D06C",74// cacerts alias: geotrustprimarycag275// DN: CN=GeoTrust Primary Certification Authority - G2,76// OU=(c) 2007 GeoTrust Inc. - For authorized use only,77// O=GeoTrust Inc., C=US78"5EDB7AC43B82A06A8761E8D7BE4979EBF2611F7DD79BF91C1C6B566A219ED766",79// cacerts alias: geotrustprimarycag380// DN: CN=GeoTrust Primary Certification Authority - G3,81// OU=(c) 2008 GeoTrust Inc. - For authorized use only,82// O=GeoTrust Inc., C=US83"B478B812250DF878635C2AA7EC7D155EAA625EE82916E2CD294361886CD1FBD4",84// cacerts alias: geotrustuniversalca85// DN: CN=GeoTrust Universal CA, O=GeoTrust Inc., C=US86"A0459B9F63B22559F5FA5D4C6DB3F9F72FF19342033578F073BF1D1B46CBB912",87// cacerts alias: thawteprimaryrootca88// DN: CN=thawte Primary Root CA,89// OU="(c) 2006 thawte, Inc. - For authorized use only",90// OU=Certification Services Division, O="thawte, Inc.", C=US91"8D722F81A9C113C0791DF136A2966DB26C950A971DB46B4199F4EA54B78BFB9F",92// cacerts alias: thawteprimaryrootcag293// DN: CN=thawte Primary Root CA - G2,94// OU="(c) 2007 thawte, Inc. - For authorized use only",95// O="thawte, Inc.", C=US96"A4310D50AF18A6447190372A86AFAF8B951FFB431D837F1E5688B45971ED1557",97// cacerts alias: thawteprimaryrootcag398// DN: CN=thawte Primary Root CA - G3,99// OU="(c) 2008 thawte, Inc. - For authorized use only",100// OU=Certification Services Division, O="thawte, Inc.", C=US101"4B03F45807AD70F21BFC2CAE71C9FDE4604C064CF5FFB686BAE5DBAAD7FDD34C",102// cacerts alias: thawtepremiumserverca103// DN: [email protected],104// CN=Thawte Premium Server CA, OU=Certification Services Division,105// O=Thawte Consulting cc, L=Cape Town, ST=Western Cape, C=ZA106"3F9F27D583204B9E09C8A3D2066C4B57D3A2479C3693650880505698105DBCE9",107// cacerts alias: verisignclass2g2ca108// DN: OU=VeriSign Trust Network,109// OU="(c) 1998 VeriSign, Inc. - For authorized use only",110// OU=Class 2 Public Primary Certification Authority - G2,111// O="VeriSign, Inc.", C=US112"3A43E220FE7F3EA9653D1E21742EAC2B75C20FD8980305BC502CAF8C2D9B41A1",113// cacerts alias: verisignclass3ca114// DN: OU=Class 3 Public Primary Certification Authority,115// O="VeriSign, Inc.", C=US116"A4B6B3996FC2F306B3FD8681BD63413D8C5009CC4FA329C2CCF0E2FA1B140305",117// cacerts alias: verisignclass3g2ca118// DN: OU=VeriSign Trust Network,119// OU="(c) 1998 VeriSign, Inc. - For authorized use only",120// OU=Class 3 Public Primary Certification Authority - G2,121// O="VeriSign, Inc.", C=US122"83CE3C1229688A593D485F81973C0F9195431EDA37CC5E36430E79C7A888638B",123// cacerts alias: verisignclass3g3ca124// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G3,125// OU="(c) 1999 VeriSign, Inc. - For authorized use only",126// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US127"EB04CF5EB1F39AFA762F2BB120F296CBA520C1B97DB1589565B81CB9A17B7244",128// cacerts alias: verisignclass3g4ca129// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G4,130// OU="(c) 2007 VeriSign, Inc. - For authorized use only",131// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US132"69DDD7EA90BB57C93E135DC85EA6FCD5480B603239BDC454FC758B2A26CF7F79",133// cacerts alias: verisignclass3g5ca134// DN: CN=VeriSign Class 3 Public Primary Certification Authority - G5,135// OU="(c) 2006 VeriSign, Inc. - For authorized use only",136// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US137"9ACFAB7E43C8D880D06B262A94DEEEE4B4659989C3D0CAF19BAF6405E41AB7DF",138// cacerts alias: verisignuniversalrootca139// DN: CN=VeriSign Universal Root Certification Authority,140// OU="(c) 2008 VeriSign, Inc. - For authorized use only",141// OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US142"2399561127A57125DE8CEFEA610DDF2FA078B5C8067F4E828290BFB860E84B3C"143));144145// Any TLS Server certificate that is anchored by one of the Symantec146// roots above and is issued after this date will be distrusted.147private static final LocalDate APRIL_16_2019 =148LocalDate.of(2019, Month.APRIL, 16);149150/**151* This method assumes the eeCert is a TLS Server Cert and chains back to152* the anchor.153*154* @param chain the end-entity's certificate chain. The end entity cert155* is at index 0, the trust anchor at index n-1.156* @throws ValidatorException if the certificate is distrusted157*/158static void checkDistrust(X509Certificate[] chain)159throws ValidatorException {160X509Certificate anchor = chain[chain.length-1];161if (FINGERPRINTS.contains(fingerprint(anchor))) {162Date notBefore = chain[0].getNotBefore();163LocalDate ldNotBefore = notBefore.toInstant().atZone(ZoneOffset.UTC).toLocalDate();164165// check if chain goes through one of the subCAs166if (chain.length > 2) {167X509Certificate subCA = chain[chain.length - 2];168LocalDate distrustDate = EXEMPT_SUBCAS.get(fingerprint(subCA));169if (distrustDate != null) {170// reject if certificate is issued after specified date171checkNotBefore(ldNotBefore, distrustDate, anchor);172return; // success173}174}175// reject if certificate is issued after April 16, 2019176checkNotBefore(ldNotBefore, APRIL_16_2019, anchor);177}178}179180private static String fingerprint(X509Certificate cert) {181return (cert instanceof X509CertImpl)182? ((X509CertImpl)cert).getFingerprint("SHA-256")183: X509CertImpl.getFingerprint("SHA-256", cert);184}185186private static void checkNotBefore(LocalDate notBeforeDate,187LocalDate distrustDate, X509Certificate anchor)188throws ValidatorException {189if (notBeforeDate.isAfter(distrustDate)) {190throw new ValidatorException191("TLS Server certificate issued after " + distrustDate +192" and anchored by a distrusted legacy Symantec root CA: "193+ anchor.getSubjectX500Principal(),194ValidatorException.T_UNTRUSTED_CERT, anchor);195}196}197private SymantecTLSPolicy() {}198}199200201