src/java.base/share/classes/javax/crypto/JceSecurity.java.template
author apetcher
Tue, 30 Oct 2018 13:48:19 -0400
changeset 52330 df10a0cacf3e
parent 50817 fa1e04811ff6
child 54996 3081932e7efd
permissions -rw-r--r--
8205476: KeyAgreement#generateSecret is not reset for ECDH based algorithm Summary: Clarify spec of generateSecret and modify ECDH in SunEC to conform to spec Reviewed-by: mullan
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
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 47216
diff changeset
    60
import jdk.internal.util.StaticProperty;
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 47216
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import sun.security.jca.GetInstance.Instance;
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    64
import sun.security.util.Debug;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * This class instantiates implementations of JCE engine classes from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * providers registered with the java.security.Security object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author Sharon Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
final class JceSecurity {
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 47216
diff changeset
    76
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 47216
diff changeset
    77
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
    78
    private static final Debug debug = Debug.getInstance("jca");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static final SecureRandom RANDOM = new SecureRandom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // The defaultPolicy and exemptPolicy will be set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // in the static initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static CryptoPermissions defaultPolicy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static CryptoPermissions exemptPolicy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // Map<Provider,?> of the providers we already have verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // value == PROVIDER_VERIFIED is successfully verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // value is failure cause Exception in error case
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
    90
    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
    91
            new IdentityHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // Map<Provider,?> of the providers currently being verified
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
    94
    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
    95
            new IdentityHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
36119
75308cd1bf2c 8149417: Use final restricted flag
xuelei
parents: 32649
diff changeset
    97
    private static final boolean isRestricted;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Don't let anyone instantiate this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private JceSecurity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   107
            AccessController.doPrivileged(
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 26861
diff changeset
   108
                new PrivilegedExceptionAction<> () {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   109
                    @Override
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   110
                    public Void run() throws Exception {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   111
                        setupJurisdictionPolicies();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   112
                        return null;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   113
                    }
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   114
                }
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   115
            );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            isRestricted = defaultPolicy.implies(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                CryptoAllPermission.INSTANCE) ? false : true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } catch (Exception e) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   120
            throw new SecurityException(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   121
                    "Can not initialize cryptographic mechanism", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   125
    static Instance getInstance(String type, Class<?> clazz, String algorithm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        Service s = GetInstance.getService(type, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Exception ve = getVerificationResult(s.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (ve != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            String msg = "JCE cannot authenticate the provider " + provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw (NoSuchProviderException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                new NoSuchProviderException(msg).initCause(ve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return GetInstance.getInstance(s, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   138
    static Instance getInstance(String type, Class<?> clazz, String algorithm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Service s = GetInstance.getService(type, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Exception ve = JceSecurity.getVerificationResult(provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (ve != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            String msg = "JCE cannot authenticate the provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                + provider.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throw new SecurityException(msg, ve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return GetInstance.getInstance(s, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   150
    static Instance getInstance(String type, Class<?> clazz, String algorithm)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throws NoSuchAlgorithmException {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   152
        List<Service> services = GetInstance.getServices(type, algorithm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        NoSuchAlgorithmException failure = null;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   154
        for (Service s : services) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (canUseProvider(s.getProvider()) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // allow only signed providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                Instance instance = GetInstance.getInstance(s, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                return instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                failure = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        throw new NoSuchAlgorithmException("Algorithm " + algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                + " not available", failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Verify if the JAR at URL codeBase is a signed exempt application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * JAR file and returns the permissions bundled with the JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @throws Exception on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    static CryptoPermissions verifyExemptJar(URL codeBase) throws Exception {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   177
        ProviderVerifier pv = new ProviderVerifier(codeBase, true);
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   178
        pv.verify();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   179
        return pv.getPermissions();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Verify if the JAR at URL codeBase is a signed provider JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @throws Exception on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   187
    static void verifyProvider(URL codeBase, Provider p) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // Verify the provider JAR file and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // supporting JAR files if there are any.
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   190
        ProviderVerifier pv = new ProviderVerifier(codeBase, p, false);
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   191
        pv.verify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
   194
    private static final Object PROVIDER_VERIFIED = Boolean.TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Verify that the provider JAR files are signed properly, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * means the signer's certificate can be traced back to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * JCE trusted CA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Return null if ok, failure Exception if verification failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    static synchronized Exception getVerificationResult(Provider p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        Object o = verificationResults.get(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (o == PROVIDER_VERIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        } else if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return (Exception)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (verifyingProviders.get(p) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // this method is static synchronized, must be recursion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // return failure now but do not save the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return new NoSuchProviderException("Recursion during verification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            verifyingProviders.put(p, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            URL providerURL = getCodeBase(p.getClass());
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   217
            verifyProvider(providerURL, p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            // Verified ok, cache result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            verificationResults.put(p, PROVIDER_VERIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            verificationResults.put(p, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            verifyingProviders.remove(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    // return whether this provider is properly signed and can be used by JCE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    static boolean canUseProvider(Provider p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return getVerificationResult(p) == null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    // dummy object to represent null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private static final URL NULL_URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        try {
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   239
            NULL_URL = new URL("http://null.oracle.com/");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    // 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
   246
    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
   247
            new WeakHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /*
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
   250
     * Returns the CodeBase for the given class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   252
    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
   253
        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
   254
            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
   255
            if (url == null) {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   256
                url = AccessController.doPrivileged(
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 26861
diff changeset
   257
                    new PrivilegedAction<>() {
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   258
                        @Override
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   259
                        public URL run() {
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   260
                            ProtectionDomain pd = clazz.getProtectionDomain();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   261
                            if (pd != null) {
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   262
                                CodeSource cs = pd.getCodeSource();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   263
                                if (cs != null) {
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   264
                                    return cs.getLocation();
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   265
                                }
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
   266
                            }
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   267
                            return NULL_URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        }
26861
47dde7f5cf36 8058845: Update JCE environment for build improvements
wetmore
parents: 25859
diff changeset
   269
                    });
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
   270
                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
   271
            }
767c30e88a61 8028627: Unsynchronized code path from javax.crypto.Cipher to the WeakHashMap used by JceSecurity to store codebase mappings
robm
parents: 10336
diff changeset
   272
            return (url == NULL_URL) ? null : url;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   276
    // This is called from within an doPrivileged block.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static void setupJurisdictionPolicies() throws Exception {
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   278
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   279
        // Sanity check the crypto.policy Security property.  Single
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   280
        // directory entry, no pseudo-directories (".", "..", leading/trailing
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   281
        // path separators). normalize()/getParent() will help later.
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   282
        String cryptoPolicyProperty = Security.getProperty("crypto.policy");
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   283
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   284
        /*
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   285
         * 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
   286
         * 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
   287
         * 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
   288
         * value, then compile the result gensrc.
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
         * Log the warning first.
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   291
         */
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   292
        if (cryptoPolicyProperty == null) {
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   293
            cryptoPolicyProperty = "@@JCE_DEFAULT_POLICY@@";
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   294
            if (debug != null) {
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   295
                debug.println(
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   296
                    "Security Property 'crypto.policy' not found: "
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   297
                    + "using '" + cryptoPolicyProperty + "' as fallback");
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   298
            }
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   299
        }
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   300
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   301
        Path cpPath = Paths.get(cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   302
42365
5e640c2994d6 8170157: Enable unlimited cryptographic policy by default in OracleJDK
wetmore
parents: 40565
diff changeset
   303
        if ((cpPath.getNameCount() != 1) ||
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   304
                (cpPath.compareTo(cpPath.getFileName()) != 0)) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   305
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   306
                "Invalid policy directory name format: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   307
                cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   308
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   310
        // 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
   311
        // case an extra "." or ".." snuck in somehow.
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 47216
diff changeset
   312
        String javaHomeProperty = StaticProperty.javaHome();
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   313
        Path javaHomePolicyPath = Paths.get(javaHomeProperty, "conf",
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   314
                "security", "policy").normalize();
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   315
        Path cryptoPolicyPath = Paths.get(javaHomeProperty, "conf", "security",
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   316
                "policy", cryptoPolicyProperty).normalize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   318
        if (cryptoPolicyPath.getParent().compareTo(javaHomePolicyPath) != 0) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   319
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   320
                "Invalid cryptographic jurisdiction policy directory path: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   321
                cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   322
        }
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   323
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   324
        if (!Files.isDirectory(cryptoPolicyPath)
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   325
                || !Files.isReadable(cryptoPolicyPath)) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   326
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   327
                "Can't read cryptographic policy directory: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   328
                cryptoPolicyProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   331
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   332
                cryptoPolicyPath, "{default,exempt}_*.policy")) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   333
            for (Path entry : stream) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   334
                try (InputStream is = new BufferedInputStream(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   335
                        Files.newInputStream(entry))) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   336
                    String filename = entry.getFileName().toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   338
                    CryptoPermissions tmpPerms = new CryptoPermissions();
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   339
                    tmpPerms.load(is);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   341
                    if (filename.startsWith("default_")) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   342
                        // Did we find a default perms?
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   343
                        defaultPolicy = ((defaultPolicy == null) ? tmpPerms :
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   344
                                defaultPolicy.getMinimum(tmpPerms));
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   345
                    } else if (filename.startsWith("exempt_")) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   346
                        // Did we find a exempt perms?
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   347
                        exemptPolicy = ((exemptPolicy == null) ? tmpPerms :
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   348
                                exemptPolicy.getMinimum(tmpPerms));
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   349
                    } else {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   350
                        // This should never happen.  newDirectoryStream
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   351
                        // should only throw return "{default,exempt}_*.policy"
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   352
                        throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   353
                            "Unexpected jurisdiction policy files in : " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   354
                            cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   355
                    }
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   356
                } catch (Exception e) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   357
                    throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   358
                        "Couldn't parse jurisdiction policy files in: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   359
                        cryptoPolicyProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   362
        } catch (DirectoryIteratorException ex) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   363
            // I/O error encountered during the iteration,
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   364
            // the cause is an IOException
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   365
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   366
                "Couldn't iterate through the jurisdiction policy files: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   367
                cryptoPolicyProperty);
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   368
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   370
        // Must have a default policy
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   371
        if ((defaultPolicy == null) || defaultPolicy.isEmpty()) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   372
            throw new SecurityException(
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   373
                "Missing mandatory jurisdiction policy files: " +
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   374
                cryptoPolicyProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
40565
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   376
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   377
        // 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
   378
        if ((exemptPolicy != null) && exemptPolicy.isEmpty()) {
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   379
            exemptPolicy = null;
3ac0ba151e70 8061842: Package jurisdiction policy files as something other than JAR
wetmore
parents: 36511
diff changeset
   380
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    static CryptoPermissions getDefaultPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return defaultPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    static CryptoPermissions getExemptPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return exemptPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    static boolean isRestricted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return isRestricted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
}