jdk/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java
author ascarpino
Thu, 26 May 2016 13:33:27 -0700
changeset 38576 ccaac80108c5
parent 37726 bbecfff95ec3
child 39465 8c06651d9138
permissions -rw-r--r--
8154005: Add algorithm constraint that specifies the restriction date Reviewed-by: mullan, igerasim
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     1
/*
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     4
 *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    10
 *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    15
 * accompanied this code).
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    16
 *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    20
 *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    23
 * questions.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    24
 */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    25
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    26
package sun.security.util;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    27
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    28
import java.security.CryptoPrimitive;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    29
import java.security.AlgorithmParameters;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    30
import java.security.Key;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    31
import java.security.cert.CertPathValidatorException;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    32
import java.security.cert.CertPathValidatorException.BasicReason;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    33
import java.security.cert.X509Certificate;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    34
import java.text.SimpleDateFormat;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    35
import java.util.Calendar;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    36
import java.util.Date;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    37
import java.util.HashMap;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    38
import java.util.HashSet;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    39
import java.util.Locale;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    40
import java.util.Map;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    41
import java.util.Set;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    42
import java.util.TimeZone;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    43
import java.util.regex.Pattern;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    44
import java.util.regex.Matcher;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    45
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    46
/**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    47
 * Algorithm constraints for disabled algorithms property
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    48
 *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    49
 * See the "jdk.certpath.disabledAlgorithms" specification in java.security
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    50
 * for the syntax of the disabled algorithm string.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    51
 */
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    52
public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    53
    private static final Debug debug = Debug.getInstance("certpath");
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    54
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    55
    // the known security property, jdk.certpath.disabledAlgorithms
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
    56
    public static final String PROPERTY_CERTPATH_DISABLED_ALGS =
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    57
            "jdk.certpath.disabledAlgorithms";
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    58
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    59
    // the known security property, jdk.tls.disabledAlgorithms
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
    60
    public static final String PROPERTY_TLS_DISABLED_ALGS =
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    61
            "jdk.tls.disabledAlgorithms";
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    62
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    63
    private final String[] disabledAlgorithms;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    64
    private final Constraints algorithmConstraints;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    65
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    66
    /**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    67
     * Initialize algorithm constraints with the specified security property.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    68
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    69
     * @param propertyName the security property name that define the disabled
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    70
     *        algorithm constraints
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    71
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    72
    public DisabledAlgorithmConstraints(String propertyName) {
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    73
        this(propertyName, new AlgorithmDecomposer());
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    74
    }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    75
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    76
    public DisabledAlgorithmConstraints(String propertyName,
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    77
            AlgorithmDecomposer decomposer) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    78
        super(decomposer);
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    79
        disabledAlgorithms = getAlgorithms(propertyName);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    80
        algorithmConstraints = new Constraints(disabledAlgorithms);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    81
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    82
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    83
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    84
     * This only checks if the algorithm has been completely disabled.  If
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    85
     * there are keysize or other limit, this method allow the algorithm.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    86
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    87
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
    88
    public final boolean permits(Set<CryptoPrimitive> primitives,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    89
            String algorithm, AlgorithmParameters parameters) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    90
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    91
        if (primitives == null || primitives.isEmpty()) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    92
            throw new IllegalArgumentException(
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    93
                        "No cryptographic primitive specified");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    94
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    95
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    96
        return checkAlgorithm(disabledAlgorithms, algorithm, decomposer);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    97
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    98
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
    99
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   100
     * Checks if the key algorithm has been disabled or constraints have been
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   101
     * placed on the key.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   102
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   103
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
   104
    public final boolean permits(Set<CryptoPrimitive> primitives, Key key) {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   105
        return checkConstraints(primitives, "", key, null);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   106
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   107
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   108
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   109
     * Checks if the key algorithm has been disabled or if constraints have
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   110
     * been placed on the key.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   111
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   112
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
   113
    public final boolean permits(Set<CryptoPrimitive> primitives,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   114
            String algorithm, Key key, AlgorithmParameters parameters) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   115
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   116
        if (algorithm == null || algorithm.length() == 0) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   117
            throw new IllegalArgumentException("No algorithm name specified");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   118
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   119
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   120
        return checkConstraints(primitives, algorithm, key, parameters);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   121
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   122
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   123
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   124
     * Check if a x509Certificate object is permitted.  Check if all
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   125
     * algorithms are allowed, certificate constraints, and the
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   126
     * public key against key constraints.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   127
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   128
     * Uses new style permit() which throws exceptions.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   129
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   130
    public final void permits(Set<CryptoPrimitive> primitives,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   131
            CertConstraintParameters cp) throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   132
        checkConstraints(primitives, cp);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   133
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   134
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   135
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   136
     * Check if Certificate object is within the constraints.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   137
     * Uses new style permit() which throws exceptions.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   138
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   139
    public final void permits(Set<CryptoPrimitive> primitives,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   140
            X509Certificate cert) throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   141
        checkConstraints(primitives, new CertConstraintParameters(cert));
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   142
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   143
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   144
    // Check if a string is contained inside the property
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   145
    public boolean checkProperty(String param) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   146
        param = param.toLowerCase(Locale.ENGLISH);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   147
        for (String block : disabledAlgorithms) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   148
            if (block.toLowerCase(Locale.ENGLISH).indexOf(param) >= 0) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   149
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   150
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   151
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   152
        return false;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   153
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   154
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   155
    // Check algorithm constraints with key and algorithm
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   156
    private boolean checkConstraints(Set<CryptoPrimitive> primitives,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   157
            String algorithm, Key key, AlgorithmParameters parameters) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   158
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   159
        // check the key parameter, it cannot be null.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   160
        if (key == null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   161
            throw new IllegalArgumentException("The key cannot be null");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   162
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   163
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   164
        // check the signature algorithm
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   165
        if (algorithm != null && algorithm.length() != 0) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   166
            if (!permits(primitives, algorithm, parameters)) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   167
                return false;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   168
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   169
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   170
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   171
        // check the key algorithm
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   172
        if (!permits(primitives, key.getAlgorithm(), null)) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   173
            return false;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   174
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   175
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   176
        // check the key constraints
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   177
        return algorithmConstraints.permits(key);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   178
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   179
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   180
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   181
     * Check algorithm constraints with Certificate
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   182
     * Uses new style permit() which throws exceptions.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   183
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   184
    private void checkConstraints(Set<CryptoPrimitive> primitives,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   185
            CertConstraintParameters cp) throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   186
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   187
        X509Certificate cert = cp.getCertificate();
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   188
        String algorithm = cert.getSigAlgName();
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   189
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   190
        // Check signature algorithm is not disabled
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   191
        if (!permits(primitives, algorithm, null)) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   192
            throw new CertPathValidatorException(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   193
                    "Algorithm constraints check failed on disabled "+
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   194
                            "signature algorithm: " + algorithm,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   195
                    null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   196
        }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   197
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   198
        // Check key algorithm is not disabled
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   199
        if (!permits(primitives, cert.getPublicKey().getAlgorithm(), null)) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   200
            throw new CertPathValidatorException(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   201
                    "Algorithm constraints check failed on disabled "+
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   202
                            "public key algorithm: " + algorithm,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   203
                    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: 32649
diff changeset
   204
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   205
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   206
        // Check the certificate and key constraints
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   207
        algorithmConstraints.permits(cp);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   208
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   209
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   210
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   211
    /**
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   212
     * Key and Certificate Constraints
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   213
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   214
     * The complete disabling of an algorithm is not handled by Constraints or
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   215
     * Constraint classes.  That is addressed with
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   216
     *   permit(Set<CryptoPrimitive>, String, AlgorithmParameters)
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   217
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   218
     * When passing a Key to permit(), the boolean return values follow the
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   219
     * same as the interface class AlgorithmConstraints.permit().  This is to
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   220
     * maintain compatibility:
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   221
     * 'true' means the operation is allowed.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   222
     * 'false' means it failed the constraints and is disallowed.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   223
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   224
     * When passing CertConstraintParameters through permit(), an exception
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   225
     * will be thrown on a failure to better identify why the operation was
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   226
     * disallowed.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   227
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   228
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   229
    private static class Constraints {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   230
        private Map<String, Set<Constraint>> constraintsMap = new HashMap<>();
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   231
        private static final Pattern keySizePattern = Pattern.compile(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   232
                "keySize\\s*(<=|<|==|!=|>|>=)\\s*(\\d+)");
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   233
        private static final Pattern denyAfterPattern = Pattern.compile(
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   234
                "denyAfter\\s+(\\d{4})-(\\d{2})-(\\d{2})");
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   235
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   236
        public Constraints(String[] constraintArray) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   237
            for (String constraintEntry : constraintArray) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   238
                if (constraintEntry == null || constraintEntry.isEmpty()) {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   239
                    continue;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   240
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   241
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   242
                constraintEntry = constraintEntry.trim();
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   243
                if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   244
                    debug.println("Constraints: " + constraintEntry);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   245
                }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   246
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   247
                // Check if constraint is a complete disabling of an
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   248
                // algorithm or has conditions.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   249
                String algorithm;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   250
                String policy;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   251
                int space = constraintEntry.indexOf(' ');
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   252
                if (space > 0) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   253
                    algorithm = AlgorithmDecomposer.hashName(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   254
                            constraintEntry.substring(0, space).
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   255
                                    toUpperCase(Locale.ENGLISH));
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   256
                    policy = constraintEntry.substring(space + 1);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   257
                } else {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   258
                    constraintsMap.computeIfAbsent(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   259
                            constraintEntry.toUpperCase(Locale.ENGLISH),
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   260
                            k -> new HashSet<>());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   261
                    continue;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   262
                }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   263
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   264
                // Convert constraint conditions into Constraint classes
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   265
                Constraint c, lastConstraint = null;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   266
                // Allow only one jdkCA entry per constraint entry
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   267
                boolean jdkCALimit = false;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   268
                // Allow only one denyAfter entry per constraint entry
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   269
                boolean denyAfterLimit = false;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   270
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   271
                for (String entry : policy.split("&")) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   272
                    entry = entry.trim();
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   273
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   274
                    Matcher matcher = keySizePattern.matcher(entry);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   275
                    if (matcher.matches()) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   276
                        if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   277
                            debug.println("Constraints set to keySize: " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   278
                                    entry);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   279
                        }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   280
                        c = new KeySizeConstraint(algorithm,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   281
                                KeySizeConstraint.Operator.of(matcher.group(1)),
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   282
                                Integer.parseInt(matcher.group(2)));
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   283
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   284
                    } else if (entry.equalsIgnoreCase("jdkCA")) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   285
                        if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   286
                            debug.println("Constraints set to jdkCA.");
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   287
                        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   288
                        if (jdkCALimit) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   289
                            throw new IllegalArgumentException("Only one " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   290
                                    "jdkCA entry allowed in property. " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   291
                                    "Constraint: " + constraintEntry);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   292
                        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   293
                        c = new jdkCAConstraint(algorithm);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   294
                        jdkCALimit = true;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   295
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   296
                    } else if(matcher.usePattern(denyAfterPattern).matches()) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   297
                        if (debug != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   298
                            debug.println("Constraints set to denyAfter");
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   299
                        }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   300
                        if (denyAfterLimit) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   301
                            throw new IllegalArgumentException("Only one " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   302
                                    "denyAfter entry allowed in property. " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   303
                                    "Constraint: " + constraintEntry);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   304
                        }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   305
                        int year = Integer.parseInt(matcher.group(1));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   306
                        int month = Integer.parseInt(matcher.group(2));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   307
                        int day = Integer.parseInt(matcher.group(3));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   308
                        c = new DenyAfterConstraint(algorithm, year, month,
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   309
                                day);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   310
                        denyAfterLimit = true;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   311
                    } else {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   312
                        throw new IllegalArgumentException("Error in security" +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   313
                                " property. Constraint unknown: " + entry);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   314
                    }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   315
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   316
                    // Link multiple conditions for a single constraint
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   317
                    // into a linked list.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   318
                    if (lastConstraint == null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   319
                        if (!constraintsMap.containsKey(algorithm)) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   320
                            constraintsMap.putIfAbsent(algorithm,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   321
                                    new HashSet<>());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   322
                        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   323
                        constraintsMap.get(algorithm).add(c);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   324
                    } else {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   325
                        lastConstraint.nextConstraint = c;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   326
                    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   327
                    lastConstraint = c;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   328
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   329
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   330
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   331
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   332
        // Get applicable constraints based off the signature algorithm
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   333
        private Set<Constraint> getConstraints(String algorithm) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   334
            return constraintsMap.get(algorithm);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   335
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   336
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   337
        // Check if KeySizeConstraints permit the specified key
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   338
        public boolean permits(Key key) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   339
            Set<Constraint> set = getConstraints(key.getAlgorithm());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   340
            if (set == null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   341
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   342
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   343
            for (Constraint constraint : set) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   344
                if (!constraint.permits(key)) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   345
                    if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   346
                        debug.println("keySizeConstraint: failed key " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   347
                                "constraint check " + KeyUtil.getKeySize(key));
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   348
                    }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   349
                    return false;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   350
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   351
            }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   352
            return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   353
        }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   354
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   355
        // Check if constraints permit this cert.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   356
        public void permits(CertConstraintParameters cp)
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   357
                throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   358
            X509Certificate cert = cp.getCertificate();
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   359
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   360
            if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   361
                debug.println("Constraints.permits(): " + cert.getSigAlgName());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   362
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   363
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   364
            // Get all signature algorithms to check for constraints
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   365
            Set<String> algorithms =
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   366
                    AlgorithmDecomposer.decomposeOneHash(cert.getSigAlgName());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   367
            if (algorithms == null || algorithms.isEmpty()) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   368
                return;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   369
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   370
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   371
            // Attempt to add the public key algorithm to the set
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   372
            algorithms.add(cert.getPublicKey().getAlgorithm());
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   373
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   374
            // Check all applicable constraints
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   375
            for (String algorithm : algorithms) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   376
                Set<Constraint> set = getConstraints(algorithm);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   377
                if (set == null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   378
                    continue;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   379
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   380
                for (Constraint constraint : set) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   381
                    constraint.permits(cp);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   382
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   383
            }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   384
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   385
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   386
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   387
    /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   388
     * This abstract Constraint class for algorithm-based checking
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   389
     * may contain one or more constraints.  If the '&' on the {@Security}
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   390
     * property is used, multiple constraints have been grouped together
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   391
     * requiring all the constraints to fail for the check to be disallowed.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   392
     *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   393
     * If the class contains multiple constraints, the next constraint
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   394
     * is stored in {@code nextConstraint} in linked-list fashion.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   395
     */
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   396
    private abstract static class Constraint {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   397
        String algorithm;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   398
        Constraint nextConstraint = null;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   399
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   400
        // operator
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   401
        enum Operator {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   402
            EQ,         // "=="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   403
            NE,         // "!="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   404
            LT,         // "<"
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   405
            LE,         // "<="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   406
            GT,         // ">"
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   407
            GE;         // ">="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   408
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   409
            static Operator of(String s) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   410
                switch (s) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   411
                    case "==":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   412
                        return EQ;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   413
                    case "!=":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   414
                        return NE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   415
                    case "<":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   416
                        return LT;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   417
                    case "<=":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   418
                        return LE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   419
                    case ">":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   420
                        return GT;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   421
                    case ">=":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   422
                        return GE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   423
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   424
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   425
                throw new IllegalArgumentException("Error in security " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   426
                        "property. " + s + " is not a legal Operator");
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   427
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   428
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   429
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   430
        /**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   431
         * Check if an algorithm constraint is permitted with a given key.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   432
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   433
         * If the check inside of {@code permit()} fails, it must call
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   434
         * {@code next()} with the same {@code Key} parameter passed if
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   435
         * multiple constraints need to be checked.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   436
         *
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   437
         * @param key Public key
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   438
         * @return 'true' if constraint is allowed, 'false' if disallowed.
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   439
         */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   440
        public boolean permits(Key key) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   441
            return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   442
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   443
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   444
        /**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   445
         * Check if an algorithm constraint is permitted with a given
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   446
         * CertConstraintParameters.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   447
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   448
         * If the check inside of {@code permits()} fails, it must call
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   449
         * {@code next()} with the same {@code CertConstraintParameters}
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   450
         * parameter passed if multiple constraints need to be checked.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   451
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   452
         * @param cp CertConstraintParameter containing certificate info
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   453
         * @throws CertPathValidatorException if constraint disallows.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   454
         *
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   455
         */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   456
        public abstract void permits(CertConstraintParameters cp)
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   457
                throws CertPathValidatorException;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   458
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   459
        /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   460
         * Recursively check if the constraints are allowed.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   461
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   462
         * If {@code nextConstraint} is non-null, this method will
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   463
         * call {@code nextConstraint}'s {@code permits()} to check if the
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   464
         * constraint is allowed or denied.  If the constraint's
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   465
         * {@code permits()} is allowed, this method will exit this and any
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   466
         * recursive next() calls, returning 'true'.  If the constraints called
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   467
         * were disallowed, the last constraint will throw
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   468
         * {@code CertPathValidatorException}.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   469
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   470
         * @param cp CertConstraintParameters
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   471
         * @return 'true' if constraint allows the operation, 'false' if
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   472
         * we are at the end of the constraint list or,
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   473
         * {@code nextConstraint} is null.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   474
         */
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   475
        boolean next(CertConstraintParameters cp)
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   476
                throws CertPathValidatorException {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   477
            if (nextConstraint != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   478
                nextConstraint.permits(cp);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   479
                return true;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   480
            }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   481
            return false;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   482
        }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   483
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   484
        /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   485
         * Recursively check if this constraint is allowed,
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   486
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   487
         * If {@code nextConstraint} is non-null, this method will
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   488
         * call {@code nextConstraint}'s {@code permit()} to check if the
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   489
         * constraint is allowed or denied.  If the constraint's
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   490
         * {@code permit()} is allowed, this method will exit this and any
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   491
         * recursive next() calls, returning 'true'.  If the constraints
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   492
         * called were disallowed the check will exit with 'false'.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   493
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   494
         * @param key Public key
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   495
         * @return 'true' if constraint allows the operation, 'false' if
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   496
         * the constraint denies the operation.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   497
         */
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   498
        boolean next(Key key) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   499
            if (nextConstraint != null && nextConstraint.permits(key)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   500
                return true;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   501
            }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   502
            return false;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   503
        }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   504
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   505
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   506
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   507
     * This class contains constraints dealing with the certificate chain
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   508
     * of the certificate.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   509
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   510
    private static class jdkCAConstraint extends Constraint {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   511
        jdkCAConstraint(String algo) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   512
            algorithm = algo;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   513
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   514
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   515
        /*
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   516
         * Check if CertConstraintParameters has a trusted match, if it does
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   517
         * call next() for any following constraints. If it does not, exit
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   518
         * as this constraint(s) does not restrict the operation.
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   519
         */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   520
        public void permits(CertConstraintParameters cp)
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   521
                throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   522
            if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   523
                debug.println("jdkCAConstraints.permits(): " + algorithm);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   524
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   525
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   526
            // Check chain has a trust anchor in cacerts
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   527
            if (cp.isTrustedMatch()) {
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   528
                if (next(cp)) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   529
                    return;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   530
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   531
                throw new CertPathValidatorException(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   532
                        "Algorithm constraints check failed on certificate " +
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   533
                                "anchor limits",
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   534
                        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: 32649
diff changeset
   535
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   536
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   537
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   538
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   539
    /*
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   540
     * This class handles the denyAfter constraint.  The date is in the UTC/GMT
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   541
     * timezone.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   542
     */
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   543
     private static class DenyAfterConstraint extends Constraint {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   544
         private Date denyAfterDate;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   545
         private static final SimpleDateFormat dateFormat =
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   546
                 new SimpleDateFormat("EEE, MMM d HH:mm:ss z YYYY");
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   547
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   548
         DenyAfterConstraint(String algo, int year, int month, int day) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   549
             Calendar c;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   550
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   551
             algorithm = algo;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   552
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   553
             if (debug != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   554
                 debug.println("DenyAfterConstraint read in as:  year " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   555
                         year + ", month = " + month + ", day = " + day);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   556
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   557
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   558
             c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT"))
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   559
                     .setDate(year, month - 1, day).build();
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   560
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   561
             if (year > c.getActualMaximum(Calendar.YEAR) ||
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   562
                     year < c.getActualMinimum(Calendar.YEAR)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   563
                 throw new IllegalArgumentException(
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   564
                         "Invalid year given in constraint: " + year);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   565
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   566
             if ((month - 1) > c.getActualMaximum(Calendar.MONTH) ||
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   567
                     (month - 1) < c.getActualMinimum(Calendar.MONTH)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   568
                 throw new IllegalArgumentException(
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   569
                         "Invalid month given in constraint: " + month);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   570
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   571
             if (day > c.getActualMaximum(Calendar.DAY_OF_MONTH) ||
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   572
                     day < c.getActualMinimum(Calendar.DAY_OF_MONTH)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   573
                 throw new IllegalArgumentException(
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   574
                         "Invalid Day of Month given in constraint: " + day);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   575
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   577
             denyAfterDate = c.getTime();
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   578
             if (debug != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   579
                 debug.println("DenyAfterConstraint date set to: " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   580
                         dateFormat.format(denyAfterDate));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   581
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   582
         }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   583
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   584
         /*
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   585
          * Checking that the provided date is not beyond the constraint date.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   586
          * The provided date can be the PKIXParameter date if given,
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   587
          * otherwise it is the current date.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   588
          *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   589
          * If the constraint disallows, call next() for any following
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   590
          * constraints. Throw an exception if this is the last constraint.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   591
          */
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   592
         @Override
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   593
         public void permits(CertConstraintParameters cp)
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   594
                 throws CertPathValidatorException {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   595
             Date currentDate;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   596
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   597
             if (cp.getPKIXParamDate() != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   598
                 currentDate = cp.getPKIXParamDate();
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   599
             } else {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   600
                 currentDate = new Date();
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   601
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   602
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   603
             if (!denyAfterDate.after(currentDate)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   604
                 if (next(cp)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   605
                     return;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   606
                 }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   607
                 throw new CertPathValidatorException(
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   608
                         "denyAfter constraint check failed.  " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   609
                                 "Constraint date: " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   610
                                 dateFormat.format(denyAfterDate) +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   611
                                 "; Cert date: " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   612
                                 dateFormat.format(currentDate),
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   613
                          null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   614
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   615
         }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   616
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   617
         /*
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   618
          * Return result if the constraint's date is beyond the current date
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   619
          * in UTC timezone.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   620
          */
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   621
         public boolean permits(Key key) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   622
             if (next(key)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   623
                 return true;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   624
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   625
             if (debug != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   626
                 debug.println("DenyAfterConstraints.permits(): " + algorithm);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   627
             }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   628
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   629
             return denyAfterDate.after(new Date());
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   630
         }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   631
     }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   632
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   633
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   634
     * This class contains constraints dealing with the key size
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   635
     * support limits per algorithm.   e.g.  "keySize <= 1024"
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   636
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   637
    private static class KeySizeConstraint extends Constraint {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   638
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   639
        private int minSize;            // the minimal available key size
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   640
        private int maxSize;            // the maximal available key size
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   641
        private int prohibitedSize = -1;    // unavailable key sizes
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   642
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   643
        public KeySizeConstraint(String algo, Operator operator, int length) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   644
            algorithm = algo;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   645
            switch (operator) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   646
                case EQ:      // an unavailable key size
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   647
                    this.minSize = 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   648
                    this.maxSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   649
                    prohibitedSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   650
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   651
                case NE:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   652
                    this.minSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   653
                    this.maxSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   654
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   655
                case LT:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   656
                    this.minSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   657
                    this.maxSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   658
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   659
                case LE:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   660
                    this.minSize = length + 1;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   661
                    this.maxSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   662
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   663
                case GT:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   664
                    this.minSize = 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   665
                    this.maxSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   666
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   667
                case GE:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   668
                    this.minSize = 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   669
                    this.maxSize = length > 1 ? (length - 1) : 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   670
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   671
                default:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   672
                    // unlikely to happen
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   673
                    this.minSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   674
                    this.maxSize = -1;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   675
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   676
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   677
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   678
        /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   679
         * If we are passed a certificate, extract the public key and use it.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   680
         *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   681
         * Check if each constraint fails and check if there is a linked
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   682
         * constraint  Any permitted constraint will exit the linked list
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   683
         * to allow the operation.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   684
         */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   685
        public void permits(CertConstraintParameters cp)
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   686
                throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   687
            if (!permitsImpl(cp.getCertificate().getPublicKey())) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   688
                if (nextConstraint != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   689
                    nextConstraint.permits(cp);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   690
                    return;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   691
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   692
                throw new CertPathValidatorException(
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   693
                        "Algorithm constraints check failed on keysize limits",
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   694
                        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: 32649
diff changeset
   695
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   696
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   697
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   698
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   699
        // Check if key constraint disable the specified key
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   700
        // Uses old style permit()
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   701
        public boolean permits(Key key) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   702
            // If we recursively find a constraint that permits us to use
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   703
            // this key, return true and skip any other constraint checks.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   704
            if (nextConstraint != null && nextConstraint.permits(key)) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   705
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   706
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   707
            if (debug != null) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   708
                debug.println("KeySizeConstraints.permits(): " + algorithm);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   709
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   710
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   711
            return permitsImpl(key);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   712
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   713
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   714
        private boolean permitsImpl(Key key) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   715
            // Verify this constraint is for this public key algorithm
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   716
            if (algorithm.compareToIgnoreCase(key.getAlgorithm()) != 0) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   717
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   718
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   719
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   720
            int size = KeyUtil.getKeySize(key);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   721
            if (size == 0) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   722
                return false;    // we don't allow any key of size 0.
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 7040
diff changeset
   723
            } else if (size > 0) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   724
                return !((size < minSize) || (size > maxSize) ||
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   725
                    (prohibitedSize == size));
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 7040
diff changeset
   726
            }   // Otherwise, the key size is not accessible. Conservatively,
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 7040
diff changeset
   727
                // please don't disable such keys.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   728
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   729
            return true;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   730
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   731
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   732
}
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   733