Path: blob/master/src/java.base/share/classes/sun/security/provider/certpath/CertPathConstraintsParameters.java
41161 views
/*1* Copyright (c) 2020, 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*/2425package sun.security.provider.certpath;2627import java.security.Key;28import java.security.cert.TrustAnchor;29import java.security.cert.X509Certificate;30import java.util.Date;31import java.util.Set;3233import sun.security.util.ConstraintsParameters;34import sun.security.validator.Validator;3536/**37* This class contains parameters for checking certificates against38* constraints specified in the jdk.certpath.disabledAlgorithms security39* property.40*/41class CertPathConstraintsParameters implements ConstraintsParameters {42// The public key of the certificate43private final Key key;44// The certificate's trust anchor which will be checked against the45// jdkCA constraint, if specified.46private final TrustAnchor anchor;47// The PKIXParameter validity date or the timestamp of the signed JAR48// file, if this chain is associated with a timestamped signed JAR.49private final Date date;50// The variant or usage of this certificate51private final String variant;52// The certificate being checked (may be null if a CRL or OCSPResponse is53// being checked)54private final X509Certificate cert;5556public CertPathConstraintsParameters(X509Certificate cert,57String variant, TrustAnchor anchor, Date date) {58this(cert.getPublicKey(), variant, anchor, date, cert);59}6061public CertPathConstraintsParameters(Key key, String variant,62TrustAnchor anchor) {63this(key, variant, anchor, null, null);64}6566private CertPathConstraintsParameters(Key key, String variant,67TrustAnchor anchor, Date date, X509Certificate cert) {68this.key = key;69this.variant = (variant == null ? Validator.VAR_GENERIC : variant);70this.anchor = anchor;71this.date = date;72this.cert = cert;73}7475@Override76public boolean anchorIsJdkCA() {77return CertPathHelper.isJdkCA(anchor);78}7980@Override81public Set<Key> getKeys() {82return (key == null) ? Set.of() : Set.of(key);83}8485@Override86public Date getDate() {87return date;88}8990@Override91public String getVariant() {92return variant;93}9495@Override96public String extendedExceptionMsg() {97return (cert == null ? "."98: " used with certificate: " +99cert.getSubjectX500Principal());100}101102@Override103public String toString() {104StringBuilder sb = new StringBuilder("[\n");105sb.append("\n Variant: ").append(variant);106if (anchor != null) {107sb.append("\n Anchor: ").append(anchor);108}109if (cert != null) {110sb.append("\n Cert Issuer: ")111.append(cert.getIssuerX500Principal());112sb.append("\n Cert Subject: ")113.append(cert.getSubjectX500Principal());114}115if (key != null) {116sb.append("\n Key: ").append(key.getAlgorithm());117}118if (date != null) {119sb.append("\n Date: ").append(date);120}121sb.append("\n]");122return sb.toString();123}124}125126127