jdk/src/share/classes/sun/security/pkcs11/Config.java
author jjg
Mon, 15 Aug 2011 11:48:20 -0700
changeset 10336 0bb1999251f8
parent 9849 eb437e9fba66
child 10781 f8a00c400655
permissions -rw-r--r--
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror Reviewed-by: xuelei, mullan Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9849
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
     2
 * Copyright (c) 2003, 2011, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.pkcs11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import static java.io.StreamTokenizer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.util.PropertyExpander;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.pkcs11.wrapper.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import static sun.security.pkcs11.wrapper.CK_ATTRIBUTE.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static sun.security.pkcs11.TemplateManager.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Configuration container and file parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
final class Config {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final int ERR_HALT       = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final int ERR_IGNORE_ALL = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final int ERR_IGNORE_LIB = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // same as allowSingleThreadedModules but controlled via a system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // and applied to all providers. if set to false, no SunPKCS11 instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // will accept single threaded modules regardless of the setting in their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // config files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final boolean staticAllowSingleThreadedModules;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        String p = "sun.security.pkcs11.allowSingleThreadedModules";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        String s = AccessController.doPrivileged(new GetPropertyAction(p));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if ("false".equalsIgnoreCase(s)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            staticAllowSingleThreadedModules = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            staticAllowSingleThreadedModules = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // temporary storage for configurations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // needed because the SunPKCS11 needs to call the superclass constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // in provider before accessing any instance variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private final static Map<String,Config> configMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                        new HashMap<String,Config>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static Config getConfig(final String name, final InputStream stream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Config config = configMap.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (config != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            config = new Config(name, stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            configMap.put(name, config);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new ProviderException("Error parsing configuration", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    static Config removeConfig(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return configMap.remove(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private final static boolean DEBUG = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static void debug(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            System.out.println(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // Reader and StringTokenizer used during parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private Reader reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private StreamTokenizer st;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private Set<String> parsedKeywords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // name suffix of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // name of the PKCS#11 library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private String library;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // description to pass to the provider class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // slotID of the slot to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private int slotID = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // slot to use, specified as index in the slotlist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private int slotListIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // set of enabled mechanisms (or null to use default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private Set<Long> enabledMechanisms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // set of disabled mechanisms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private Set<Long> disabledMechanisms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // whether to print debug info during startup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private boolean showInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // template manager, initialized from parsed attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private TemplateManager templateManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // how to handle error during startup, one of ERR_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private int handleStartupErrors = ERR_HALT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // flag indicating whether the P11KeyStore should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // be more tolerant of input parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private boolean keyStoreCompatibilityMode = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // flag indicating whether we need to explicitly cancel operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // see Token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private boolean explicitCancel = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    // how often to test for token insertion, if no token is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private int insertionCheckInterval = 2000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // flag inidicating whether to omit the call to C_Initialize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // should be used only if we are running within a process that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    // has already called it (e.g. Plugin inside of Mozilla/NSS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private boolean omitInitialize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // whether to allow modules that only support single threaded access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    // they cannot be used safely from multiple PKCS#11 consumers in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // same process, for example NSS and SunPKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private boolean allowSingleThreadedModules = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    // name of the C function that returns the PKCS#11 functionlist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // This option primarily exists for the deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    // Secmod.Module.getProvider() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private String functionList = "C_GetFunctionList";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // whether to use NSS secmod mode. Implicitly set if nssLibraryDirectory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    // nssSecmodDirectory, or nssModule is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private boolean nssUseSecmod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    // location of the NSS library files (libnss3.so, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private String nssLibraryDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    // location of secmod.db
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    private String nssSecmodDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    // which NSS module to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private String nssModule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private Secmod.DbMode nssDbMode = Secmod.DbMode.READ_WRITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // Whether the P11KeyStore should specify the CKA_NETSCAPE_DB attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    // when creating private keys. Only valid if nssUseSecmod is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private boolean nssNetscapeDbWorkaround = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    // Special init argument string for the NSS softtoken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    // This is used when using the NSS softtoken directly without secmod mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private String nssArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    // whether to use NSS trust attributes for the KeyStore of this provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    // this option is for internal use by the SunPKCS11 code only and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    // works only for NSS providers created via the Secmod API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private boolean nssUseSecmodTrust = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private Config(String filename, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (in == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (filename.startsWith("--")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                // inline config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                String config = filename.substring(2).replace("\\n", "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                reader = new StringReader(config);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                in = new FileInputStream(expand(filename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (reader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            reader = new BufferedReader(new InputStreamReader(in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        parsedKeywords = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        st = new StreamTokenizer(reader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        setupTokenizer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        parse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    String getLibrary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return library;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (description != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return "SunPKCS11-" + name + " using library " + library;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    int getSlotID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return slotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    int getSlotListIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if ((slotID == -1) && (slotListIndex == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // if neither is set, default to first slot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return slotListIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    boolean getShowInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return (SunPKCS11.debug != null) || showInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    TemplateManager getTemplateManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (templateManager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            templateManager = new TemplateManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return templateManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    boolean isEnabled(long m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (enabledMechanisms != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return enabledMechanisms.contains(Long.valueOf(m));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (disabledMechanisms != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            return !disabledMechanisms.contains(Long.valueOf(m));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    int getHandleStartupErrors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return handleStartupErrors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    boolean getKeyStoreCompatibilityMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return keyStoreCompatibilityMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    boolean getExplicitCancel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return explicitCancel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    int getInsertionCheckInterval() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return insertionCheckInterval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    boolean getOmitInitialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return omitInitialize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    boolean getAllowSingleThreadedModules() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return staticAllowSingleThreadedModules && allowSingleThreadedModules;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    String getFunctionList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return functionList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    boolean getNssUseSecmod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return nssUseSecmod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    String getNssLibraryDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return nssLibraryDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    String getNssSecmodDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return nssSecmodDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    String getNssModule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return nssModule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    Secmod.DbMode getNssDbMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return nssDbMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public boolean getNssNetscapeDbWorkaround() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return nssUseSecmod && nssNetscapeDbWorkaround;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    String getNssArgs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return nssArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    boolean getNssUseSecmodTrust() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return nssUseSecmodTrust;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    private static String expand(final String s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return PropertyExpander.expand(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            throw new RuntimeException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    private void setupTokenizer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        st.resetSyntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        st.wordChars('a', 'z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        st.wordChars('A', 'Z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        st.wordChars('0', '9');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        st.wordChars(':', ':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        st.wordChars('.', '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        st.wordChars('_', '_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        st.wordChars('-', '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        st.wordChars('/', '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        st.wordChars('\\', '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        st.wordChars('$', '$');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        st.wordChars('{', '{'); // need {} for property subst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        st.wordChars('}', '}');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        st.wordChars('*', '*');
9261
efb29ab3324e 6986789: Sun pkcs11 provider fails to parse path name containing "+"
valeriep
parents: 7808
diff changeset
   346
        st.wordChars('+', '+');
7808
992bb9918576 6581254: pkcs11 provider fails to parse configuration file contains windows short path
valeriep
parents: 5506
diff changeset
   347
        st.wordChars('~', '~');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        // XXX check ASCII table and add all other characters except special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // special: #="(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        st.whitespaceChars(0, ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        st.commentChar('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        st.eolIsSignificant(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        st.quoteChar('\"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    private ConfigurationException excToken(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return new ConfigurationException(msg + " " + st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private ConfigurationException excLine(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return new ConfigurationException(msg + ", line " + st.lineno());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    private void parse() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            if (token == TT_EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (token == TT_EOL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (token != TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                throw excToken("Unexpected token:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            String word = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (word.equals("name")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                name = parseStringEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            } else if (word.equals("library")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                library = parseLibrary(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            } else if (word.equals("description")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                parseDescription(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            } else if (word.equals("slot")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                parseSlotID(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            } else if (word.equals("slotListIndex")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                parseSlotListIndex(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            } else if (word.equals("enabledMechanisms")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                parseEnabledMechanisms(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } else if (word.equals("disabledMechanisms")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                parseDisabledMechanisms(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            } else if (word.equals("attributes")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                parseAttributes(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            } else if (word.equals("handleStartupErrors")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                parseHandleStartupErrors(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            } else if (word.endsWith("insertionCheckInterval")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                insertionCheckInterval = parseIntegerEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                if (insertionCheckInterval < 100) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    throw excLine(word + " must be at least 100 ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            } else if (word.equals("showInfo")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                showInfo = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            } else if (word.equals("keyStoreCompatibilityMode")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                keyStoreCompatibilityMode = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            } else if (word.equals("explicitCancel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                explicitCancel = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            } else if (word.equals("omitInitialize")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                omitInitialize = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            } else if (word.equals("allowSingleThreadedModules")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                allowSingleThreadedModules = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            } else if (word.equals("functionList")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                functionList = parseStringEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            } else if (word.equals("nssUseSecmod")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                nssUseSecmod = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            } else if (word.equals("nssLibraryDirectory")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                nssLibraryDirectory = parseLibrary(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                nssUseSecmod = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            } else if (word.equals("nssSecmodDirectory")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                nssSecmodDirectory = expand(parseStringEntry(word));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                nssUseSecmod = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            } else if (word.equals("nssModule")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                nssModule = parseStringEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                nssUseSecmod = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            } else if (word.equals("nssDbMode")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                String mode = parseStringEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                if (mode.equals("readWrite")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    nssDbMode = Secmod.DbMode.READ_WRITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                } else if (mode.equals("readOnly")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    nssDbMode = Secmod.DbMode.READ_ONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                } else if (mode.equals("noDb")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    nssDbMode = Secmod.DbMode.NO_DB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    throw excToken("nssDbMode must be one of readWrite, readOnly, and noDb:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                nssUseSecmod = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            } else if (word.equals("nssNetscapeDbWorkaround")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                nssNetscapeDbWorkaround = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                nssUseSecmod = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            } else if (word.equals("nssArgs")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                parseNSSArgs(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            } else if (word.equals("nssUseSecmodTrust")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                nssUseSecmodTrust = parseBooleanEntry(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                throw new ConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        ("Unknown keyword '" + word + "', line " + st.lineno());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            parsedKeywords.add(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        reader.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        reader = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        st = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        parsedKeywords = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            throw new ConfigurationException("name must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (nssUseSecmod == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (library == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                throw new ConfigurationException("library must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if (library != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                throw new ConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    ("library must not be specified in NSS mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if ((slotID != -1) || (slotListIndex != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                throw new ConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    ("slot and slotListIndex must not be specified in NSS mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (nssArgs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                throw new ConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    ("nssArgs must not be specified in NSS mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (nssUseSecmodTrust != false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                throw new ConfigurationException("nssUseSecmodTrust is an "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    + "internal option and must not be specified in NSS mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    // Parsing helper methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    private int nextToken() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        int token = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        debug(st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    private void parseEquals() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (token != '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            throw excToken("Expected '=', read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    private void parseOpenBraces() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (token == TT_EOL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            if ((token == TT_WORD) && st.sval.equals("{")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            throw excToken("Expected '{', read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    private boolean isCloseBraces(int token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return (token == TT_WORD) && st.sval.equals("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    private String parseWord() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (token != TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            throw excToken("Unexpected value:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    private String parseStringEntry(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (token != TT_WORD && token != '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            // not a word token nor a string enclosed by double quotes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            throw excToken("Unexpected value:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        String value = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        debug(keyword + ": " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    private boolean parseBooleanEntry(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        boolean value = parseBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        debug(keyword + ": " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    private int parseIntegerEntry(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        int value = decodeNumber(parseWord());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        debug(keyword + ": " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    private boolean parseBoolean() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        String val = parseWord();
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   555
        switch (val) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   556
            case "true":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   557
                return true;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   558
            case "false":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   559
                return false;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   560
            default:
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   561
                throw excToken("Expected boolean value, read:");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    private String parseLine() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        String s = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if ((token == TT_EOL) || (token == TT_EOF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            if (token != TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                throw excToken("Unexpected value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            s = s + " " + st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    private int decodeNumber(String str) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (str.startsWith("0x") || str.startsWith("0X")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                return Integer.parseInt(str.substring(2), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                return Integer.parseInt(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            throw excToken("Expected number, read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    private static boolean isNumber(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        if (s.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        char ch = s.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return ((ch >= '0') && (ch <= '9'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    private void parseComma() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (token != ',') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            throw excToken("Expected ',', read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    private static boolean isByteArray(String val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return val.startsWith("0h");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private byte[] decodeByteArray(String str) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (str.startsWith("0h") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            throw excToken("Expected byte array value, read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        str = str.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        // XXX proper hex parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return new BigInteger(str, 16).toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            throw excToken("Expected byte array value, read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    private void checkDup(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (parsedKeywords.contains(keyword)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            throw excLine(keyword + " must only be specified once");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    // individual entry parsing methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    private String parseLibrary(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        String lib = parseLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        lib = expand(lib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        int i = lib.indexOf("/$ISA/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (i != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            // replace "/$ISA/" with "/sparcv9/" on 64-bit Solaris SPARC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            // and with "/amd64/" on Solaris AMD64.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            // On all other platforms, just turn it into a "/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            String osName = System.getProperty("os.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            String osArch = System.getProperty("os.arch", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            String prefix = lib.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            String suffix = lib.substring(i + 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            if (osName.equals("SunOS") && osArch.equals("sparcv9")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                lib = prefix + "/sparcv9" + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            } else if (osName.equals("SunOS") && osArch.equals("amd64")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                lib = prefix + "/amd64" + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                lib = prefix + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        debug(keyword + ": " + lib);
9849
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   657
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   658
        // Check to see if full path is specified to prevent the DLL
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   659
        // preloading attack
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   660
        if (!(new File(lib)).isAbsolute()) {
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   661
            throw new ConfigurationException(
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   662
                "Absolute path required for library value: " + lib);
eb437e9fba66 7003952: SEC: securely load DLLs and launch executables using fully qualified path
valeriep
parents: 9275
diff changeset
   663
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return lib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    private void parseDescription(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        description = parseLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        debug("description: " + description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    private void parseSlotID(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (slotID >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            throw excLine("Duplicate slot definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        if (slotListIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            throw excLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                ("Only one of slot and slotListIndex must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        String slotString = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        slotID = decodeNumber(slotString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        debug("slot: " + slotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    private void parseSlotListIndex(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        if (slotListIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            throw excLine("Duplicate slotListIndex definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (slotID >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            throw excLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                ("Only one of slot and slotListIndex must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        String slotString = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        slotListIndex = decodeNumber(slotString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        debug("slotListIndex: " + slotListIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    private void parseEnabledMechanisms(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        enabledMechanisms = parseMechanisms(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    private void parseDisabledMechanisms(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        disabledMechanisms = parseMechanisms(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    private Set<Long> parseMechanisms(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        Set<Long> mechs = new HashSet<Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        parseOpenBraces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (isCloseBraces(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            if (token == TT_EOL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (token != TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                throw excToken("Expected mechanism, read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            long mech = parseMechanism(st.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            mechs.add(Long.valueOf(mech));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            System.out.print("mechanisms: [");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            for (Long mech : mechs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                System.out.print(Functions.getMechanismName(mech));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                System.out.print(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            System.out.println("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        return mechs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    private long parseMechanism(String mech) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (isNumber(mech)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            return decodeNumber(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                return Functions.getMechanismId(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                throw excLine("Unknown mechanism: " + mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    private void parseAttributes(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        if (templateManager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            templateManager = new TemplateManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        if (token == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            String s = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            if (s.equals("compatibility") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                throw excLine("Expected 'compatibility', read " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            setCompatibilityAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        if (token != '(') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            throw excToken("Expected '(' or '=', read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        String op = parseOperation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        parseComma();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        long objectClass = parseObjectClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        parseComma();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        long keyAlg = parseKeyAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (token != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            throw excToken("Expected ')', read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        parseOpenBraces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        List<CK_ATTRIBUTE> attributes = new ArrayList<CK_ATTRIBUTE>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            if (isCloseBraces(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if (token == TT_EOL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            if (token != TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                throw excToken("Expected mechanism, read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            String attributeName = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            long attributeId = decodeAttributeName(attributeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            String attributeValue = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            attributes.add(decodeAttributeValue(attributeId, attributeValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        templateManager.addTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                (op, objectClass, keyAlg, attributes.toArray(CK_A0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    private void setCompatibilityAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        // all secret keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        templateManager.addTemplate(O_ANY, CKO_SECRET_KEY, PCKK_ANY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            TOKEN_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            SENSITIVE_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            EXTRACTABLE_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            ENCRYPT_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            DECRYPT_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            WRAP_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            UNWRAP_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        // generic secret keys are special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        // They are used as MAC keys plus for the SSL/TLS (pre)master secrets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        templateManager.addTemplate(O_ANY, CKO_SECRET_KEY, CKK_GENERIC_SECRET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            SIGN_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            VERIFY_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            ENCRYPT_NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            DECRYPT_NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            WRAP_NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            UNWRAP_NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            DERIVE_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        // all private and public keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        templateManager.addTemplate(O_ANY, CKO_PRIVATE_KEY, PCKK_ANY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            TOKEN_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            SENSITIVE_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            EXTRACTABLE_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        templateManager.addTemplate(O_ANY, CKO_PUBLIC_KEY, PCKK_ANY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            TOKEN_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        // additional attributes for RSA private keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        templateManager.addTemplate(O_ANY, CKO_PRIVATE_KEY, CKK_RSA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            DECRYPT_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            SIGN_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            SIGN_RECOVER_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            UNWRAP_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        // additional attributes for RSA public keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        templateManager.addTemplate(O_ANY, CKO_PUBLIC_KEY, CKK_RSA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            ENCRYPT_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            VERIFY_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            VERIFY_RECOVER_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            WRAP_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        // additional attributes for DSA private keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        templateManager.addTemplate(O_ANY, CKO_PRIVATE_KEY, CKK_DSA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            SIGN_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        // additional attributes for DSA public keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        templateManager.addTemplate(O_ANY, CKO_PUBLIC_KEY, CKK_DSA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            VERIFY_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        // additional attributes for DH private keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        templateManager.addTemplate(O_ANY, CKO_PRIVATE_KEY, CKK_DH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            DERIVE_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        // additional attributes for EC private keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        templateManager.addTemplate(O_ANY, CKO_PRIVATE_KEY, CKK_EC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            SIGN_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            DERIVE_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        // additional attributes for EC public keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        templateManager.addTemplate(O_ANY, CKO_PUBLIC_KEY, CKK_EC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            VERIFY_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    private final static CK_ATTRIBUTE[] CK_A0 = new CK_ATTRIBUTE[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    private String parseOperation() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        String op = parseWord();
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   890
        switch (op) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   891
            case "*":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   892
                return TemplateManager.O_ANY;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   893
            case "generate":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   894
                return TemplateManager.O_GENERATE;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   895
            case "import":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   896
                return TemplateManager.O_IMPORT;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   897
            default:
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   898
                throw excLine("Unknown operation " + op);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    private long parseObjectClass() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        String name = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            return Functions.getObjectClassId(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            throw excLine("Unknown object class " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    private long parseKeyAlgorithm() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        String name = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (isNumber(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            return decodeNumber(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                return Functions.getKeyId(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                throw excLine("Unknown key algorithm " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    private long decodeAttributeName(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        if (isNumber(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            return decodeNumber(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                return Functions.getAttributeId(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                throw excLine("Unknown attribute name " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    private CK_ATTRIBUTE decodeAttributeValue(long id, String value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        if (value.equals("null")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            return new CK_ATTRIBUTE(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        } else if (value.equals("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            return new CK_ATTRIBUTE(id, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        } else if (value.equals("false")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            return new CK_ATTRIBUTE(id, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        } else if (isByteArray(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            return new CK_ATTRIBUTE(id, decodeByteArray(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        } else if (isNumber(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            return new CK_ATTRIBUTE(id, Integer.valueOf(decodeNumber(value)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            throw excLine("Unknown attribute value " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    private void parseNSSArgs(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        int token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        if (token != '"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            throw excToken("Expected quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        nssArgs = expand(st.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        debug("nssArgs: " + nssArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    private void parseHandleStartupErrors(String keyword) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        checkDup(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        parseEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        String val = parseWord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        if (val.equals("ignoreAll")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            handleStartupErrors = ERR_IGNORE_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } else if (val.equals("ignoreMissingLibrary")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            handleStartupErrors = ERR_IGNORE_LIB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        } else if (val.equals("halt")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            handleStartupErrors = ERR_HALT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            throw excToken("Invalid value for handleStartupErrors:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        debug("handleStartupErrors: " + handleStartupErrors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
class ConfigurationException extends IOException {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9849
diff changeset
   983
    private static final long serialVersionUID = 254492758807673194L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    ConfigurationException(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        super(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
}