jdk/src/java.base/share/classes/javax/crypto/JceSecurity.java.template
author wetmore
Mon, 05 Dec 2016 17:04:02 -0800
changeset 42365 5e640c2994d6
parent 40565 jdk/src/java.base/share/classes/javax/crypto/JceSecurity.java@3ac0ba151e70
permissions -rw-r--r--
8170157: Enable unlimited cryptographic policy by default in OracleJDK 8169335: Add a crypto policy fallback in case Security Property 'crypto.policy' does not exist Reviewed-by: erikj, ihse, weijun, xuelei, coffeys
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36119
75308cd1bf2c 8149417: Use final restricted flag
xuelei
parents: 32649
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    26
/*
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    27
 * README README README README README README README README README
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    28
 *
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    29
 * This file is the template for generating the JceSecurity.java source
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    30
 * file.
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    31
 *
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    32
 * In the current jdk builds, this file is first preprocessed to replace
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    33
 * @@JCE_DEFAULT_POLICY@ [sic] with "limited" or "unlimited" which is
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    34
 * determined by the $(UNLIMTED_CRYPTO) make variable.  This variable is
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    35
 * set by top-level configure script, using either
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    36
 * --disable-unlimited-crypto or --enable-unlimited-crypto [default].
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    37
 *
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    38
 * Since this file is a generated source, incremental changes to
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    39
 * this file require regenerating the source.  Compilation options:
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    40
 *
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    41
 *     (fewer dependencies/"faster" ones first)
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    42
 *
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    43
 * 1.  make JDK_FILTER=javax/crypto java.base-gensrc-only java.base-java-only
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    44
 * 2.  make java.base-gensrc-only java.base-java-only
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    45
 * 3.  make java.base-gensrc-only java.base-only
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    46
 * 4.  make java.base-only
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    47
 * 5.  make
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    48
 */
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    49
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
package javax.crypto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.net.URL;
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
    55
import java.nio.file.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.security.Provider.Service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.security.jca.GetInstance.Instance;
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    62
import sun.security.util.Debug;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * This class instantiates implementations of JCE engine classes from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * providers registered with the java.security.Security object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @author Sharon Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
final class JceSecurity {
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    74
  
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    75
  	
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    76
    private static final Debug debug = Debug.getInstance("jca");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static final SecureRandom RANDOM = new SecureRandom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // The defaultPolicy and exemptPolicy will be set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // in the static initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static CryptoPermissions defaultPolicy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static CryptoPermissions exemptPolicy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // Map<Provider,?> of the providers we already have verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // value == PROVIDER_VERIFIED is successfully verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // value is failure cause Exception in error case
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
    88
    private static final Map<Provider, Object> verificationResults =
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    89
            new IdentityHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Map<Provider,?> of the providers currently being verified
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
    92
    private static final Map<Provider, Object> verifyingProviders =
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    93
            new IdentityHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
36119
75308cd1bf2c 8149417: Use final restricted flag
xuelei
parents: 32649
diff changeset
    95
    private static final boolean isRestricted;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Don't let anyone instantiate this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private JceSecurity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   105
            AccessController.doPrivileged(
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 26861
diff changeset
   106
                new PrivilegedExceptionAction<> () {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   107
                    @Override
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   108
                    public Void run() throws Exception {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   109
                        setupJurisdictionPolicies();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   110
                        return null;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   111
                    }
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   112
                }
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   113
            );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            isRestricted = defaultPolicy.implies(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                CryptoAllPermission.INSTANCE) ? false : true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } catch (Exception e) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   118
            throw new SecurityException(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   119
                    "Can not initialize cryptographic mechanism", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   123
    static Instance getInstance(String type, Class<?> clazz, String algorithm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        Service s = GetInstance.getService(type, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Exception ve = getVerificationResult(s.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (ve != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            String msg = "JCE cannot authenticate the provider " + provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw (NoSuchProviderException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                new NoSuchProviderException(msg).initCause(ve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return GetInstance.getInstance(s, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   136
    static Instance getInstance(String type, Class<?> clazz, String algorithm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Service s = GetInstance.getService(type, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Exception ve = JceSecurity.getVerificationResult(provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (ve != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            String msg = "JCE cannot authenticate the provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                + provider.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new SecurityException(msg, ve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return GetInstance.getInstance(s, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   148
    static Instance getInstance(String type, Class<?> clazz, String algorithm)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throws NoSuchAlgorithmException {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   150
        List<Service> services = GetInstance.getServices(type, algorithm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        NoSuchAlgorithmException failure = null;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   152
        for (Service s : services) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (canUseProvider(s.getProvider()) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                // allow only signed providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                Instance instance = GetInstance.getInstance(s, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                failure = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        throw new NoSuchAlgorithmException("Algorithm " + algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                + " not available", failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Verify if the JAR at URL codeBase is a signed exempt application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * JAR file and returns the permissions bundled with the JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @throws Exception on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    static CryptoPermissions verifyExemptJar(URL codeBase) throws Exception {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   175
        ProviderVerifier pv = new ProviderVerifier(codeBase, true);
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   176
        pv.verify();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   177
        return pv.getPermissions();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Verify if the JAR at URL codeBase is a signed provider JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @throws Exception on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   185
    static void verifyProvider(URL codeBase, Provider p) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // Verify the provider JAR file and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // supporting JAR files if there are any.
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   188
        ProviderVerifier pv = new ProviderVerifier(codeBase, p, false);
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   189
        pv.verify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
   192
    private static final Object PROVIDER_VERIFIED = Boolean.TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Verify that the provider JAR files are signed properly, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * means the signer's certificate can be traced back to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * JCE trusted CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Return null if ok, failure Exception if verification failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    static synchronized Exception getVerificationResult(Provider p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        Object o = verificationResults.get(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (o == PROVIDER_VERIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } else if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return (Exception)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (verifyingProviders.get(p) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // this method is static synchronized, must be recursion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // return failure now but do not save the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return new NoSuchProviderException("Recursion during verification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            verifyingProviders.put(p, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            URL providerURL = getCodeBase(p.getClass());
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   215
            verifyProvider(providerURL, p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // Verified ok, cache result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            verificationResults.put(p, PROVIDER_VERIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            verificationResults.put(p, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            verifyingProviders.remove(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // return whether this provider is properly signed and can be used by JCE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    static boolean canUseProvider(Provider p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return getVerificationResult(p) == null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    // dummy object to represent null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private static final URL NULL_URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        try {
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   237
            NULL_URL = new URL("http://null.oracle.com/");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    // reference to a Map we use as a cache for codebases
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   244
    private static final Map<Class<?>, URL> codeBaseCacheRef =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   245
            new WeakHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /*
24501
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   248
     * Returns the CodeBase for the given class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   250
    static URL getCodeBase(final Class<?> clazz) {
24501
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   251
        synchronized (codeBaseCacheRef) {
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   252
            URL url = codeBaseCacheRef.get(clazz);
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   253
            if (url == null) {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   254
                url = AccessController.doPrivileged(
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 26861
diff changeset
   255
                    new PrivilegedAction<>() {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   256
                        @Override
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   257
                        public URL run() {
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   258
                            ProtectionDomain pd = clazz.getProtectionDomain();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   259
                            if (pd != null) {
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   260
                                CodeSource cs = pd.getCodeSource();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   261
                                if (cs != null) {
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   262
                                    return cs.getLocation();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   263
                                }
24501
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   264
                            }
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   265
                            return NULL_URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        }
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   267
                    });
24501
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   268
                codeBaseCacheRef.put(clazz, url);
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   269
            }
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   270
            return (url == NULL_URL) ? null : url;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   274
    // This is called from within an doPrivileged block.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static void setupJurisdictionPolicies() throws Exception {
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   276
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   277
        // Sanity check the crypto.policy Security property.  Single
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   278
        // directory entry, no pseudo-directories (".", "..", leading/trailing
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   279
        // path separators). normalize()/getParent() will help later.
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   280
        String cryptoPolicyProperty = Security.getProperty("crypto.policy");
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   281
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   282
        /*
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   283
         * In case no property is present, rather than fail catastrophically,
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   284
         * we at least try for a "sane" value, which is what we were
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   285
         * built with.  We first preprocess this file to plug in that
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   286
         * value, then compile the result gensrc.
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   287
         *
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   288
         * Log the warning first.
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   289
         */
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   290
        if (cryptoPolicyProperty == null) {
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   291
            cryptoPolicyProperty = "@@JCE_DEFAULT_POLICY@@";
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   292
            if (debug != null) {
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   293
                debug.println(
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   294
                    "Security Property 'crypto.policy' not found: "
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   295
                    + "using '" + cryptoPolicyProperty + "' as fallback");
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   296
            }
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   297
        }
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   298
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   299
        Path cpPath = Paths.get(cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   300
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   301
        if ((cpPath.getNameCount() != 1) ||
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   302
                (cpPath.compareTo(cpPath.getFileName()) != 0)) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   303
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   304
                "Invalid policy directory name format: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   305
                cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   306
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   308
        // Prepend java.home to get the full path.  normalize() in
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   309
        // case an extra "." or ".." snuck in somehow.
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   310
        String javaHomeProperty = System.getProperty("java.home");
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   311
        Path javaHomePolicyPath = Paths.get(javaHomeProperty, "conf",
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   312
                "security", "policy").normalize();
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   313
        Path cryptoPolicyPath = Paths.get(javaHomeProperty, "conf", "security",
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   314
                "policy", cryptoPolicyProperty).normalize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   316
        if (cryptoPolicyPath.getParent().compareTo(javaHomePolicyPath) != 0) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   317
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   318
                "Invalid cryptographic jurisdiction policy directory path: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   319
                cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   320
        }
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   321
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   322
        if (!Files.isDirectory(cryptoPolicyPath)
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   323
                || !Files.isReadable(cryptoPolicyPath)) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   324
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   325
                "Can't read cryptographic policy directory: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   326
                cryptoPolicyProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   329
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   330
                cryptoPolicyPath, "{default,exempt}_*.policy")) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   331
            for (Path entry : stream) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   332
                try (InputStream is = new BufferedInputStream(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   333
                        Files.newInputStream(entry))) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   334
                    String filename = entry.getFileName().toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   336
                    CryptoPermissions tmpPerms = new CryptoPermissions();
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   337
                    tmpPerms.load(is);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   339
                    if (filename.startsWith("default_")) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   340
                        // Did we find a default perms?
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   341
                        defaultPolicy = ((defaultPolicy == null) ? tmpPerms :
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   342
                                defaultPolicy.getMinimum(tmpPerms));
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   343
                    } else if (filename.startsWith("exempt_")) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   344
                        // Did we find a exempt perms?
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   345
                        exemptPolicy = ((exemptPolicy == null) ? tmpPerms :
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   346
                                exemptPolicy.getMinimum(tmpPerms));
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   347
                    } else {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   348
                        // This should never happen.  newDirectoryStream
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   349
                        // should only throw return "{default,exempt}_*.policy"
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   350
                        throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   351
                            "Unexpected jurisdiction policy files in : " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   352
                            cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   353
                    }
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   354
                } catch (Exception e) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   355
                    throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   356
                        "Couldn't parse jurisdiction policy files in: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   357
                        cryptoPolicyProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   360
        } catch (DirectoryIteratorException ex) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   361
            // I/O error encountered during the iteration,
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   362
            // the cause is an IOException
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   363
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   364
                "Couldn't iterate through the jurisdiction policy files: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   365
                cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   366
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   368
        // Must have a default policy
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   369
        if ((defaultPolicy == null) || defaultPolicy.isEmpty()) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   370
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   371
                "Missing mandatory jurisdiction policy files: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   372
                cryptoPolicyProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   374
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   375
        // If there was an empty exempt policy file, ignore it.
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   376
        if ((exemptPolicy != null) && exemptPolicy.isEmpty()) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   377
            exemptPolicy = null;
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   378
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    static CryptoPermissions getDefaultPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return defaultPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    static CryptoPermissions getExemptPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return exemptPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    static boolean isRestricted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return isRestricted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
}