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