/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Configuration container and file parsing.
*
* @author Andreas Sterbenz
* @since 1.5
*/
final class Config {
// same as allowSingleThreadedModules but controlled via a system property
// and applied to all providers. if set to false, no SunPKCS11 instances
// will accept single threaded modules regardless of the setting in their
// config files.
private static final boolean staticAllowSingleThreadedModules;
static {
String p = "sun.security.pkcs11.allowSingleThreadedModules";
if ("false".equalsIgnoreCase(s)) {
staticAllowSingleThreadedModules = false;
} else {
staticAllowSingleThreadedModules = true;
}
}
// temporary storage for configurations
// needed because the SunPKCS11 needs to call the superclass constructor
// in provider before accessing any instance variables
return config;
}
try {
return config;
} catch (Exception e) {
throw new ProviderException("Error parsing configuration", e);
}
}
}
private final static boolean DEBUG = false;
if (DEBUG) {
}
}
// Reader and StringTokenizer used during parsing
// name suffix of the provider
// name of the PKCS#11 library
// description to pass to the provider class
// slotID of the slot to use
// slot to use, specified as index in the slotlist
// set of enabled mechanisms (or null to use default)
// set of disabled mechanisms
// whether to print debug info during startup
private boolean showInfo = false;
// template manager, initialized from parsed attributes
// how to handle error during startup, one of ERR_
// flag indicating whether the P11KeyStore should
// be more tolerant of input parameters
private boolean keyStoreCompatibilityMode = true;
// flag indicating whether we need to explicitly cancel operations
// see Token
private boolean explicitCancel = true;
// how often to test for token insertion, if no token is present
// flag inidicating whether to omit the call to C_Initialize()
// should be used only if we are running within a process that
private boolean omitInitialize = false;
// whether to allow modules that only support single threaded access.
// they cannot be used safely from multiple PKCS#11 consumers in the
// same process, for example NSS and SunPKCS11
private boolean allowSingleThreadedModules = true;
// name of the C function that returns the PKCS#11 functionlist
// This option primarily exists for the deprecated
// Secmod.Module.getProvider() method.
// whether to use NSS secmod mode. Implicitly set if nssLibraryDirectory,
// nssSecmodDirectory, or nssModule is specified.
private boolean nssUseSecmod;
// location of the NSS library files (libnss3.so, etc.)
// location of secmod.db
// which NSS module to use
// Whether the P11KeyStore should specify the CKA_NETSCAPE_DB attribute
// when creating private keys. Only valid if nssUseSecmod is true.
private boolean nssNetscapeDbWorkaround = true;
// Special init argument string for the NSS softtoken.
// This is used when using the NSS softtoken directly without secmod mode.
// whether to use NSS trust attributes for the KeyStore of this provider
// this option is for internal use by the SunPKCS11 code only and
// works only for NSS providers created via the Secmod API
private boolean nssUseSecmodTrust = false;
// Flag to indicate whether the X9.63 encoding for EC points shall be used
// (true) or whether that encoding shall be wrapped in an ASN.1 OctetString
// (false).
private boolean useEcX963Encoding = false;
// inline config
} else {
}
}
}
parse();
}
return name;
}
return library;
}
if (description != null) {
return description;
}
}
int getSlotID() {
return slotID;
}
int getSlotListIndex() {
// if neither is set, default to first slot
return 0;
} else {
return slotListIndex;
}
}
boolean getShowInfo() {
}
if (templateManager == null) {
templateManager = new TemplateManager();
}
return templateManager;
}
boolean isEnabled(long m) {
if (enabledMechanisms != null) {
}
if (disabledMechanisms != null) {
}
return true;
}
int getHandleStartupErrors() {
return handleStartupErrors;
}
boolean getKeyStoreCompatibilityMode() {
return keyStoreCompatibilityMode;
}
boolean getExplicitCancel() {
return explicitCancel;
}
int getInsertionCheckInterval() {
return insertionCheckInterval;
}
boolean getOmitInitialize() {
return omitInitialize;
}
boolean getAllowSingleThreadedModules() {
}
return functionList;
}
boolean getNssUseSecmod() {
return nssUseSecmod;
}
return nssLibraryDirectory;
}
return nssSecmodDirectory;
}
return nssModule;
}
return nssDbMode;
}
public boolean getNssNetscapeDbWorkaround() {
return nssUseSecmod && nssNetscapeDbWorkaround;
}
return nssArgs;
}
boolean getNssUseSecmodTrust() {
return nssUseSecmodTrust;
}
boolean getUseEcX963Encoding() {
return useEcX963Encoding;
}
try {
return PropertyExpander.expand(s);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
private void setupTokenizer() {
st.resetSyntax();
// XXX check ASCII table and add all other characters except special
// special: #="(),
st.eolIsSignificant(true);
}
}
}
while (true) {
break;
}
continue;
}
throw excToken("Unexpected token:");
}
if (insertionCheckInterval < 100) {
}
nssUseSecmod = true;
nssUseSecmod = true;
nssUseSecmod = true;
} else {
throw excToken("nssDbMode must be one of readWrite, readOnly, and noDb:");
}
nssUseSecmod = true;
nssUseSecmod = true;
} else {
throw new ConfigurationException
}
}
throw new ConfigurationException("name must be specified");
}
if (nssUseSecmod == false) {
throw new ConfigurationException("library must be specified");
}
} else {
throw new ConfigurationException
("library must not be specified in NSS mode");
}
throw new ConfigurationException
("slot and slotListIndex must not be specified in NSS mode");
}
throw new ConfigurationException
("nssArgs must not be specified in NSS mode");
}
if (nssUseSecmodTrust != false) {
throw new ConfigurationException("nssUseSecmodTrust is an "
+ "internal option and must not be specified in NSS mode");
}
}
}
//
// Parsing helper methods
//
return token;
}
if (token != '=') {
throw excToken("Expected '=', read");
}
}
while (true) {
continue;
}
return;
}
throw excToken("Expected '{', read");
}
}
}
throw excToken("Unexpected value:");
}
}
parseEquals();
// not a word token nor a string enclosed by double quotes
throw excToken("Unexpected value:");
}
return value;
}
parseEquals();
boolean value = parseBoolean();
return value;
}
parseEquals();
return value;
}
return true;
return false;
} else {
throw excToken("Expected boolean value, read:");
}
}
while (true) {
break;
}
throw excToken("Unexpected value");
}
}
return s;
}
try {
} else {
}
} catch (NumberFormatException e) {
throw excToken("Expected number, read");
}
}
if (s.length() == 0) {
return false;
}
}
if (token != ',') {
throw excToken("Expected ',', read");
}
}
}
throw excToken("Expected byte array value, read");
}
// XXX proper hex parsing
try {
} catch (NumberFormatException e) {
throw excToken("Expected byte array value, read");
}
}
}
}
//
// individual entry parsing methods
//
parseEquals();
if (i != -1) {
// replace "/$ISA/" with "/sparcv9/" on 64-bit Solaris SPARC
// and with "/amd64/" on Solaris AMD64.
// On all other platforms, just turn it into a "/"
} else {
}
}
// Check to see if full path is specified to prevent the DLL
// preloading attack
throw new ConfigurationException(
"Absolute path required for library value: " + lib);
}
return lib;
}
parseEquals();
description = parseLine();
}
if (slotID >= 0) {
throw excLine("Duplicate slot definition");
}
if (slotListIndex >= 0) {
throw excLine
("Only one of slot and slotListIndex must be specified");
}
parseEquals();
}
if (slotListIndex >= 0) {
throw excLine("Duplicate slotListIndex definition");
}
if (slotID >= 0) {
throw excLine
("Only one of slot and slotListIndex must be specified");
}
parseEquals();
}
}
}
parseEquals();
while (true) {
if (isCloseBraces(token)) {
break;
}
continue;
}
throw excToken("Expected mechanism, read");
}
}
if (DEBUG) {
}
}
return mechs;
}
return decodeNumber(mech);
} else {
try {
} catch (IllegalArgumentException e) {
}
}
}
if (templateManager == null) {
templateManager = new TemplateManager();
}
if (token == '=') {
if (s.equals("compatibility") == false) {
throw excLine("Expected 'compatibility', read " + s);
}
return;
}
if (token != '(') {
throw excToken("Expected '(' or '=', read");
}
parseComma();
long objectClass = parseObjectClass();
parseComma();
long keyAlg = parseKeyAlgorithm();
if (token != ')') {
throw excToken("Expected ')', read");
}
parseEquals();
while (true) {
if (isCloseBraces(token)) {
break;
}
continue;
}
throw excToken("Expected mechanism, read");
}
parseEquals();
}
}
private void setCompatibilityAttributes() {
// all secret keys
new CK_ATTRIBUTE[] {
});
// generic secret keys are special
new CK_ATTRIBUTE[] {
});
// all private and public keys
new CK_ATTRIBUTE[] {
});
new CK_ATTRIBUTE[] {
});
// additional attributes for RSA private keys
new CK_ATTRIBUTE[] {
});
// additional attributes for RSA public keys
new CK_ATTRIBUTE[] {
});
// additional attributes for DSA private keys
new CK_ATTRIBUTE[] {
});
// additional attributes for DSA public keys
new CK_ATTRIBUTE[] {
});
// additional attributes for DH private keys
new CK_ATTRIBUTE[] {
});
// additional attributes for EC private keys
new CK_ATTRIBUTE[] {
});
// additional attributes for EC public keys
new CK_ATTRIBUTE[] {
});
}
return TemplateManager.O_ANY;
return TemplateManager.O_GENERATE;
return TemplateManager.O_IMPORT;
} else {
}
}
try {
} catch (IllegalArgumentException e) {
}
}
return decodeNumber(name);
} else {
try {
} catch (IllegalArgumentException e) {
}
}
}
return decodeNumber(name);
} else {
try {
} catch (IllegalArgumentException e) {
}
}
}
throws IOException {
return new CK_ATTRIBUTE(id);
return new CK_ATTRIBUTE(id, true);
return new CK_ATTRIBUTE(id, false);
} else if (isByteArray(value)) {
} else {
}
}
parseEquals();
if (token != '"') {
throw excToken("Expected quoted string");
}
}
parseEquals();
} else {
throw excToken("Invalid value for handleStartupErrors:");
}
}
}
super(msg);
}
}