src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java
author redestad
Mon, 08 Oct 2018 18:16:03 +0200
changeset 52040 d8aebcc2d3ac
parent 47216 71c04702a3d5
child 53018 8bf9268df0e2
permissions -rw-r--r--
8211860: Avoid reading security properties eagerly on Manifest class initialization Reviewed-by: mullan, alanb
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
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
     2
 * Copyright (c) 2010, 2017, 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
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
    28
import sun.security.validator.Validator;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
    29
44158
49deb8a1ed3f 8176350: Usage constraints don't take effect when using PKIX
ascarpino
parents: 43701
diff changeset
    30
import java.io.ByteArrayOutputStream;
49deb8a1ed3f 8176350: Usage constraints don't take effect when using PKIX
ascarpino
parents: 43701
diff changeset
    31
import java.io.PrintStream;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    32
import java.security.CryptoPrimitive;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    33
import java.security.AlgorithmParameters;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    34
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
    35
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
    36
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
    37
import java.security.cert.X509Certificate;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    38
import java.text.SimpleDateFormat;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
    39
import java.util.ArrayList;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    40
import java.util.Calendar;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    41
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
    42
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
    43
import java.util.HashSet;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
    44
import java.util.List;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    45
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
    46
import java.util.Map;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    47
import java.util.Set;
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
    48
import java.util.Collection;
41956
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
    49
import java.util.StringTokenizer;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    50
import java.util.TimeZone;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    51
import java.util.regex.Pattern;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    52
import java.util.regex.Matcher;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    53
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
 * Algorithm constraints for disabled algorithms property
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    56
 *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    57
 * 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
    58
 * for the syntax of the disabled algorithm string.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    59
 */
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    60
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
    61
    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
    62
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    63
    // the known security property, jdk.certpath.disabledAlgorithms
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
    64
    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
    65
            "jdk.certpath.disabledAlgorithms";
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
    // the known security property, jdk.tls.disabledAlgorithms
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
    68
    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
    69
            "jdk.tls.disabledAlgorithms";
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    70
41580
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    71
    // the known security property, jdk.jar.disabledAlgorithms
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    72
    public static final String PROPERTY_JAR_DISABLED_ALGS =
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    73
            "jdk.jar.disabledAlgorithms";
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    74
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    75
    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
    76
    private final Constraints algorithmConstraints;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    77
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    78
    /**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    79
     * Initialize algorithm constraints with the specified security property.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    80
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    81
     * @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
    82
     *        algorithm constraints
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    83
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    84
    public DisabledAlgorithmConstraints(String propertyName) {
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    85
        this(propertyName, new AlgorithmDecomposer());
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    86
    }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
    87
41580
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    88
    /**
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    89
     * Initialize algorithm constraints with the specified security property
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    90
     * for a specific usage type.
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    91
     *
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    92
     * @param propertyName the security property name that define the disabled
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    93
     *        algorithm constraints
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    94
     * @param decomposer an alternate AlgorithmDecomposer.
cc479488428c 8155973: Tighten jar checks
ascarpino
parents: 41562
diff changeset
    95
     */
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    96
    public DisabledAlgorithmConstraints(String propertyName,
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    97
            AlgorithmDecomposer decomposer) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 28974
diff changeset
    98
        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
    99
        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
   100
        algorithmConstraints = new Constraints(disabledAlgorithms);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   101
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   102
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   103
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   104
     * 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
   105
     * 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
   106
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   107
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
   108
    public final boolean permits(Set<CryptoPrimitive> primitives,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   109
            String algorithm, AlgorithmParameters parameters) {
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   110
        if (!checkAlgorithm(disabledAlgorithms, algorithm, decomposer)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   111
            return false;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   112
        }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   113
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   114
        if (parameters != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   115
            return algorithmConstraints.permits(algorithm, parameters);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   116
        }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   117
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   118
        return true;
7040
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
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   121
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   122
     * 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
   123
     * 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
   124
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   125
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
   126
    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
   127
        return checkConstraints(primitives, "", key, null);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   128
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   129
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   130
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   131
     * 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
   132
     * 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
   133
     */
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   134
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31689
diff changeset
   135
    public final boolean permits(Set<CryptoPrimitive> primitives,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   136
            String algorithm, Key key, AlgorithmParameters parameters) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   137
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   138
        if (algorithm == null || algorithm.length() == 0) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   139
            throw new IllegalArgumentException("No algorithm name specified");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   140
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   141
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   142
        return checkConstraints(primitives, algorithm, key, parameters);
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   143
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   144
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   145
    public final void permits(ConstraintsParameters cp)
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   146
            throws CertPathValidatorException {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   147
        permits(cp.getAlgorithm(), cp);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   148
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   149
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   150
    public final void permits(String algorithm, Key key,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   151
            AlgorithmParameters params, String variant)
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   152
            throws CertPathValidatorException {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   153
        permits(algorithm, new ConstraintsParameters(algorithm, params, key,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   154
                (variant == null) ? Validator.VAR_GENERIC : variant));
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   155
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   156
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   157
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   158
     * 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
   159
     * 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
   160
     * 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
   161
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   162
     * 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
   163
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   164
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   165
    public final void permits(String algorithm, ConstraintsParameters cp)
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   166
            throws CertPathValidatorException {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   167
        algorithmConstraints.permits(algorithm, cp);
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   168
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   169
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   170
    // 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
   171
    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
   172
        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
   173
        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
   174
            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
   175
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   176
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   177
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   178
        return false;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   179
    }
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 key and algorithm
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   182
    private boolean checkConstraints(Set<CryptoPrimitive> primitives,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   183
            String algorithm, Key key, AlgorithmParameters parameters) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   184
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   185
        // check the key parameter, it cannot be null.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   186
        if (key == null) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   187
            throw new IllegalArgumentException("The key cannot be null");
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   188
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   189
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   190
        // check the signature algorithm with parameters
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   191
        if (algorithm != null && algorithm.length() != 0) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   192
            if (!permits(primitives, algorithm, parameters)) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   193
                return false;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   194
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   195
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   196
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   197
        // check the key algorithm
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   198
        if (!permits(primitives, key.getAlgorithm(), null)) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   199
            return false;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   200
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   201
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   202
        // 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
   203
        return algorithmConstraints.permits(key);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   204
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   205
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   206
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   207
    /**
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   208
     * 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
   209
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   210
     * 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
   211
     * 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
   212
     *   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
   213
     *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   214
     * 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
   215
     * 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
   216
     * maintain compatibility:
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   217
     * '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
   218
     * '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
   219
     *
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   220
     * When passing ConstraintsParameters through permit(), an exception
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   221
     * 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
   222
     * disallowed.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   223
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   224
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   225
    private static class Constraints {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   226
        private Map<String, List<Constraint>> constraintsMap = new HashMap<>();
41956
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   227
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   228
        private static class Holder {
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   229
            private static final Pattern DENY_AFTER_PATTERN = Pattern.compile(
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   230
                    "denyAfter\\s+(\\d{4})-(\\d{2})-(\\d{2})");
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   231
        }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   232
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   233
        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
   234
            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
   235
                if (constraintEntry == null || constraintEntry.isEmpty()) {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   236
                    continue;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   237
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   238
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   239
                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
   240
                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
   241
                    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
   242
                }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   243
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   244
                // 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
   245
                // 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
   246
                int space = constraintEntry.indexOf(' ');
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   247
                String algorithm = AlgorithmDecomposer.hashName(
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   248
                        ((space > 0 ? constraintEntry.substring(0, space) :
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   249
                                constraintEntry).
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   250
                                toUpperCase(Locale.ENGLISH)));
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   251
                List<Constraint> constraintList =
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   252
                        constraintsMap.getOrDefault(algorithm,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   253
                                new ArrayList<>(1));
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   254
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   255
                // Consider the impact of algorithm aliases.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   256
                for (String alias : AlgorithmDecomposer.getAliases(algorithm)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   257
                    constraintsMap.putIfAbsent(alias, constraintList);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   258
                }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   259
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   260
                if (space <= 0) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   261
                    constraintList.add(new DisabledConstraint(algorithm));
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   262
                    continue;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   263
                }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   264
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   265
                String policy = constraintEntry.substring(space + 1);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   266
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   267
                // 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
   268
                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
   269
                // 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
   270
                boolean jdkCALimit = false;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   271
                // Allow only one denyAfter entry per constraint entry
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   272
                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
   273
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   274
                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
   275
                    entry = entry.trim();
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   276
41956
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   277
                    Matcher matcher;
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   278
                    if (entry.startsWith("keySize")) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   279
                        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
   280
                            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
   281
                                    entry);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   282
                        }
41956
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   283
                        StringTokenizer tokens = new StringTokenizer(entry);
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   284
                        if (!"keySize".equals(tokens.nextToken())) {
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   285
                            throw new IllegalArgumentException("Error in " +
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   286
                                    "security property. Constraint unknown: " +
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   287
                                    entry);
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   288
                        }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   289
                        c = new KeySizeConstraint(algorithm,
41956
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   290
                                KeySizeConstraint.Operator.of(tokens.nextToken()),
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   291
                                Integer.parseInt(tokens.nextToken()));
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   292
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   293
                    } 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
   294
                        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
   295
                            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
   296
                        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   297
                        if (jdkCALimit) {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   298
                            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
   299
                                    "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
   300
                                    "Constraint: " + constraintEntry);
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   301
                        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   302
                        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
   303
                        jdkCALimit = true;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   304
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   305
                    } else if (entry.startsWith("denyAfter") &&
41956
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   306
                            (matcher = Holder.DENY_AFTER_PATTERN.matcher(entry))
69deb06bb8f1 8168911: Increased number of classes initialized during initialization of SignatureFileVerifier
redestad
parents: 41580
diff changeset
   307
                                    .matches()) {
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   308
                        if (debug != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   309
                            debug.println("Constraints set to denyAfter");
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   310
                        }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   311
                        if (denyAfterLimit) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   312
                            throw new IllegalArgumentException("Only one " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   313
                                    "denyAfter entry allowed in property. " +
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   314
                                    "Constraint: " + constraintEntry);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   315
                        }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   316
                        int year = Integer.parseInt(matcher.group(1));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   317
                        int month = Integer.parseInt(matcher.group(2));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   318
                        int day = Integer.parseInt(matcher.group(3));
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   319
                        c = new DenyAfterConstraint(algorithm, year, month,
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   320
                                day);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   321
                        denyAfterLimit = true;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   322
                    } else if (entry.startsWith("usage")) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   323
                        String s[] = (entry.substring(5)).trim().split(" ");
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   324
                        c = new UsageConstraint(algorithm, s);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   325
                        if (debug != null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   326
                            debug.println("Constraints usage length is " + s.length);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   327
                        }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   328
                    } else {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   329
                        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
   330
                                " property. Constraint unknown: " + entry);
7040
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
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   333
                    // 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
   334
                    // 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
   335
                    if (lastConstraint == null) {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   336
                        constraintList.add(c);
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   337
                    } else {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   338
                        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
   339
                    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   340
                    lastConstraint = c;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   341
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   342
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   343
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   344
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   345
        // Get applicable constraints based off the signature algorithm
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   346
        private List<Constraint> getConstraints(String algorithm) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   347
            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
   348
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   349
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   350
        // 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
   351
        public boolean permits(Key key) {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   352
            List<Constraint> list = getConstraints(key.getAlgorithm());
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   353
            if (list == null) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   354
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   355
            }
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   356
            for (Constraint constraint : list) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   357
                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
   358
                    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
   359
                        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
   360
                                "constraint check " + KeyUtil.getKeySize(key));
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   361
                    }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   362
                    return false;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   363
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   364
            }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   365
            return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   366
        }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   367
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   368
        // Check if constraints permit this AlgorithmParameters.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   369
        public boolean permits(String algorithm, AlgorithmParameters aps) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   370
            List<Constraint> list = getConstraints(algorithm);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   371
            if (list == null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   372
                return true;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   373
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   374
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   375
            for (Constraint constraint : list) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   376
                if (!constraint.permits(aps)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   377
                    if (debug != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   378
                        debug.println("keySizeConstraint: failed algorithm " +
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   379
                                "parameters constraint check " + aps);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   380
                    }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   381
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   382
                    return false;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   383
                }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   384
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   385
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   386
            return true;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   387
        }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   388
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   389
        // Check if constraints permit this cert.
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   390
        public void permits(String algorithm, ConstraintsParameters cp)
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   391
                throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   392
            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
   393
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   394
            if (debug != null) {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   395
                debug.println("Constraints.permits(): " + algorithm +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   396
                        " Variant: " + cp.getVariant());
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   397
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   398
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   399
            // Get all signature algorithms to check for constraints
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   400
            Set<String> algorithms = new HashSet<>();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   401
            if (algorithm != null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   402
                algorithms.addAll(AlgorithmDecomposer.decomposeOneHash(algorithm));
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   403
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   404
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   405
            // Attempt to add the public key algorithm if cert provided
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   406
            if (cert != null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   407
                algorithms.add(cert.getPublicKey().getAlgorithm());
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   408
            }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   409
            if (cp.getPublicKey() != null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   410
                algorithms.add(cp.getPublicKey().getAlgorithm());
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   411
            }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   412
            // Check all applicable constraints
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   413
            for (String alg : algorithms) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   414
                List<Constraint> list = getConstraints(alg);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   415
                if (list == null) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   416
                    continue;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   417
                }
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   418
                for (Constraint constraint : list) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   419
                    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
   420
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   421
            }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   422
        }
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
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   425
    /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   426
     * This abstract Constraint class for algorithm-based checking
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   427
     * 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
   428
     * property is used, multiple constraints have been grouped together
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   429
     * 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
   430
     *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   431
     * If the class contains multiple constraints, the next constraint
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   432
     * is stored in {@code nextConstraint} in linked-list fashion.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   433
     */
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   434
    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
   435
        String algorithm;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   436
        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
   437
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   438
        // operator
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   439
        enum Operator {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   440
            EQ,         // "=="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   441
            NE,         // "!="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   442
            LT,         // "<"
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   443
            LE,         // "<="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   444
            GT,         // ">"
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   445
            GE;         // ">="
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   446
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   447
            static Operator of(String s) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   448
                switch (s) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   449
                    case "==":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   450
                        return EQ;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   451
                    case "!=":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   452
                        return NE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   453
                    case "<":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   454
                        return LT;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   455
                    case "<=":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   456
                        return LE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   457
                    case ">":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   458
                        return GT;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   459
                    case ">=":
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   460
                        return GE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   461
                }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   462
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   463
                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
   464
                        "property. " + s + " is not a legal Operator");
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   465
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   466
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   467
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   468
        /**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   469
         * 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
   470
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   471
         * 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
   472
         * {@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
   473
         * multiple constraints need to be checked.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   474
         *
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   475
         * @param key Public key
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   476
         * @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
   477
         */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   478
        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
   479
            return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   480
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   481
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   482
        /**
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   483
         * Check if the algorithm constraint permits a given cryptographic
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   484
         * parameters.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   485
         *
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   486
         * @param parameters the cryptographic parameters
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   487
         * @return 'true' if the cryptographic parameters is allowed,
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   488
         *         'false' ortherwise.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   489
         */
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   490
        public boolean permits(AlgorithmParameters parameters) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   491
            return true;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   492
        }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   493
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   494
        /**
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   495
         * Check if an algorithm constraint is permitted with a given
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   496
         * ConstraintsParameters.
38576
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
         * If the check inside of {@code permits()} fails, it must call
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   499
         * {@code next()} with the same {@code ConstraintsParameters}
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   500
         * parameter passed if multiple constraints need to be checked.
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
         * @param cp CertConstraintParameter containing certificate info
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   503
         * @throws CertPathValidatorException if constraint disallows.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   504
         *
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   505
         */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   506
        public abstract void permits(ConstraintsParameters cp)
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   507
                throws CertPathValidatorException;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   508
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   509
        /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   510
         * Recursively check if the constraints are allowed.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   511
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   512
         * If {@code nextConstraint} is non-null, this method will
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   513
         * 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
   514
         * constraint is allowed or denied.  If the constraint's
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   515
         * {@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
   516
         * recursive next() calls, returning 'true'.  If the constraints called
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   517
         * were disallowed, the last constraint will throw
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   518
         * {@code CertPathValidatorException}.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   519
         *
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   520
         * @param cp ConstraintsParameters
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   521
         * @return 'true' if constraint allows the operation, 'false' if
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   522
         * 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
   523
         * {@code nextConstraint} is null.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   524
         */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   525
        boolean next(ConstraintsParameters cp)
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   526
                throws CertPathValidatorException {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   527
            if (nextConstraint != null) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   528
                nextConstraint.permits(cp);
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   529
                return true;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   530
            }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   531
            return false;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   532
        }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   533
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   534
        /**
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   535
         * Recursively check if this constraint is allowed,
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   536
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   537
         * If {@code nextConstraint} is non-null, this method will
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   538
         * 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
   539
         * constraint is allowed or denied.  If the constraint's
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   540
         * {@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
   541
         * recursive next() calls, returning 'true'.  If the constraints
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   542
         * called were disallowed the check will exit with 'false'.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   543
         *
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   544
         * @param key Public key
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   545
         * @return 'true' if constraint allows the operation, 'false' if
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   546
         * the constraint denies the operation.
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
        boolean next(Key key) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   549
            if (nextConstraint != null && nextConstraint.permits(key)) {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   550
                return true;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   551
            }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   552
            return false;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   553
        }
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   554
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   555
        String extendedMsg(ConstraintsParameters cp) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   556
            return (cp.getCertificate() == null ? "." :
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   557
                    " used with certificate: " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   558
                            cp.getCertificate().getSubjectX500Principal() +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   559
                    (cp.getVariant() != Validator.VAR_GENERIC ?
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   560
                            ".  Usage was " + cp.getVariant() : "."));
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   561
        }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   562
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   563
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   564
    /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   565
     * 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
   566
     * 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
   567
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   568
    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
   569
        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
   570
            algorithm = algo;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   571
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   572
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   573
        /*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   574
         * Check if ConstraintsParameters has a trusted match, if it does
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   575
         * 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
   576
         * 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
   577
         */
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   578
        @Override
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   579
        public void permits(ConstraintsParameters cp)
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   580
                throws CertPathValidatorException {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   581
            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
   582
                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
   583
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   584
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   585
            // 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
   586
            if (cp.isTrustedMatch()) {
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   587
                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
   588
                    return;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   589
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   590
                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
   591
                        "Algorithm constraints check failed on certificate " +
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   592
                        "anchor limits. " + algorithm + extendedMsg(cp),
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   593
                        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
   594
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   595
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   596
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   597
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   598
    /*
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   599
     * 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
   600
     * timezone.
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   601
     */
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   602
    private static class DenyAfterConstraint extends Constraint {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   603
        private Date denyAfterDate;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   604
        private static final SimpleDateFormat dateFormat =
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   605
                new SimpleDateFormat("EEE, MMM d HH:mm:ss z yyyy");
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   606
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   607
        DenyAfterConstraint(String algo, int year, int month, int day) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   608
            Calendar c;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   609
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   610
            algorithm = algo;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   611
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   612
            if (debug != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   613
                debug.println("DenyAfterConstraint read in as:  year " +
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   614
                        year + ", month = " + month + ", day = " + day);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   615
            }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   616
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   617
            c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT"))
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   618
                    .setDate(year, month - 1, day).build();
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   619
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   620
            if (year > c.getActualMaximum(Calendar.YEAR) ||
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   621
                    year < c.getActualMinimum(Calendar.YEAR)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   622
                throw new IllegalArgumentException(
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   623
                        "Invalid year given in constraint: " + year);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   624
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   625
            if ((month - 1) > c.getActualMaximum(Calendar.MONTH) ||
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   626
                    (month - 1) < c.getActualMinimum(Calendar.MONTH)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   627
                throw new IllegalArgumentException(
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   628
                        "Invalid month given in constraint: " + month);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   629
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   630
            if (day > c.getActualMaximum(Calendar.DAY_OF_MONTH) ||
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   631
                    day < c.getActualMinimum(Calendar.DAY_OF_MONTH)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   632
                throw new IllegalArgumentException(
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   633
                        "Invalid Day of Month given in constraint: " + day);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   634
            }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   635
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   636
            denyAfterDate = c.getTime();
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   637
            if (debug != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   638
                debug.println("DenyAfterConstraint date set to: " +
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   639
                        dateFormat.format(denyAfterDate));
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   640
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   641
        }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   642
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   643
        /*
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   644
         * Checking that the provided date is not beyond the constraint date.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   645
         * The provided date can be the PKIXParameter date if given,
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   646
         * otherwise it is the current date.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   647
         *
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   648
         * If the constraint disallows, call next() for any following
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   649
         * constraints. Throw an exception if this is the last constraint.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   650
         */
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   651
        @Override
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   652
        public void permits(ConstraintsParameters cp)
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   653
                throws CertPathValidatorException {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   654
            Date currentDate;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   655
            String errmsg;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   656
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   657
            if (cp.getJARTimestamp() != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   658
                currentDate = cp.getJARTimestamp().getTimestamp();
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   659
                errmsg = "JAR Timestamp date: ";
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   660
            } else if (cp.getPKIXParamDate() != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   661
                currentDate = cp.getPKIXParamDate();
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   662
                errmsg = "PKIXParameter date: ";
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   663
            } else {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   664
                currentDate = new Date();
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   665
                errmsg = "Current date: ";
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   666
            }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   667
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   668
            if (!denyAfterDate.after(currentDate)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   669
                if (next(cp)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   670
                    return;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   671
                }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   672
                throw new CertPathValidatorException(
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   673
                        "denyAfter constraint check failed: " + algorithm +
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   674
                        " used with Constraint date: " +
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   675
                        dateFormat.format(denyAfterDate) + "; " + errmsg +
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   676
                        dateFormat.format(currentDate) + extendedMsg(cp),
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   677
                        null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   678
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   679
        }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   680
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   681
        /*
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   682
         * Return result if the constraint's date is beyond the current date
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   683
         * in UTC timezone.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   684
         */
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   685
        @Override
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   686
        public boolean permits(Key key) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   687
            if (next(key)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   688
                return true;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   689
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   690
            if (debug != null) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   691
                debug.println("DenyAfterConstraints.permits(): " + algorithm);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   692
            }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   693
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   694
            return denyAfterDate.after(new Date());
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   695
        }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   696
    }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   697
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   698
    /*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   699
     * The usage constraint is for the "usage" keyword.  It checks against the
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   700
     * variant value in ConstraintsParameters.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   701
     */
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   702
    private static class UsageConstraint extends Constraint {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   703
        String[] usages;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   704
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   705
        UsageConstraint(String algorithm, String[] usages) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   706
            this.algorithm = algorithm;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   707
            this.usages = usages;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   708
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   709
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   710
        @Override
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   711
        public void permits(ConstraintsParameters cp)
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   712
                throws CertPathValidatorException {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   713
            for (String usage : usages) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   714
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   715
                String v = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   716
                if (usage.compareToIgnoreCase("TLSServer") == 0) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   717
                    v = Validator.VAR_TLS_SERVER;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   718
                } else if (usage.compareToIgnoreCase("TLSClient") == 0) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   719
                    v = Validator.VAR_TLS_CLIENT;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   720
                } else if (usage.compareToIgnoreCase("SignedJAR") == 0) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   721
                    v = Validator.VAR_PLUGIN_CODE_SIGNING;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   722
                }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   723
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   724
                if (debug != null) {
44158
49deb8a1ed3f 8176350: Usage constraints don't take effect when using PKIX
ascarpino
parents: 43701
diff changeset
   725
                    debug.println("Checking if usage constraint \"" + v +
49deb8a1ed3f 8176350: Usage constraints don't take effect when using PKIX
ascarpino
parents: 43701
diff changeset
   726
                            "\" matches \"" + cp.getVariant() + "\"");
44920
5b66112437ba 8176457: Add verbose option to java.security.debug
ascarpino
parents: 44158
diff changeset
   727
                    if (Debug.isVerbose()) {
5b66112437ba 8176457: Add verbose option to java.security.debug
ascarpino
parents: 44158
diff changeset
   728
                        // Because usage checking can come from many places
5b66112437ba 8176457: Add verbose option to java.security.debug
ascarpino
parents: 44158
diff changeset
   729
                        // a stack trace is very helpful.
5b66112437ba 8176457: Add verbose option to java.security.debug
ascarpino
parents: 44158
diff changeset
   730
                        (new Exception()).printStackTrace(debug.getPrintStream());
5b66112437ba 8176457: Add verbose option to java.security.debug
ascarpino
parents: 44158
diff changeset
   731
                    }
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   732
                }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   733
                if (cp.getVariant().compareTo(v) == 0) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   734
                    if (next(cp)) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   735
                        return;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   736
                    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   737
                    throw new CertPathValidatorException("Usage constraint " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   738
                            usage + " check failed: " + algorithm +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   739
                            extendedMsg(cp),
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   740
                            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   741
                }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   742
            }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   743
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   744
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   745
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   746
    /*
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   747
     * 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
   748
     * 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
   749
     */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   750
    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
   751
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   752
        private int minSize;            // the minimal available key size
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   753
        private int maxSize;            // the maximal available key size
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   754
        private int prohibitedSize = -1;    // unavailable key sizes
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   755
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   756
        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
   757
            algorithm = algo;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   758
            switch (operator) {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   759
                case EQ:      // an unavailable key size
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   760
                    this.minSize = 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   761
                    this.maxSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   762
                    prohibitedSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   763
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   764
                case NE:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   765
                    this.minSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   766
                    this.maxSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   767
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   768
                case LT:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   769
                    this.minSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   770
                    this.maxSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   771
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   772
                case LE:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   773
                    this.minSize = length + 1;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   774
                    this.maxSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   775
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   776
                case GT:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   777
                    this.minSize = 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   778
                    this.maxSize = length;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   779
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   780
                case GE:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   781
                    this.minSize = 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   782
                    this.maxSize = length > 1 ? (length - 1) : 0;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   783
                    break;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   784
                default:
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   785
                    // unlikely to happen
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   786
                    this.minSize = Integer.MAX_VALUE;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   787
                    this.maxSize = -1;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   788
            }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   789
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   790
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   791
        /*
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   792
         * 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
   793
         *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   794
         * 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
   795
         * 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
   796
         * 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
   797
         */
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   798
        @Override
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   799
        public void permits(ConstraintsParameters cp)
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   800
                throws CertPathValidatorException {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   801
            Key key = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   802
            if (cp.getPublicKey() != null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   803
                key = cp.getPublicKey();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   804
            } else if (cp.getCertificate() != null) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   805
                key = cp.getCertificate().getPublicKey();
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   806
            }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   807
            if (key != null && !permitsImpl(key)) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   808
                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
   809
                    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
   810
                    return;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   811
                }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   812
                throw new CertPathValidatorException(
45988
6b7aa871e786 8179101: Improve algorithm constraints implementation
ascarpino
parents: 44158
diff changeset
   813
                        "Algorithm constraints check failed on keysize limits. " +
6b7aa871e786 8179101: Improve algorithm constraints implementation
ascarpino
parents: 44158
diff changeset
   814
                        algorithm + " " + KeyUtil.getKeySize(key) + "bit key" +
6b7aa871e786 8179101: Improve algorithm constraints implementation
ascarpino
parents: 44158
diff changeset
   815
                        extendedMsg(cp),
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   816
                        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
   817
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   818
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   819
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   820
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   821
        // 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
   822
        // Uses old style permit()
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   823
        @Override
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   824
        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
   825
            // 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
   826
            // 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
   827
            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
   828
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   829
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   830
            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
   831
                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
   832
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   833
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   834
            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
   835
        }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   836
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   837
        @Override
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   838
        public boolean permits(AlgorithmParameters parameters) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   839
            String paramAlg = parameters.getAlgorithm();
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   840
            if (!algorithm.equalsIgnoreCase(parameters.getAlgorithm())) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   841
                // Consider the impact of the algorithm aliases.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   842
                Collection<String> aliases =
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   843
                        AlgorithmDecomposer.getAliases(algorithm);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   844
                if (!aliases.contains(paramAlg)) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   845
                    return true;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   846
                }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   847
            }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   848
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   849
            int keySize = KeyUtil.getKeySize(parameters);
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   850
            if (keySize == 0) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   851
                return false;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   852
            } else if (keySize > 0) {
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   853
                return !((keySize < minSize) || (keySize > maxSize) ||
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   854
                    (prohibitedSize == keySize));
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   855
            }   // Otherwise, the key size is not accessible or determined.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   856
                // Conservatively, please don't disable such keys.
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   857
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   858
            return true;
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   859
        }
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   860
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   861
        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
   862
            // 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
   863
            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
   864
                return true;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   865
            }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   866
45988
6b7aa871e786 8179101: Improve algorithm constraints implementation
ascarpino
parents: 44158
diff changeset
   867
            int size = KeyUtil.getKeySize(key);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   868
            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
   869
                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
   870
            } 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
   871
                return !((size < minSize) || (size > maxSize) ||
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   872
                    (prohibitedSize == size));
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 7040
diff changeset
   873
            }   // 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
   874
                // please don't disable such keys.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   875
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents: 32649
diff changeset
   876
            return true;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   877
        }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   878
    }
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   879
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   880
    /*
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   881
     * This constraint is used for the complete disabling of the algorithm.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   882
     */
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   883
    private static class DisabledConstraint extends Constraint {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   884
        DisabledConstraint(String algo) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   885
            algorithm = algo;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   886
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   887
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   888
        @Override
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   889
        public void permits(ConstraintsParameters cp)
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   890
                throws CertPathValidatorException {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   891
            throw new CertPathValidatorException(
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   892
                    "Algorithm constraints check failed on disabled " +
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   893
                            "algorithm: " + algorithm + extendedMsg(cp),
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   894
                    null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   895
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   896
45394
6b54e8cd9b3d 8178728: Check the AlgorithmParameters in algorithm constraints
xuelei
parents: 44920
diff changeset
   897
        @Override
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   898
        public boolean permits(Key key) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   899
            return false;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   900
        }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41956
diff changeset
   901
    }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   902
}
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
diff changeset
   903