Navigation Menu

Skip to content

Commit

Permalink
Bug 1585189 - Changed the algorithm used to encrypt NSS database entr…
Browse files Browse the repository at this point in the history
…ies, from 3DES to AES256.

Our NSS DB uses 3DES internally to encrypt their entries.
This patch changes the default algorithm for AES256 to increase the security.
This patch also adds code to use AES Wrap in the future. It also adds an integrity
check to the AES256 CBC. The change only affects sqlite databases.

bob

Differential Revision: https://phabricator.services.mozilla.com/D54589
  • Loading branch information
rjrelyea committed Nov 25, 2019
1 parent f699f5c commit 4703a81
Show file tree
Hide file tree
Showing 17 changed files with 796 additions and 205 deletions.
6 changes: 6 additions & 0 deletions lib/softoken/legacydb/keydb.c
Expand Up @@ -2251,6 +2251,12 @@ lg_PutMetaData(SDB *sdb, const char *id,
return CKR_OK;
}

CK_RV
lg_DestroyMetaData(SDB *db, const char *id)
{
return CKR_GENERAL_ERROR; /* no extra data stored */
}

CK_RV
lg_Reset(SDB *sdb)
{
Expand Down
16 changes: 16 additions & 0 deletions lib/softoken/legacydb/lgcreate.c
Expand Up @@ -960,6 +960,22 @@ lg_createKeyObject(SDB *sdb, CK_OBJECT_CLASS objclass,
return CKR_ATTRIBUTE_VALUE_INVALID;
}

/*
* return the 'next' key handle
*/
CK_RV
lg_GetNewObjectID(SDB *sdb, CK_OBJECT_HANDLE *handle)
{
/* the upper level needs the Object ID early to populate any
* signature attributes. The legacy can't really return a new
* handle without the full object template (chicken and egg issue).
* Fortunately we can just return a bogus handle because the legacy
* database doesn't support meta data and can't store any of the signed
* attributes anyway */
*handle = CK_INVALID_HANDLE;
return CKR_OK;
}

/*
* Parse the template and create an object stored in the DB that reflects.
* the object specified in the database.
Expand Down
2 changes: 2 additions & 0 deletions lib/softoken/legacydb/lgdb.h
Expand Up @@ -150,6 +150,8 @@ CK_RV lg_Abort(SDB *sdb);
CK_RV lg_GetMetaData(SDB *sdb, const char *id, SECItem *item1, SECItem *item2);
CK_RV lg_PutMetaData(SDB *sdb, const char *id,
const SECItem *item1, const SECItem *item2);
CK_RV lg_DestroyMetaData(SDB *sdb, const char *id);
CK_RV lg_GetNewObjectID(SDB *sdb, CK_OBJECT_HANDLE *object_id);

SEC_END_PROTOS

Expand Down
4 changes: 3 additions & 1 deletion lib/softoken/legacydb/lginit.c
Expand Up @@ -519,7 +519,7 @@ lg_init(SDB **pSdb, int flags, NSSLOWCERTCertDBHandle *certdbPtr,
}

sdb->private = lgdb_p;
sdb->version = 0;
sdb->version = 1;
sdb->sdb_flags = flags;
sdb->app_private = NULL;
sdb->sdb_FindObjectsInit = lg_FindObjectsInit;
Expand All @@ -531,12 +531,14 @@ lg_init(SDB **pSdb, int flags, NSSLOWCERTCertDBHandle *certdbPtr,
sdb->sdb_DestroyObject = lg_DestroyObject;
sdb->sdb_GetMetaData = lg_GetMetaData;
sdb->sdb_PutMetaData = lg_PutMetaData;
sdb->sdb_DestroyMetaData = lg_DestroyMetaData;
sdb->sdb_Begin = lg_Begin;
sdb->sdb_Commit = lg_Commit;
sdb->sdb_Abort = lg_Abort;
sdb->sdb_Reset = lg_Reset;
sdb->sdb_Close = lg_Close;
sdb->sdb_SetForkState = lg_SetForkState;
sdb->sdb_GetNewObjectID = lg_GetNewObjectID;

*pSdb = sdb;
return CKR_OK;
Expand Down
9 changes: 6 additions & 3 deletions lib/softoken/lgglue.c
Expand Up @@ -205,7 +205,8 @@ sftkdb_encrypt_stub(PLArenaPool *arena, SDB *sdb, SECItem *plainText,
iterationCount = 1;
}

rv = sftkdb_EncryptAttribute(arena, key, iterationCount,
rv = sftkdb_EncryptAttribute(arena, handle, sdb, key, iterationCount,
CK_INVALID_HANDLE, CKT_INVALID_TYPE,
plainText, cipherText);
PZ_Unlock(handle->passwordLock);

Expand All @@ -227,7 +228,7 @@ sftkdb_decrypt_stub(SDB *sdb, SECItem *cipherText, SECItem **plainText)
return SECFailure;
}

/* if we aren't th handle, try the other handle */
/* if we aren't the key handle, try the other handle */
oldKey = handle->oldKey;
if (handle->type != SFTK_KEYDB_TYPE) {
handle = handle->peerDB;
Expand All @@ -244,7 +245,9 @@ sftkdb_decrypt_stub(SDB *sdb, SECItem *cipherText, SECItem **plainText)
/* PORT_SetError */
return SECFailure;
}
rv = sftkdb_DecryptAttribute(oldKey ? oldKey : &handle->passwordKey,
rv = sftkdb_DecryptAttribute(NULL, oldKey ? oldKey : &handle->passwordKey,
CK_INVALID_HANDLE,
CKT_INVALID_TYPE,
cipherText, plainText);
PZ_Unlock(handle->passwordLock);

Expand Down

0 comments on commit 4703a81

Please sign in to comment.