/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * The following code handles the storage of PKCS 11 modules used by the * NSS. This file is written to abstract away how the modules are * stored so we can deside that later.
*/
if (count) { for (i = 0; i < count; i++) {
LGDB_PUTLONG(slot[i].slotID, slotInfo[i].slotID);
LGDB_PUTLONG(slot[i].defaultFlags,
slotInfo[i].defaultFlags);
LGDB_PUTLONG(slot[i].timeout, slotInfo[i].timeout);
slot[i].askpw = slotInfo[i].askpw;
slot[i].hasRootCerts = slotInfo[i].hasRootCerts;
PORT_Memset(slot[i].reserved, 0, sizeof(slot[i].reserved));
}
}
rv = SECSuccess;
loser: if (commonName)
PORT_Free(commonName); if (dllName)
PORT_Free(dllName); if (param)
PORT_Free(param); if (slotInfo)
PORT_Free(slotInfo); if (nss)
PORT_Free(nss); return rv;
}
staticvoid
lgdb_FreeData(DBT *data)
{ if (data->data) {
PORT_Free(data->data);
}
}
staticvoid
lgdb_FreeSlotStrings(char **slotStrings, int count)
{ int i;
for (i = 0; i < count; i++) { if (slotStrings[i]) {
PR_smprintf_free(slotStrings[i]);
slotStrings[i] = NULL;
}
}
}
/* * build a module from the data base entry.
*/ staticchar *
lgdb_DecodeData(char *defParams, DBT *data, PRBool *retInternal)
{
lgdbData *encoded;
lgdbSlotData *slots;
PLArenaPool *arena; char *commonName = NULL; char *dllName = NULL; char *parameters = NULL; char *nss; char *moduleSpec; char **slotStrings = NULL; unsignedchar *names; unsignedlong slotCount; unsignedlong ssl0 = 0; unsignedlong ssl1 = 0; unsignedlong slotID; unsignedlong defaultFlags; unsignedlong timeout; unsignedlong trustOrder = NSSUTIL_DEFAULT_TRUST_ORDER; unsignedlong cipherOrder = NSSUTIL_DEFAULT_CIPHER_ORDER; unsignedshort len; unsignedshort namesOffset = 0; /* start of the names block */ unsignedlong namesRunningOffset; /* offset to name we are
* currently processing */ unsignedshort slotOffset;
PRBool isOldVersion = PR_FALSE;
PRBool internal;
PRBool isFIPS;
PRBool isModuleDB = PR_FALSE;
PRBool isModuleDBOnly = PR_FALSE;
PRBool extended = PR_FALSE; int i;
arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); if (arena == NULL) return NULL;
#define CHECK_SIZE(x) \ if ((unsignedint)data->size < (unsignedint)(x)) \ goto db_loser
/* ------------------------------------------------------------- ** Process the buffer header, which is the lgdbData struct. ** It may be an old or new version. Check the length for each.
*/
/*-------------------------------------------------------------- ** Now process the variable length set of names. ** The names have this structure: ** struct { ** BYTE commonNameLen[ 2 ]; ** BYTE commonName [ commonNameLen ]; ** BTTE libNameLen [ 2 ]; ** BYTE libName [ libNameLen ]; ** If it is "extended" it also has these members: ** BYTE initStringLen[ 2 ]; ** BYTE initString [ initStringLen ]; ** }
*/
namesRunningOffset = namesOffset; /* copy the module's common name */
CHECK_SIZE(namesRunningOffset + 2);
names = (unsignedchar *)data->data;
len = LGDB_GETSHORT(names + namesRunningOffset);
/* copy the module's shared library file name. */
CHECK_SIZE(namesRunningOffset + 2);
len = LGDB_GETSHORT(names + namesRunningOffset); if (len) {
CHECK_SIZE(namesRunningOffset + 2 + len);
dllName = (char *)PORT_ArenaAlloc(arena, len + 1); if (dllName == NULL) goto loser;
PORT_Memcpy(dllName, names + namesRunningOffset + 2, len);
dllName[len] = 0;
}
namesRunningOffset += len + 2;
/* copy the module's initialization string, if present. */ if (!internal && extended) {
CHECK_SIZE(namesRunningOffset + 2);
len = LGDB_GETSHORT(names + namesRunningOffset); if (len) {
CHECK_SIZE(namesRunningOffset + 2 + len);
parameters = (char *)PORT_ArenaAlloc(arena, len + 1); if (parameters == NULL) goto loser;
PORT_Memcpy(parameters, names + namesRunningOffset + 2, len);
parameters[len] = 0;
}
namesRunningOffset += len + 2;
}
/* * Consistency check: Make sure the slot and names blocks don't * overlap. These blocks can occur in any order, so this check is made * in 2 parts. First we check the case where the slot block starts * after the name block. Later, when we have the slot block length, * we check the case where slot block starts before the name block. * NOTE: in most cases any overlap will likely be detected by invalid * data read from the blocks, but it's better to find out sooner * than later.
*/ if (slotOffset >= namesOffset) { /* slot block starts after name block */ if (slotOffset < namesRunningOffset) { goto db_loser;
}
}
/* ------------------------------------------------------------------ ** Part 3, process the slot table. ** This part has this structure: ** struct { ** BYTE slotCount [ 2 ]; ** lgdbSlotData [ slotCount ]; ** {
*/
/* * Consistency check: Part 2. We now have the slot block length, we can * check the case where the slotblock procedes the name block.
*/ if (slotOffset < namesOffset) { /* slot block starts before name block */ if (namesOffset < slotOffset + 2 + slotCount * sizeof(lgdbSlotData)) { goto db_loser;
}
}
nss = NSSUTIL_MkNSSString(slotStrings, slotCount, internal, isFIPS,
isModuleDB, isModuleDBOnly, internal, trustOrder,
cipherOrder, ssl0, ssl1);
lgdb_FreeSlotStrings(slotStrings, slotCount); /* it's permissible (and normal) for nss to be NULL. it simply means
* there are no NSS specific parameters in the database */
moduleSpec = NSSUTIL_MkModuleSpec(dllName, commonName, parameters, nss);
PR_smprintf_free(nss);
PORT_FreeArena(arena, PR_TRUE); return moduleSpec;
/* * Delete a module from the Data Base
*/
SECStatus
legacy_DeleteSecmodDB(constchar *appName, constchar *filename, constchar *dbname, char *args, PRBool rw)
{
DBT key;
SECStatus rv = SECFailure;
DB *pkcs11db = NULL; int ret;
if (!rw) return SECFailure;
/* make sure we have a db handle */
pkcs11db = lgdb_OpenDB(appName, filename, dbname, PR_FALSE, PR_FALSE); if (pkcs11db == NULL) { return SECFailure;
}
rv = lgdb_MakeKey(&key, args); if (rv != SECSuccess) goto done;
rv = SECFailure;
ret = (*pkcs11db->del)(pkcs11db, &key, 0);
lgdb_FreeKey(&key); if (ret != 0) goto done;
ret = (*pkcs11db->sync)(pkcs11db, 0); if (ret == 0)
rv = SECSuccess;
done:
lgdb_CloseDB(pkcs11db); return rv;
}
/* * Add a module to the Data base
*/
SECStatus
legacy_AddSecmodDB(constchar *appName, constchar *filename, constchar *dbname, char *module, PRBool rw)
{
DBT key, data;
SECStatus rv = SECFailure;
DB *pkcs11db = NULL; int ret;
if (!rw) return SECFailure;
/* make sure we have a db handle */
pkcs11db = lgdb_OpenDB(appName, filename, dbname, PR_FALSE, PR_FALSE); if (pkcs11db == NULL) { return SECFailure;
}
rv = lgdb_MakeKey(&key, module); if (rv != SECSuccess) goto done;
rv = lgdb_EncodeData(&data, module); if (rv != SECSuccess) {
lgdb_FreeKey(&key); goto done;
}
rv = SECFailure;
ret = (*pkcs11db->put)(pkcs11db, &key, &data, 0);
lgdb_FreeKey(&key);
lgdb_FreeData(&data); if (ret != 0) goto done;
ret = (*pkcs11db->sync)(pkcs11db, 0); if (ret == 0)
rv = SECSuccess;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.