jdk/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 42357 bd44ffcd570f
child 43807 82f979ff031f
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
     1
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
     2
 * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
     4
 *
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4190
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4190
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    10
 *
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    15
 * accompanied this code).
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    16
 *
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4190
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4190
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4190
diff changeset
    23
 * questions.
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    24
 */
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    25
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    26
package sun.security.provider.certpath;
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    27
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    28
import java.security.AlgorithmConstraints;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    29
import java.security.CryptoPrimitive;
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
    30
import java.security.Timestamp;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
    31
import java.security.cert.CertPathValidator;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    32
import java.util.Collection;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    33
import java.util.Collections;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    34
import java.util.Date;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    35
import java.util.Set;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    36
import java.util.EnumSet;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    37
import java.math.BigInteger;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    38
import java.security.PublicKey;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    39
import java.security.KeyFactory;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    40
import java.security.AlgorithmParameters;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    41
import java.security.GeneralSecurityException;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    42
import java.security.cert.Certificate;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    43
import java.security.cert.X509CRL;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    44
import java.security.cert.X509Certificate;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    45
import java.security.cert.PKIXCertPathChecker;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    46
import java.security.cert.TrustAnchor;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    47
import java.security.cert.CRLException;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    48
import java.security.cert.CertificateException;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    49
import java.security.cert.CertPathValidatorException;
8163
d9bcc1208691 7011497: new CertPathValidatorException.BasicReason enum constant for constrained algorithm
xuelei
parents: 7040
diff changeset
    50
import java.security.cert.CertPathValidatorException.BasicReason;
d9bcc1208691 7011497: new CertPathValidatorException.BasicReason enum constant for constrained algorithm
xuelei
parents: 7040
diff changeset
    51
import java.security.cert.PKIXReason;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
    52
import java.security.interfaces.DSAParams;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
    53
import java.security.interfaces.DSAPublicKey;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
    54
import java.security.spec.DSAPublicKeySpec;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    55
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
    56
import sun.security.util.AnchorCertificates;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
    57
import sun.security.util.ConstraintsParameters;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
    58
import sun.security.util.Debug;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    59
import sun.security.util.DisabledAlgorithmConstraints;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
    60
import sun.security.validator.Validator;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    61
import sun.security.x509.X509CertImpl;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    62
import sun.security.x509.X509CRLImpl;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    63
import sun.security.x509.AlgorithmId;
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    64
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    65
/**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    66
 * A {@code PKIXCertPathChecker} implementation to check whether a
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    67
 * specified certificate contains the required algorithm constraints.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    68
 * <p>
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    69
 * Certificate fields such as the subject public key, the signature
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    70
 * algorithm, key usage, extended key usage, etc. need to conform to
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    71
 * the specified algorithm constraints.
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    72
 *
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    73
 * @see PKIXCertPathChecker
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    74
 * @see PKIXParameters
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    75
 */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    76
public final class AlgorithmChecker extends PKIXCertPathChecker {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
    77
    private static final Debug debug = Debug.getInstance("certpath");
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    78
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    79
    private final AlgorithmConstraints constraints;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    80
    private final PublicKey trustedPubKey;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    81
    private final Date pkixdate;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    82
    private PublicKey prevPubKey;
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
    83
    private final Timestamp jarTimestamp;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
    84
    private final String variant;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    85
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    86
    private static final Set<CryptoPrimitive> SIGNATURE_PRIMITIVE_SET =
23897
911b1eb93667 8029745: Enhance algorithm checking
juh
parents: 13806
diff changeset
    87
        Collections.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE));
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    88
33297
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    89
    private static final Set<CryptoPrimitive> KU_PRIMITIVE_SET =
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    90
        Collections.unmodifiableSet(EnumSet.of(
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    91
            CryptoPrimitive.SIGNATURE,
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    92
            CryptoPrimitive.KEY_ENCAPSULATION,
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    93
            CryptoPrimitive.PUBLIC_KEY_ENCRYPTION,
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    94
            CryptoPrimitive.KEY_AGREEMENT));
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
    95
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    96
    private static final DisabledAlgorithmConstraints
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    97
        certPathDefaultConstraints = new DisabledAlgorithmConstraints(
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    98
            DisabledAlgorithmConstraints.PROPERTY_CERTPATH_DISABLED_ALGS);
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
    99
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   100
    // If there is no "cacerts" keyword, then disable anchor checking
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   101
    private static final boolean publicCALimits =
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   102
            certPathDefaultConstraints.checkProperty("jdkCA");
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   103
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   104
    // If anchor checking enabled, this will be true if the trust anchor
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   105
    // has a match in the cacerts file
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   106
    private boolean trustedMatch = false;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   107
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   108
    /**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   109
     * Create a new {@code AlgorithmChecker} with the algorithm
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   110
     * constraints specified in security property
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   111
     * "jdk.certpath.disabledAlgorithms".
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   112
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   113
     * @param anchor the trust anchor selected to validate the target
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   114
     *     certificate
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   115
     * @param variant is the Validator variants of the operation. A null value
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   116
     *                passed will set it to Validator.GENERIC.
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   117
     */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   118
    public AlgorithmChecker(TrustAnchor anchor, String variant) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   119
        this(anchor, certPathDefaultConstraints, null, variant);
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   120
    }
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   121
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   122
    /**
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   123
     * Create a new {@code AlgorithmChecker} with the given
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   124
     * {@code AlgorithmConstraints}, {@code Timestamp}, and/or {@code Variant}.
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   125
     * <p>
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   126
     * Note that this constructor can initialize a variation of situations where
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   127
     * the AlgorithmConstraints, Timestamp, or Variant maybe known.
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   128
     *
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   129
     * @param constraints the algorithm constraints (or null)
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   130
     * @param jarTimestamp Timestamp passed for JAR timestamp constraint
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   131
     *                     checking. Set to null if not applicable.
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   132
     * @param variant is the Validator variants of the operation. A null value
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   133
     *                passed will set it to Validator.GENERIC.
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   134
     */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   135
    public AlgorithmChecker(AlgorithmConstraints constraints,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   136
            Timestamp jarTimestamp, String variant) {
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   137
        this.prevPubKey = null;
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   138
        this.trustedPubKey = null;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   139
        this.constraints = (constraints == null ? certPathDefaultConstraints :
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   140
                constraints);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   141
        this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   142
                null);
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   143
        this.jarTimestamp = jarTimestamp;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   144
        this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   145
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   146
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   147
    /**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   148
     * Create a new {@code AlgorithmChecker} with the
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   149
     * given {@code TrustAnchor} and {@code AlgorithmConstraints}.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   150
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   151
     * @param anchor the trust anchor selected to validate the target
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   152
     *     certificate
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   153
     * @param constraints the algorithm constraints (or null)
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   154
     * @param pkixdate Date the constraints are checked against. The value is
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   155
     *             either the PKIXParameter date or null for the current date.
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   156
     * @param variant is the Validator variants of the operation. A null value
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   157
     *                passed will set it to Validator.GENERIC.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   158
     *
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   159
     * @throws IllegalArgumentException if the {@code anchor} is null
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   160
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   161
    public AlgorithmChecker(TrustAnchor anchor,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   162
            AlgorithmConstraints constraints, Date pkixdate, String variant) {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   163
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   164
        if (anchor != null) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   165
            if (anchor.getTrustedCert() != null) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   166
                this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   167
                // Check for anchor certificate restrictions
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   168
                trustedMatch = checkFingerprint(anchor.getTrustedCert());
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   169
                if (trustedMatch && debug != null) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   170
                    debug.println("trustedMatch = true");
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   171
                }
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   172
            } else {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   173
                this.trustedPubKey = anchor.getCAPublicKey();
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   174
            }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   175
        } else {
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   176
            this.trustedPubKey = null;
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   177
            if (debug != null) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   178
                debug.println("TrustAnchor is null, trustedMatch is false.");
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 39465
diff changeset
   179
            }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   180
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   181
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   182
        this.prevPubKey = trustedPubKey;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   183
        this.constraints = constraints;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   184
        this.pkixdate = pkixdate;
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   185
        this.jarTimestamp = null;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   186
        this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   187
    }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   188
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   189
    /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   190
     * Create a new {@code AlgorithmChecker} with the
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   191
     * given {@code TrustAnchor} and {@code PKIXParameter} date.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   192
     *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   193
     * @param anchor the trust anchor selected to validate the target
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   194
     *     certificate
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   195
     * @param pkixdate Date the constraints are checked against. The value is
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   196
     *             either the PKIXParameter date or null for the current date.
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   197
     * @param variant is the Validator variants of the operation. A null value
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   198
     *                passed will set it to Validator.GENERIC.
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   199
     *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   200
     * @throws IllegalArgumentException if the {@code anchor} is null
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   201
     */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   202
    public AlgorithmChecker(TrustAnchor anchor, Date pkixdate, String variant) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   203
        this(anchor, certPathDefaultConstraints, pkixdate, variant);
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   204
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   205
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   206
    // Check this 'cert' for restrictions in the AnchorCertificates
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   207
    // trusted certificates list
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   208
    private static boolean checkFingerprint(X509Certificate cert) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   209
        if (!publicCALimits) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   210
            return false;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   211
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   212
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   213
        if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   214
            debug.println("AlgorithmChecker.contains: " + cert.getSigAlgName());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   215
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   216
        return AnchorCertificates.contains(cert);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   217
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   218
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   219
    Timestamp getJarTimestamp() {
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   220
        return jarTimestamp;
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   221
    }
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   222
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   223
    @Override
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   224
    public void init(boolean forward) throws CertPathValidatorException {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   225
        //  Note that this class does not support forward mode.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   226
        if (!forward) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   227
            if (trustedPubKey != null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   228
                prevPubKey = trustedPubKey;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   229
            } else {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   230
                prevPubKey = null;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   231
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   232
        } else {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   233
            throw new
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   234
                CertPathValidatorException("forward checking not supported");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   235
        }
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   236
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   237
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   238
    @Override
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   239
    public boolean isForwardCheckingSupported() {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   240
        //  Note that as this class does not support forward mode, the method
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   241
        //  will always returns false.
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   242
        return false;
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   243
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   244
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   245
    @Override
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   246
    public Set<String> getSupportedExtensions() {
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   247
        return null;
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   248
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   249
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   250
    @Override
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   251
    public void check(Certificate cert,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   252
            Collection<String> unresolvedCritExts)
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   253
            throws CertPathValidatorException {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   254
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   255
        if (!(cert instanceof X509Certificate) || constraints == null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   256
            // ignore the check for non-x.509 certificate or null constraints
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   257
            return;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   258
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   259
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   260
        // check the key usage and key size
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   261
        boolean[] keyUsage = ((X509Certificate) cert).getKeyUsage();
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   262
        if (keyUsage != null && keyUsage.length < 9) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   263
            throw new CertPathValidatorException(
8163
d9bcc1208691 7011497: new CertPathValidatorException.BasicReason enum constant for constrained algorithm
xuelei
parents: 7040
diff changeset
   264
                "incorrect KeyUsage extension",
d9bcc1208691 7011497: new CertPathValidatorException.BasicReason enum constant for constrained algorithm
xuelei
parents: 7040
diff changeset
   265
                null, null, -1, PKIXReason.INVALID_KEY_USAGE);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   266
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   267
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   268
        X509CertImpl x509Cert;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   269
        AlgorithmId algorithmId;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   270
        try {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   271
            x509Cert = X509CertImpl.toImpl((X509Certificate)cert);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   272
            algorithmId = (AlgorithmId)x509Cert.get(X509CertImpl.SIG_ALG);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   273
        } catch (CertificateException ce) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   274
            throw new CertPathValidatorException(ce);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   275
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   276
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   277
        AlgorithmParameters currSigAlgParams = algorithmId.getParameters();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   278
        PublicKey currPubKey = cert.getPublicKey();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   279
        String currSigAlg = x509Cert.getSigAlgName();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   280
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   281
        // Check the signature algorithm and parameters against constraints.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   282
        if (!constraints.permits(SIGNATURE_PRIMITIVE_SET, currSigAlg,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   283
                currSigAlgParams)) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   284
            throw new CertPathValidatorException(
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   285
                    "Algorithm constraints check failed on signature " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   286
                            "algorithm: " + currSigAlg, null, null, -1,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   287
                    BasicReason.ALGORITHM_CONSTRAINED);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   288
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   289
33297
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   290
        // Assume all key usage bits are set if key usage is not present
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   291
        Set<CryptoPrimitive> primitives = KU_PRIMITIVE_SET;
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   292
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   293
        if (keyUsage != null) {
33297
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   294
                primitives = EnumSet.noneOf(CryptoPrimitive.class);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   295
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   296
            if (keyUsage[0] || keyUsage[1] || keyUsage[5] || keyUsage[6]) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   297
                // keyUsage[0]: KeyUsage.digitalSignature
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   298
                // keyUsage[1]: KeyUsage.nonRepudiation
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   299
                // keyUsage[5]: KeyUsage.keyCertSign
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   300
                // keyUsage[6]: KeyUsage.cRLSign
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   301
                primitives.add(CryptoPrimitive.SIGNATURE);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   302
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   303
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   304
            if (keyUsage[2]) {      // KeyUsage.keyEncipherment
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   305
                primitives.add(CryptoPrimitive.KEY_ENCAPSULATION);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   306
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   307
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   308
            if (keyUsage[3]) {      // KeyUsage.dataEncipherment
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   309
                primitives.add(CryptoPrimitive.PUBLIC_KEY_ENCRYPTION);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   310
            }
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   311
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   312
            if (keyUsage[4]) {      // KeyUsage.keyAgreement
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   313
                primitives.add(CryptoPrimitive.KEY_AGREEMENT);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   314
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   315
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   316
            // KeyUsage.encipherOnly and KeyUsage.decipherOnly are
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   317
            // undefined in the absence of the keyAgreement bit.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   318
33297
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   319
            if (primitives.isEmpty()) {
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   320
                throw new CertPathValidatorException(
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   321
                    "incorrect KeyUsage extension bits",
33297
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   322
                    null, null, -1, PKIXReason.INVALID_KEY_USAGE);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   323
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   324
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   325
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   326
        ConstraintsParameters cp =
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   327
                new ConstraintsParameters((X509Certificate)cert,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   328
                        trustedMatch, pkixdate, jarTimestamp, variant);
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   329
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   330
        // Check against local constraints if it is DisabledAlgorithmConstraints
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   331
        if (constraints instanceof DisabledAlgorithmConstraints) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   332
            ((DisabledAlgorithmConstraints)constraints).permits(currSigAlg, cp);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   333
            // DisabledAlgorithmsConstraints does not check primitives, so key
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   334
            // additional key check.
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   335
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   336
        } else {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   337
            // Perform the default constraints checking anyway.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   338
            certPathDefaultConstraints.permits(currSigAlg, cp);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   339
            // Call locally set constraints to check key with primitives.
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   340
            if (!constraints.permits(primitives, currPubKey)) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   341
                throw new CertPathValidatorException(
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   342
                        "Algorithm constraints check failed on key " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   343
                                currPubKey.getAlgorithm() + " with size of " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   344
                                sun.security.util.KeyUtil.getKeySize(currPubKey) +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   345
                                "bits",
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   346
                        null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   347
            }
33297
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   348
        }
5970d160cbc0 8131291: Perfect parameter patterning
vinnie
parents: 32649
diff changeset
   349
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   350
        // If there is no previous key, set one and exit
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   351
        if (prevPubKey == null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   352
            prevPubKey = currPubKey;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   353
            return;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   354
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   355
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   356
        // Check with previous cert for signature algorithm and public key
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   357
        if (!constraints.permits(
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   358
                SIGNATURE_PRIMITIVE_SET,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   359
                currSigAlg, prevPubKey, currSigAlgParams)) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   360
            throw new CertPathValidatorException(
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   361
                    "Algorithm constraints check failed on " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   362
                            "signature algorithm: " + currSigAlg,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   363
                    null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   364
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   365
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   366
        // Inherit key parameters from previous key
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   367
        if (PKIX.isDSAPublicKeyWithoutParams(currPubKey)) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   368
            // Inherit DSA parameters from previous key
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   369
            if (!(prevPubKey instanceof DSAPublicKey)) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   370
                throw new CertPathValidatorException("Input key is not " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   371
                        "of a appropriate type for inheriting parameters");
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   372
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   373
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   374
            DSAParams params = ((DSAPublicKey)prevPubKey).getParams();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   375
            if (params == null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   376
                throw new CertPathValidatorException(
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   377
                        "Key parameters missing from public key.");
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   378
            }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   379
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   380
            try {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   381
                BigInteger y = ((DSAPublicKey)currPubKey).getY();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   382
                KeyFactory kf = KeyFactory.getInstance("DSA");
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   383
                DSAPublicKeySpec ks = new DSAPublicKeySpec(y, params.getP(),
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   384
                        params.getQ(), params.getG());
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   385
                currPubKey = kf.generatePublic(ks);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   386
            } catch (GeneralSecurityException e) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   387
                throw new CertPathValidatorException("Unable to generate " +
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   388
                        "key with inherited parameters: " + e.getMessage(), e);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   389
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   390
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   391
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   392
        // reset the previous public key
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   393
        prevPubKey = currPubKey;
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   394
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   395
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   396
    /**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   397
     * Try to set the trust anchor of the checker.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   398
     * <p>
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   399
     * If there is no trust anchor specified and the checker has not started,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   400
     * set the trust anchor.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   401
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   402
     * @param anchor the trust anchor selected to validate the target
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   403
     *     certificate
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   404
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   405
    void trySetTrustAnchor(TrustAnchor anchor) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   406
        // Don't bother if the check has started or trust anchor has already
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   407
        // specified.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   408
        if (prevPubKey == null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   409
            if (anchor == null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   410
                throw new IllegalArgumentException(
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   411
                        "The trust anchor cannot be null");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   412
            }
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   413
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   414
            // Don't bother to change the trustedPubKey.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   415
            if (anchor.getTrustedCert() != null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   416
                prevPubKey = anchor.getTrustedCert().getPublicKey();
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   417
                // Check for anchor certificate restrictions
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   418
                trustedMatch = checkFingerprint(anchor.getTrustedCert());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   419
                if (trustedMatch && debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   420
                    debug.println("trustedMatch = true");
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 33297
diff changeset
   421
                }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   422
            } else {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   423
                prevPubKey = anchor.getCAPublicKey();
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   424
            }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   425
        }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   426
    }
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   427
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   428
    /**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   429
     * Check the signature algorithm with the specified public key.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   430
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   431
     * @param key the public key to verify the CRL signature
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   432
     * @param crl the target CRL
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   433
     * @param variant is the Validator variants of the operation. A null value
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   434
     *                passed will set it to Validator.GENERIC.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   435
     */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   436
    static void check(PublicKey key, X509CRL crl, String variant)
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   437
                        throws CertPathValidatorException {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   438
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   439
        X509CRLImpl x509CRLImpl = null;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   440
        try {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   441
            x509CRLImpl = X509CRLImpl.toImpl(crl);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   442
        } catch (CRLException ce) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   443
            throw new CertPathValidatorException(ce);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   444
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   445
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   446
        AlgorithmId algorithmId = x509CRLImpl.getSigAlgId();
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   447
        check(key, algorithmId, variant);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   448
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   449
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   450
    /**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   451
     * Check the signature algorithm with the specified public key.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   452
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   453
     * @param key the public key to verify the CRL signature
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   454
     * @param algorithmId signature algorithm Algorithm ID
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   455
     * @param variant is the Validator variants of the operation. A null value
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   456
     *                passed will set it to Validator.GENERIC.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   457
     */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   458
    static void check(PublicKey key, AlgorithmId algorithmId, String variant)
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   459
                        throws CertPathValidatorException {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   460
        String sigAlgName = algorithmId.getName();
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   461
        AlgorithmParameters sigAlgParams = algorithmId.getParameters();
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   462
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   463
        certPathDefaultConstraints.permits(new ConstraintsParameters(
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 42357
diff changeset
   464
                sigAlgName, sigAlgParams, key, variant));
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   465
    }
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents:
diff changeset
   466
}
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   467