jdk/src/share/classes/javax/crypto/JceSecurityManager.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
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 1999-2007 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 javax.crypto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.jar.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * The JCE security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>The JCE security manager is responsible for determining the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * allowable cryptographic strength for a given applet/application, for a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * algorithm, by consulting the configured jurisdiction policy files and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the cryptographic permissions bundled with the applet/application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>Note that this security manager is never installed, only instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
final class JceSecurityManager extends SecurityManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final CryptoPermissions defaultPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final CryptoPermissions exemptPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final CryptoAllPermission allPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final Vector TrustedCallersCache = new Vector(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final Map exemptCache = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // singleton instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static final JceSecurityManager INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        defaultPolicy = JceSecurity.getDefaultPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        exemptPolicy = JceSecurity.getExemptPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        allPerm = CryptoAllPermission.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        INSTANCE = (JceSecurityManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
              AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                  public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                      return new JceSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
              });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private JceSecurityManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Returns the maximum allowable crypto strength for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * applet/application, for the given algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    CryptoPermission getCryptoPermission(String alg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // Need to convert to uppercase since the crypto perm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // lookup is case sensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        alg = alg.toUpperCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // If CryptoAllPermission is granted by default, we return that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Otherwise, this will be the permission we return if anything goes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // wrong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        CryptoPermission defaultPerm = getDefaultPermission(alg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (defaultPerm == CryptoAllPermission.INSTANCE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // Determine the codebase of the caller of the JCE API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // This is the codebase of the first class which is not in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // javax.crypto.* packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // NOTE: javax.crypto.* package maybe subject to package
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // insertion, so need to check its classloader as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Class[] context = getClassContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        URL callerCodeBase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (i=0; i<context.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            Class cls = context[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            callerCodeBase = JceSecurity.getCodeBase(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (callerCodeBase != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                if (cls.getName().startsWith("javax.crypto.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    // skip jce classes since they aren't the callers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                // use default permission when the caller is system classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (i == context.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        CryptoPermissions appPerms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        synchronized (this.getClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (exemptCache.containsKey(callerCodeBase)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                appPerms = (CryptoPermissions)exemptCache.get(callerCodeBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                appPerms = getAppPermissions(callerCodeBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                exemptCache.put(callerCodeBase, appPerms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (appPerms == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // If the app was granted the special CryptoAllPermission, return that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (appPerms.implies(allPerm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return allPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // Check if the crypto permissions granted to the app contain a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // crypto permission for the requested algorithm that does not require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // any exemption mechanism to be enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // Return that permission, if present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        PermissionCollection appPc = appPerms.getPermissionCollection(alg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (appPc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Enumeration enum_ = appPc.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            CryptoPermission cp = (CryptoPermission)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (cp.getExemptionMechanism() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // Check if the jurisdiction file for exempt applications contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // any entries for the requested algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // If not, return the default permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        PermissionCollection exemptPc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            exemptPolicy.getPermissionCollection(alg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (exemptPc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // In the jurisdiction file for exempt applications, go through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // list of CryptoPermission entries for the requested algorithm, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // stop at the first entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        //  - that is implied by the collection of crypto permissions granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        //    to the app, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        //  - whose exemption mechanism is available from one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        //    registered CSPs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        enum_ = exemptPc.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            CryptoPermission cp = (CryptoPermission)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                ExemptionMechanism.getInstance(cp.getExemptionMechanism());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (cp.getAlgorithm().equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                      CryptoPermission.ALG_NAME_WILDCARD)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    CryptoPermission newCp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    if (cp.getCheckParam()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        newCp = new CryptoPermission(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                alg, cp.getMaxKeySize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                cp.getAlgorithmParameterSpec(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                cp.getExemptionMechanism());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        newCp = new CryptoPermission(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                alg, cp.getMaxKeySize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                cp.getExemptionMechanism());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    if (appPerms.implies(newCp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        return newCp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                if (appPerms.implies(cp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return defaultPerm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static CryptoPermissions getAppPermissions(URL callerCodeBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Check if app is exempt, and retrieve the permissions bundled with it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return JceSecurity.verifyExemptJar(callerCodeBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // Jar verification fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns the default permission for the given algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private CryptoPermission getDefaultPermission(String alg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Enumeration enum_ =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            defaultPolicy.getPermissionCollection(alg).elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return (CryptoPermission)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    // See  bug 4341369 & 4334690 for more info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    boolean isCallerTrusted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // Get the caller and its codebase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        Class[] context = getClassContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        URL callerCodeBase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        for (i=0; i<context.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            callerCodeBase = JceSecurity.getCodeBase(context[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (callerCodeBase != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // The caller is in the JCE framework.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (i == context.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        //The caller has been verified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (TrustedCallersCache.contains(context[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        // Check whether the caller is a trusted provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            JceSecurity.verifyProviderJar(callerCodeBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } catch (Exception e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        TrustedCallersCache.addElement(context[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}