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