jdk/src/java.base/share/classes/sun/security/provider/certpath/PolicyChecker.java
author juh
Tue, 07 Oct 2014 22:23:19 -0700
changeset 26967 c182469301ee
parent 25859 3317bb8137f4
child 30374 2abaf49910ea
permissions -rw-r--r--
8037550: Update RFC references in javadoc to RFC 5280 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    29
import java.security.GeneralSecurityException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.CertificateException;
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
    32
import java.security.cert.CertPathValidatorException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.PKIXCertPathChecker;
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
    34
import java.security.cert.PKIXReason;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.cert.PolicyNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.cert.PolicyQualifierInfo;
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
    37
import java.security.cert.X509Certificate;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    38
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.security.x509.CertificatePoliciesExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.security.x509.PolicyConstraintsExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.security.x509.PolicyMappingsExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.security.x509.CertificatePolicyMap;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    45
import static sun.security.x509.PKIXExtensions.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.security.x509.PolicyInformation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.security.x509.X509CertImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.security.x509.InhibitAnyPolicyExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * PolicyChecker is a <code>PKIXCertPathChecker</code> that checks policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * information on a PKIX certificate, namely certificate policies, policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * mappings, policy constraints and policy qualifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
class PolicyChecker extends PKIXCertPathChecker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final Set<String> initPolicies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final int certPathLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final boolean expPolicyRequired;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final boolean polMappingInhibited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final boolean anyPolicyInhibited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private final boolean rejectPolicyQualifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private PolicyNodeImpl rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int explicitPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private int policyMapping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int inhibitAnyPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private int certIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
790
b91742db13e2 6673277: Thread unsafe lazy initialization code in sun.security.provider.certpath.*Checker classes
mullan
parents: 2
diff changeset
    72
    private Set<String> supportedExts;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static final String ANY_POLICY = "2.5.29.32.0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constructs a Policy Checker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param initialPolicies Set of initial policies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param certPathLen length of the certification path to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param expPolicyRequired true if explicit policy is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param polMappingInhibited true if policy mapping is inhibited
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param anyPolicyInhibited true if the ANY_POLICY OID should be inhibited
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param rejectPolicyQualifiers true if pol qualifiers are to be rejected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param rootNode the initial root node of the valid policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    PolicyChecker(Set<String> initialPolicies, int certPathLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        boolean expPolicyRequired, boolean polMappingInhibited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        boolean anyPolicyInhibited, boolean rejectPolicyQualifiers,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    91
        PolicyNodeImpl rootNode)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (initialPolicies.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            // if no initialPolicies are specified by user, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            // initPolicies to be anyPolicy by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            this.initPolicies = new HashSet<String>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            this.initPolicies.add(ANY_POLICY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            this.initPolicies = new HashSet<String>(initialPolicies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.certPathLen = certPathLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.expPolicyRequired = expPolicyRequired;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.polMappingInhibited = polMappingInhibited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.anyPolicyInhibited = anyPolicyInhibited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.rejectPolicyQualifiers = rejectPolicyQualifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.rootNode = rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Initializes the internal state of the checker from parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * specified in the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   113
     * @param forward a boolean indicating whether this checker should be
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   114
     *        initialized capable of building in the forward direction
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   115
     * @throws CertPathValidatorException if user wants to enable forward
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   116
     *         checking and forward checking is not supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   118
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void init(boolean forward) throws CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                        ("forward checking not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        certIndex = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        explicitPolicy = (expPolicyRequired ? 0 : certPathLen + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        policyMapping = (polMappingInhibited ? 0 : certPathLen + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        inhibitAnyPolicy = (anyPolicyInhibited ? 0 : certPathLen + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Checks if forward checking is supported. Forward checking refers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * to the ability of the PKIXCertPathChecker to perform its checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * when presented with certificates in the forward direction (from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * target to anchor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return true if forward checking is supported, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   139
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public boolean isForwardCheckingSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Gets an immutable Set of the OID strings for the extensions that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the PKIXCertPathChecker supports (i.e. recognizes, is able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * process), or null if no extensions are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * supported. All OID strings that a PKIXCertPathChecker might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * possibly be able to process should be included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @return the Set of extensions supported by this PKIXCertPathChecker,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * or null if no extensions are supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   154
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public Set<String> getSupportedExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (supportedExts == null) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   157
            supportedExts = new HashSet<String>(4);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   158
            supportedExts.add(CertificatePolicies_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   159
            supportedExts.add(PolicyMappings_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   160
            supportedExts.add(PolicyConstraints_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   161
            supportedExts.add(InhibitAnyPolicy_Id.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            supportedExts = Collections.unmodifiableSet(supportedExts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return supportedExts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Performs the policy processing checks on the certificate using its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * internal state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param cert the Certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param unresCritExts the unresolved critical extensions
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   173
     * @throws CertPathValidatorException if the certificate does not verify
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   175
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void check(Certificate cert, Collection<String> unresCritExts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // now do the policy checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        checkPolicy((X509Certificate) cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (unresCritExts != null && !unresCritExts.isEmpty()) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   183
            unresCritExts.remove(CertificatePolicies_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   184
            unresCritExts.remove(PolicyMappings_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   185
            unresCritExts.remove(PolicyConstraints_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   186
            unresCritExts.remove(InhibitAnyPolicy_Id.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Internal method to run through all the checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param currCert the certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @exception CertPathValidatorException Exception thrown if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * the certificate does not verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private void checkPolicy(X509Certificate currCert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        String msg = "certificate policies";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            debug.println("PolicyChecker.checkPolicy() ---checking " + msg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            debug.println("PolicyChecker.checkPolicy() certIndex = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                + certIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                + "explicitPolicy = " + explicitPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                + "policyMapping = " + policyMapping);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                + "inhibitAnyPolicy = " + inhibitAnyPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            debug.println("PolicyChecker.checkPolicy() BEFORE PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                + "policyTree = " + rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        X509CertImpl currCertImpl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            currCertImpl = X509CertImpl.toImpl(currCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        } catch (CertificateException ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            throw new CertPathValidatorException(ce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        boolean finalCert = (certIndex == certPathLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        rootNode = processPolicies(certIndex, initPolicies, explicitPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            policyMapping, inhibitAnyPolicy, rejectPolicyQualifiers, rootNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            currCertImpl, finalCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!finalCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            explicitPolicy = mergeExplicitPolicy(explicitPolicy, currCertImpl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                                 finalCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            policyMapping = mergePolicyMapping(policyMapping, currCertImpl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            inhibitAnyPolicy = mergeInhibitAnyPolicy(inhibitAnyPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                                     currCertImpl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        certIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                + "explicitPolicy = " + explicitPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                + "policyMapping = " + policyMapping);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                + "inhibitAnyPolicy = " + inhibitAnyPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            debug.println("PolicyChecker.checkPolicy() AFTER PROCESSING: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                + "policyTree = " + rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            debug.println("PolicyChecker.checkPolicy() " + msg + " verified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Merges the specified explicitPolicy value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * requireExplicitPolicy field of the <code>PolicyConstraints</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * extension obtained from the certificate. An explicitPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * value of -1 implies no constraint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param explicitPolicy an integer which indicates if a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * valid policy tree is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param currCert the Certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param finalCert a boolean indicating whether currCert is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * the final cert in the cert path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return returns the new explicitPolicy value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @exception CertPathValidatorException Exception thrown if an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    static int mergeExplicitPolicy(int explicitPolicy, X509CertImpl currCert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        boolean finalCert) throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if ((explicitPolicy > 0) && !X509CertImpl.isSelfIssued(currCert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            explicitPolicy--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            PolicyConstraintsExtension polConstExt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                = currCert.getPolicyConstraintsExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (polConstExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                return explicitPolicy;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   279
            int require =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   280
                polConstExt.get(PolicyConstraintsExtension.REQUIRE).intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                debug.println("PolicyChecker.mergeExplicitPolicy() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                   + "require Index from cert = " + require);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (!finalCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (require != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    if ((explicitPolicy == -1) || (require < explicitPolicy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        explicitPolicy = require;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                if (require == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    explicitPolicy = require;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   295
        } catch (IOException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                debug.println("PolicyChecker.mergeExplicitPolicy "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                              + "unexpected exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return explicitPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Merges the specified policyMapping value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * inhibitPolicyMapping field of the <code>PolicyConstraints</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * extension obtained from the certificate. A policyMapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * value of -1 implies no constraint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param policyMapping an integer which indicates if policy mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * is inhibited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param currCert the Certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @return returns the new policyMapping value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @exception CertPathValidatorException Exception thrown if an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    static int mergePolicyMapping(int policyMapping, X509CertImpl currCert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if ((policyMapping > 0) && !X509CertImpl.isSelfIssued(currCert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            policyMapping--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            PolicyConstraintsExtension polConstExt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                = currCert.getPolicyConstraintsExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            if (polConstExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                return policyMapping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   333
            int inhibit =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   334
                polConstExt.get(PolicyConstraintsExtension.INHIBIT).intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                debug.println("PolicyChecker.mergePolicyMapping() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    + "inhibit Index from cert = " + inhibit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (inhibit != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                if ((policyMapping == -1) || (inhibit < policyMapping)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    policyMapping = inhibit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   344
        } catch (IOException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                debug.println("PolicyChecker.mergePolicyMapping "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                              + "unexpected exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return policyMapping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Merges the specified inhibitAnyPolicy value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * SkipCerts value of the InhibitAnyPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * extension obtained from the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param inhibitAnyPolicy an integer which indicates whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * "any-policy" is considered a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param currCert the Certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @return returns the new inhibitAnyPolicy value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @exception CertPathValidatorException Exception thrown if an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    static int mergeInhibitAnyPolicy(int inhibitAnyPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        X509CertImpl currCert) throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if ((inhibitAnyPolicy > 0) && !X509CertImpl.isSelfIssued(currCert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            inhibitAnyPolicy--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            InhibitAnyPolicyExtension inhAnyPolExt = (InhibitAnyPolicyExtension)
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   377
                currCert.getExtension(InhibitAnyPolicy_Id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (inhAnyPolExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                return inhibitAnyPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   381
            int skipCerts =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   382
                inhAnyPolExt.get(InhibitAnyPolicyExtension.SKIP_CERTS).intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                debug.println("PolicyChecker.mergeInhibitAnyPolicy() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    + "skipCerts Index from cert = " + skipCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (skipCerts != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                if (skipCerts < inhibitAnyPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    inhibitAnyPolicy = skipCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   392
        } catch (IOException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                debug.println("PolicyChecker.mergeInhibitAnyPolicy "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                              + "unexpected exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return inhibitAnyPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Processes certificate policies in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param certIndex the index of the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @param initPolicies the initial policies required by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param explicitPolicy an integer which indicates if a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * valid policy tree is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param policyMapping an integer which indicates if policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * mapping is inhibited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param inhibitAnyPolicy an integer which indicates whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * "any-policy" is considered a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param rejectPolicyQualifiers a boolean indicating whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * user wants to reject policies that have qualifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param origRootNode the root node of the valid policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param currCert the Certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param finalCert a boolean indicating whether currCert is the final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * cert in the cert path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @return the root node of the valid policy tree after modification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @exception CertPathValidatorException Exception thrown if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * error occurs while processing policies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    static PolicyNodeImpl processPolicies(int certIndex, Set<String> initPolicies,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int explicitPolicy, int policyMapping, int inhibitAnyPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        boolean rejectPolicyQualifiers, PolicyNodeImpl origRootNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        X509CertImpl currCert, boolean finalCert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        boolean policiesCritical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        List<PolicyInformation> policyInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        PolicyNodeImpl rootNode = null;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   434
        Set<PolicyQualifierInfo> anyQuals = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (origRootNode == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            rootNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            rootNode = origRootNode.copyTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // retrieve policyOIDs from currCert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        CertificatePoliciesExtension currCertPolicies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            = currCert.getCertificatePoliciesExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        // PKIX: Section 6.1.3: Step (d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if ((currCertPolicies != null) && (rootNode != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            policiesCritical = currCertPolicies.isCritical();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    + "policiesCritical = " + policiesCritical);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   453
                policyInfo = currCertPolicies.get(CertificatePoliciesExtension.POLICIES);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                throw new CertPathValidatorException("Exception while "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    + "retrieving policyOIDs", ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    + "rejectPolicyQualifiers = " + rejectPolicyQualifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            boolean foundAnyPolicy = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            // process each policy in cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            for (PolicyInformation curPolInfo : policyInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                String curPolicy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    curPolInfo.getPolicyIdentifier().getIdentifier().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if (curPolicy.equals(ANY_POLICY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    foundAnyPolicy = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    anyQuals = curPolInfo.getPolicyQualifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    // PKIX: Section 6.1.3: Step (d)(1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                      + "processing policy: " + curPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    // retrieve policy qualifiers from cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    Set<PolicyQualifierInfo> pQuals =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                        curPolInfo.getPolicyQualifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    // reject cert if we find critical policy qualifiers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    // the policyQualifiersRejected flag is set in the params
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    if (!pQuals.isEmpty() && rejectPolicyQualifiers &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        policiesCritical) {
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   487
                        throw new CertPathValidatorException(
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   488
                            "critical policy qualifiers present in certificate",
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   489
                            null, null, -1, PKIXReason.INVALID_POLICY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    // PKIX: Section 6.1.3: Step (d)(1)(i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    boolean foundMatch = processParents(certIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        policiesCritical, rejectPolicyQualifiers, rootNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        curPolicy, pQuals, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    if (!foundMatch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        // PKIX: Section 6.1.3: Step (d)(1)(ii)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                        processParents(certIndex, policiesCritical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                            rejectPolicyQualifiers, rootNode, curPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                            pQuals, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            // PKIX: Section 6.1.3: Step (d)(2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (foundAnyPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                if ((inhibitAnyPolicy > 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        (!finalCert && X509CertImpl.isSelfIssued(currCert))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                        debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                            + "processing policy: " + ANY_POLICY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    processParents(certIndex, policiesCritical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        rejectPolicyQualifiers, rootNode, ANY_POLICY, anyQuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            // PKIX: Section 6.1.3: Step (d)(3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            rootNode.prune(certIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (!rootNode.getChildren().hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                rootNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        } else if (currCertPolicies == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                              + "no policies present in cert");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            // PKIX: Section 6.1.3: Step (e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            rootNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        // We delay PKIX: Section 6.1.3: Step (f) to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        // because the code that follows may delete some nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        // resulting in a null tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        if (rootNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (!finalCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                // PKIX: Section 6.1.4: Steps (a)-(b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                rootNode = processPolicyMappings(currCert, certIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    policyMapping, rootNode, policiesCritical, anyQuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        // At this point, we optimize the PKIX algorithm by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        // removing those nodes which would later have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        // been removed by PKIX: Section 6.1.5: Step (g)(iii)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if ((rootNode != null) && (!initPolicies.contains(ANY_POLICY))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            && (currCertPolicies != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            rootNode = removeInvalidNodes(rootNode, certIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                                          initPolicies, currCertPolicies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            // PKIX: Section 6.1.5: Step (g)(iii)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            if ((rootNode != null) && finalCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                // rewrite anyPolicy leaf nodes (see method comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                rootNode = rewriteLeafNodes(certIndex, initPolicies, rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (finalCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            // PKIX: Section 6.1.5: Steps (a) and (b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            explicitPolicy = mergeExplicitPolicy(explicitPolicy, currCert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                             finalCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        // PKIX: Section 6.1.3: Step (f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        // verify that either explicit policy is greater than 0 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // the valid_policy_tree is not equal to NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if ((explicitPolicy == 0) && (rootNode == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            throw new CertPathValidatorException
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   573
                ("non-null policy tree required and policy tree is null",
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   574
                 null, null, -1, PKIXReason.INVALID_POLICY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   581
     * Rewrite leaf nodes at the end of validation as described in RFC 5280
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * section 6.1.5: Step (g)(iii). Leaf nodes with anyPolicy are replaced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * by nodes explicitly representing initial policies not already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * represented by leaf nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * This method should only be called when processing the final cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * and if the policy tree is not null and initial policies is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * anyPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @param certIndex the depth of the tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @param initPolicies Set of user specified initial policies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param rootNode the root of the policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    private static PolicyNodeImpl rewriteLeafNodes(int certIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            Set<String> initPolicies, PolicyNodeImpl rootNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        Set<PolicyNodeImpl> anyNodes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        rootNode.getPolicyNodesValid(certIndex, ANY_POLICY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (anyNodes.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            return rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        PolicyNodeImpl anyNode = anyNodes.iterator().next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        PolicyNodeImpl parentNode = (PolicyNodeImpl)anyNode.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        parentNode.deleteChild(anyNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        // see if there are any initialPolicies not represented by leaf nodes
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   605
        Set<String> initial = new HashSet<>(initPolicies);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        for (PolicyNodeImpl node : rootNode.getPolicyNodes(certIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            initial.remove(node.getValidPolicy());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (initial.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            // we deleted the anyPolicy node and have nothing to re-add,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            // so we need to prune the tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            rootNode.prune(certIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            if (rootNode.getChildren().hasNext() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                rootNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            boolean anyCritical = anyNode.isCritical();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            Set<PolicyQualifierInfo> anyQualifiers =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                                anyNode.getPolicyQualifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            for (String policy : initial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                Set<String> expectedPolicies = Collections.singleton(policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                PolicyNodeImpl node = new PolicyNodeImpl(parentNode, policy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    anyQualifiers, anyCritical, expectedPolicies, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Finds the policy nodes of depth (certIndex-1) where curPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * is in the expected policy set and creates a new child node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * appropriately. If matchAny is true, then a value of ANY_POLICY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * in the expected policy set will match any curPolicy. If matchAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * is false, then the expected policy set must exactly contain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * curPolicy to be considered a match. This method returns a boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * value indicating whether a match was found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @param certIndex the index of the certificate whose policy is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * being processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param policiesCritical a boolean indicating whether the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * policies extension is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @param rejectPolicyQualifiers a boolean indicating whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * user wants to reject policies that have qualifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @param rootNode the root node of the valid policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param curPolicy a String representing the policy being processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param pQuals the policy qualifiers of the policy being processed or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * empty Set if there are no qualifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @param matchAny a boolean indicating whether a value of ANY_POLICY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * in the expected policy set will be considered a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @return a boolean indicating whether a match was found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @exception CertPathValidatorException Exception thrown if error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    private static boolean processParents(int certIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        boolean policiesCritical, boolean rejectPolicyQualifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        PolicyNodeImpl rootNode, String curPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        Set<PolicyQualifierInfo> pQuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        boolean matchAny) throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        boolean foundMatch = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            debug.println("PolicyChecker.processParents(): matchAny = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                + matchAny);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        // find matching parents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        Set<PolicyNodeImpl> parentNodes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                rootNode.getPolicyNodesExpected(certIndex - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                                curPolicy, matchAny);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        // for each matching parent, extend policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        for (PolicyNodeImpl curParent : parentNodes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                debug.println("PolicyChecker.processParents() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                              + "found parent:\n" + curParent.asString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            foundMatch = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            String curParPolicy = curParent.getValidPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            PolicyNodeImpl curNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            Set<String> curExpPols = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            if (curPolicy.equals(ANY_POLICY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                // do step 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                Set<String> parExpPols = curParent.getExpectedPolicies();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            parentExplicitPolicies:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                for (String curParExpPol : parExpPols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    Iterator<PolicyNodeImpl> childIter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                                        curParent.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    while (childIter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                        PolicyNodeImpl childNode = childIter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        String childPolicy = childNode.getValidPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        if (curParExpPol.equals(childPolicy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                                debug.println(childPolicy + " in parent's "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                                    + "expected policy set already appears in "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                                    + "child node");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                            continue parentExplicitPolicies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   702
                    Set<String> expPols = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    expPols.add(curParExpPol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    curNode = new PolicyNodeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        (curParent, curParExpPol, pQuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                         policiesCritical, expPols, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                curExpPols = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                curExpPols.add(curPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                curNode = new PolicyNodeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    (curParent, curPolicy, pQuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                     policiesCritical, curExpPols, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return foundMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Processes policy mappings in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @param currCert the Certificate to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @param certIndex the index of the current certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @param policyMapping an integer which indicates if policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * mapping is inhibited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @param rootNode the root node of the valid policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @param policiesCritical a boolean indicating if the certificate policies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * extension is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @param anyQuals the qualifiers associated with ANY-POLICY, or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * Set if there are no qualifiers associated with ANY-POLICY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @return the root node of the valid policy tree after modification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @exception CertPathValidatorException exception thrown if an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * occurs while processing policy mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    private static PolicyNodeImpl processPolicyMappings(X509CertImpl currCert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        int certIndex, int policyMapping, PolicyNodeImpl rootNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        boolean policiesCritical, Set<PolicyQualifierInfo> anyQuals)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        PolicyMappingsExtension polMappingsExt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            = currCert.getPolicyMappingsExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (polMappingsExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            debug.println("PolicyChecker.processPolicyMappings() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                + "inside policyMapping check");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        List<CertificatePolicyMap> maps = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   755
            maps = polMappingsExt.get(PolicyMappingsExtension.MAP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                debug.println("PolicyChecker.processPolicyMappings() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    + "mapping exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            throw new CertPathValidatorException("Exception while checking "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                                 + "mapping", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        boolean childDeleted = false;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   767
        for (CertificatePolicyMap polMap : maps) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            String issuerDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                = polMap.getIssuerIdentifier().getIdentifier().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            String subjectDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                = polMap.getSubjectIdentifier().getIdentifier().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                debug.println("PolicyChecker.processPolicyMappings() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                              + "issuerDomain = " + issuerDomain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                debug.println("PolicyChecker.processPolicyMappings() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                              + "subjectDomain = " + subjectDomain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            if (issuerDomain.equals(ANY_POLICY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                throw new CertPathValidatorException
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   781
                    ("encountered an issuerDomainPolicy of ANY_POLICY",
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   782
                     null, null, -1, PKIXReason.INVALID_POLICY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if (subjectDomain.equals(ANY_POLICY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                throw new CertPathValidatorException
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   787
                    ("encountered a subjectDomainPolicy of ANY_POLICY",
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 790
diff changeset
   788
                     null, null, -1, PKIXReason.INVALID_POLICY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            Set<PolicyNodeImpl> validNodes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                rootNode.getPolicyNodesValid(certIndex, issuerDomain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            if (!validNodes.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                for (PolicyNodeImpl curNode : validNodes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    if ((policyMapping > 0) || (policyMapping == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        curNode.addExpectedPolicy(subjectDomain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    } else if (policyMapping == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                        PolicyNodeImpl parentNode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                            (PolicyNodeImpl) curNode.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                            debug.println("PolicyChecker.processPolicyMappings"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                                + "() before deleting: policy tree = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                + rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                        parentNode.deleteChild(curNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                        childDeleted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                            debug.println("PolicyChecker.processPolicyMappings"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                                + "() after deleting: policy tree = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                + rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            } else { // no node of depth i has a valid policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                if ((policyMapping > 0) || (policyMapping == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    Set<PolicyNodeImpl> validAnyNodes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                        rootNode.getPolicyNodesValid(certIndex, ANY_POLICY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    for (PolicyNodeImpl curAnyNode : validAnyNodes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                        PolicyNodeImpl curAnyNodeParent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                            (PolicyNodeImpl) curAnyNode.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   820
                        Set<String> expPols = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                        expPols.add(subjectDomain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                        PolicyNodeImpl curNode = new PolicyNodeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                            (curAnyNodeParent, issuerDomain, anyQuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                             policiesCritical, expPols, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        if (childDeleted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            rootNode.prune(certIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            if (!rootNode.getChildren().hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    debug.println("setting rootNode to null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                rootNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        return rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Removes those nodes which do not intersect with the initial policies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * specified by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param rootNode the root node of the valid policy tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param certIndex the index of the certificate being processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @param initPolicies the Set of policies required by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @param currCertPolicies the CertificatePoliciesExtension of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * certificate being processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @returns the root node of the valid policy tree after modification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @exception CertPathValidatorException Exception thrown if error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    private static PolicyNodeImpl removeInvalidNodes(PolicyNodeImpl rootNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        int certIndex, Set<String> initPolicies,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        CertificatePoliciesExtension currCertPolicies)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        List<PolicyInformation> policyInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   862
            policyInfo = currCertPolicies.get(CertificatePoliciesExtension.POLICIES);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            throw new CertPathValidatorException("Exception while "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                + "retrieving policyOIDs", ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        boolean childDeleted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        for (PolicyInformation curPolInfo : policyInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            String curPolicy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                curPolInfo.getPolicyIdentifier().getIdentifier().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                              + "processing policy second time: " + curPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            Set<PolicyNodeImpl> validNodes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                        rootNode.getPolicyNodesValid(certIndex, curPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            for (PolicyNodeImpl curNode : validNodes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                PolicyNodeImpl parentNode = (PolicyNodeImpl)curNode.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                if (parentNode.getValidPolicy().equals(ANY_POLICY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    if ((!initPolicies.contains(curPolicy)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                        (!curPolicy.equals(ANY_POLICY))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                            debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                + "before deleting: policy tree = " + rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                        parentNode.deleteChild(curNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                        childDeleted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                            debug.println("PolicyChecker.processPolicies() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                                + "after deleting: policy tree = " + rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        if (childDeleted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            rootNode.prune(certIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (!rootNode.getChildren().hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                rootNode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        return rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * Gets the root node of the valid policy tree, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * valid policy tree is null. Marks each node of the returned tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * immutable and thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @returns the root node of the valid policy tree, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * the valid policy tree is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    PolicyNode getPolicyTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        if (rootNode == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            PolicyNodeImpl policyTree = rootNode.copyTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            policyTree.setImmutable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            return policyTree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
}