Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/provider/certpath/CertPathConstraintsParameters.java
38923 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;32import java.util.Collections;3334import sun.security.util.ConstraintsParameters;35import sun.security.validator.Validator;3637/**38* This class contains parameters for checking certificates against39* constraints specified in the jdk.certpath.disabledAlgorithms security40* property.41*/42class CertPathConstraintsParameters implements ConstraintsParameters {43// The public key of the certificate44private final Key key;45// The certificate's trust anchor which will be checked against the46// jdkCA constraint, if specified.47private final TrustAnchor anchor;48// The PKIXParameter validity date or the timestamp of the signed JAR49// file, if this chain is associated with a timestamped signed JAR.50private final Date date;51// The variant or usage of this certificate52private final String variant;53// The certificate being checked (may be null if a CRL or OCSPResponse is54// being checked)55private final X509Certificate cert;5657public CertPathConstraintsParameters(X509Certificate cert,58String variant, TrustAnchor anchor, Date date) {59this(cert.getPublicKey(), variant, anchor, date, cert);60}6162public CertPathConstraintsParameters(Key key, String variant,63TrustAnchor anchor) {64this(key, variant, anchor, null, null);65}6667private CertPathConstraintsParameters(Key key, String variant,68TrustAnchor anchor, Date date, X509Certificate cert) {69this.key = key;70this.variant = (variant == null ? Validator.VAR_GENERIC : variant);71this.anchor = anchor;72this.date = date;73this.cert = cert;74}7576@Override77public boolean anchorIsJdkCA() {78return CertPathHelper.isJdkCA(anchor);79}8081@Override82public Set<Key> getKeys() {83return (key == null) ? Collections.emptySet()84: Collections.singleton(key);85}8687@Override88public Date getDate() {89return date;90}9192@Override93public String getVariant() {94return variant;95}9697@Override98public String extendedExceptionMsg() {99return (cert == null ? "."100: " used with certificate: " +101cert.getSubjectX500Principal());102}103104@Override105public String toString() {106StringBuilder sb = new StringBuilder("[\n");107sb.append("\n Variant: ").append(variant);108if (anchor != null) {109sb.append("\n Anchor: ").append(anchor);110}111if (cert != null) {112sb.append("\n Cert Issuer: ")113.append(cert.getIssuerX500Principal());114sb.append("\n Cert Subject: ")115.append(cert.getSubjectX500Principal());116}117if (key != null) {118sb.append("\n Key: ").append(key.getAlgorithm());119}120if (date != null) {121sb.append("\n Date: ").append(date);122}123sb.append("\n]");124return sb.toString();125}126}127128129