jdk/src/java.base/share/classes/sun/security/util/ConstraintsParameters.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 39465 jdk/src/java.base/share/classes/sun/security/util/CertConstraintParameters.java@8c06651d9138
child 45028 b0ea3c0bfb81
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     1
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
     2
 * Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved.
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     4
 *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    10
 *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    15
 * accompanied this code).
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    16
 *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    20
 *
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    23
 * questions.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    24
 */
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    25
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    26
package sun.security.util;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    27
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    28
import sun.security.validator.Validator;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    29
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    30
import java.security.AlgorithmParameters;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    31
import java.security.Key;
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
    32
import java.security.Timestamp;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    33
import java.security.cert.X509Certificate;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    34
import java.util.Date;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    35
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    36
/**
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    37
 * This class contains parameters for checking against constraints that extend
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    38
 * past the publicly available parameters in java.security.AlgorithmConstraints.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    39
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    40
 * This is currently on passed between  between PKIX, AlgorithmChecker,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    41
 * and DisabledAlgorithmConstraints.
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    42
 */
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    43
public class ConstraintsParameters {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    44
    /*
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    45
     * The below 3 values are used the same as the permit() methods
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    46
     * published in java.security.AlgorithmConstraints.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    47
     */
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    48
    // Algorithm string to be checked against constraints
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    49
    private final String algorithm;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    50
    // AlgorithmParameters to the algorithm being checked
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    51
    private final AlgorithmParameters algParams;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    52
    // Public Key being checked against constraints
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    53
    private final Key publicKey;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    54
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    55
    /*
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    56
     * New values that are checked against constraints that the current public
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    57
     * API does not support.
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    58
     */
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    59
    // A certificate being passed to check against constraints.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    60
    private final X509Certificate cert;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    61
    // This is true if the trust anchor in the certificate chain matches a cert
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    62
    // in AnchorCertificates
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    63
    private final boolean trustedMatch;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    64
    // PKIXParameter date
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    65
    private final Date pkixDate;
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
    66
    // Timestamp of the signed JAR file
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
    67
    private final Timestamp jarTimestamp;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    68
    private final String variant;
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    69
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    70
    public ConstraintsParameters(X509Certificate c, boolean match,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    71
            Date pkixdate, Timestamp jarTime, String variant) {
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    72
        cert = c;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    73
        trustedMatch = match;
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
    74
        pkixDate = pkixdate;
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
    75
        jarTimestamp = jarTime;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    76
        this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    77
        algorithm = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    78
        algParams = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    79
        publicKey = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    80
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    81
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    82
    public ConstraintsParameters(String algorithm, AlgorithmParameters params,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    83
            Key key, String variant) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    84
        this.algorithm = algorithm;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    85
        algParams = params;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    86
        this.publicKey = key;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    87
        cert = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    88
        trustedMatch = false;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    89
        pkixDate = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    90
        jarTimestamp = null;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    91
        this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    92
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
    93
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    94
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    95
    public ConstraintsParameters(X509Certificate c) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    96
        this(c, false, null, null,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    97
                Validator.VAR_GENERIC);
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    98
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
    99
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   100
    public ConstraintsParameters(Timestamp jarTime) {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   101
        this(null, false, null, jarTime, Validator.VAR_GENERIC);
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   102
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   103
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   104
    public String getAlgorithm() {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   105
        return algorithm;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   106
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   107
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   108
    public AlgorithmParameters getAlgParams() {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   109
        return algParams;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   110
    }
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   111
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   112
    public Key getPublicKey() {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   113
        return publicKey;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   114
    }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   115
    // Returns if the trust anchor has a match if anchor checking is enabled.
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   116
    public boolean isTrustedMatch() {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   117
        return trustedMatch;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   118
    }
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   119
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   120
    public X509Certificate getCertificate() {
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   121
        return cert;
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   122
    }
38576
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   123
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   124
    public Date getPKIXParamDate() {
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   125
        return pkixDate;
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   126
    }
ccaac80108c5 8154005: Add algorithm constraint that specifies the restriction date
ascarpino
parents: 37726
diff changeset
   127
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   128
    public Timestamp getJARTimestamp() {
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   129
        return jarTimestamp;
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   130
    }
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   131
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   132
    public String getVariant() {
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   133
        return variant;
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   134
    }
37726
bbecfff95ec3 8140422: Add mechanism to allow non default root CAs to be not subject to algorithm restrictions
ascarpino
parents:
diff changeset
   135
}