2021-07-01 22:12:42 +00:00
|
|
|
diff -up ./lib/softoken/sftkpwd.c.orig ./lib/softoken/sftkpwd.c
|
|
|
|
--- ./lib/softoken/sftkpwd.c.orig 2021-06-10 05:33:12.000000000 -0700
|
|
|
|
+++ ./lib/softoken/sftkpwd.c 2021-07-01 14:04:34.068596942 -0700
|
|
|
|
@@ -287,9 +287,12 @@ sftkdb_DecryptAttribute(SFTKDBHandle *ha
|
2021-06-21 17:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are using aes 256, we need to check authentication as well.*/
|
|
|
|
- if ((type != CKT_INVALID_TYPE) && (cipherValue.alg == SEC_OID_AES_256_CBC)) {
|
|
|
|
+ if ((type != CKT_INVALID_TYPE) &&
|
|
|
|
+ (cipherValue.alg == SEC_OID_PKCS5_PBES2) &&
|
|
|
|
+ (cipherValue.param->encAlg == SEC_OID_AES_256_CBC)) {
|
|
|
|
SECItem signature;
|
|
|
|
unsigned char signData[SDB_MAX_META_DATA_LEN];
|
2021-07-01 22:12:42 +00:00
|
|
|
+ CK_RV crv;
|
2021-06-21 17:17:18 +00:00
|
|
|
|
|
|
|
/* if we get here from the old legacy db, there is clearly an
|
|
|
|
* error, don't return the plaintext */
|
2021-07-01 22:12:42 +00:00
|
|
|
@@ -301,15 +304,28 @@ sftkdb_DecryptAttribute(SFTKDBHandle *ha
|
|
|
|
|
|
|
|
signature.data = signData;
|
|
|
|
signature.len = sizeof(signData);
|
|
|
|
- rv = sftkdb_GetAttributeSignature(handle, handle, id, type,
|
|
|
|
+ rv = SECFailure;
|
|
|
|
+ /* sign sftkdb_GetAttriibuteSignature returns a crv, not an rv */
|
|
|
|
+ crv = sftkdb_GetAttributeSignature(handle, handle, id, type,
|
2021-06-21 17:17:18 +00:00
|
|
|
&signature);
|
2021-07-01 22:12:42 +00:00
|
|
|
- if (rv != SECSuccess) {
|
|
|
|
- goto loser;
|
|
|
|
+ if (crv == CKR_OK) {
|
|
|
|
+ rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE,
|
|
|
|
+ type, *plain, &signature);
|
2021-06-21 17:17:18 +00:00
|
|
|
}
|
2021-07-01 22:12:42 +00:00
|
|
|
- rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE, type,
|
|
|
|
- *plain, &signature);
|
2021-06-21 17:17:18 +00:00
|
|
|
if (rv != SECSuccess) {
|
|
|
|
- goto loser;
|
|
|
|
+ /* handle a bug where old versions of NSS misfiled the signature
|
|
|
|
+ * attribute on password update */
|
|
|
|
+ id |= SFTK_KEYDB_TYPE|SFTK_TOKEN_TYPE;
|
|
|
|
+ signature.len = sizeof(signData);
|
2021-07-01 22:12:42 +00:00
|
|
|
+ crv = sftkdb_GetAttributeSignature(handle, handle, id, type,
|
2021-06-21 17:17:18 +00:00
|
|
|
+ &signature);
|
2021-07-01 22:12:42 +00:00
|
|
|
+ if (crv != CKR_OK) {
|
|
|
|
+ rv = SECFailure;
|
|
|
|
+ PORT_SetError(SEC_ERROR_BAD_SIGNATURE);
|
2021-06-21 17:17:18 +00:00
|
|
|
+ goto loser;
|
|
|
|
+ }
|
|
|
|
+ rv = sftkdb_VerifyAttribute(handle, passKey, CK_INVALID_HANDLE,
|
|
|
|
+ type, *plain, &signature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-01 22:12:42 +00:00
|
|
|
@@ -1198,6 +1214,7 @@ sftk_updateEncrypted(PLArenaPool *arena,
|
2021-06-21 17:17:18 +00:00
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < privAttrCount; i++) {
|
|
|
|
// Read the old attribute in the clear.
|
|
|
|
+ CK_OBJECT_HANDLE sdbId = id & SFTK_OBJ_ID_MASK;
|
|
|
|
CK_ATTRIBUTE privAttr = { privAttrTypes[i], NULL, 0 };
|
|
|
|
CK_RV crv = sftkdb_GetAttributeValue(keydb, id, &privAttr, 1);
|
|
|
|
if (crv != CKR_OK) {
|
2021-07-01 22:12:42 +00:00
|
|
|
@@ -1222,7 +1239,7 @@ sftk_updateEncrypted(PLArenaPool *arena,
|
2021-06-21 17:17:18 +00:00
|
|
|
plainText.data = privAttr.pValue;
|
|
|
|
plainText.len = privAttr.ulValueLen;
|
|
|
|
if (sftkdb_EncryptAttribute(arena, keydb, keydb->db, newKey,
|
|
|
|
- iterationCount, id, privAttr.type,
|
|
|
|
+ iterationCount, sdbId, privAttr.type,
|
|
|
|
&plainText, &result) != SECSuccess) {
|
|
|
|
return CKR_GENERAL_ERROR;
|
|
|
|
}
|
2021-07-01 22:12:42 +00:00
|
|
|
@@ -1232,10 +1249,9 @@ sftk_updateEncrypted(PLArenaPool *arena,
|
2021-06-21 17:17:18 +00:00
|
|
|
PORT_Memset(plainText.data, 0, plainText.len);
|
|
|
|
|
|
|
|
// Write the newly encrypted attributes out directly.
|
|
|
|
- CK_OBJECT_HANDLE newId = id & SFTK_OBJ_ID_MASK;
|
|
|
|
keydb->newKey = newKey;
|
|
|
|
keydb->newDefaultIterationCount = iterationCount;
|
|
|
|
- crv = (*keydb->db->sdb_SetAttributeValue)(keydb->db, newId, &privAttr, 1);
|
|
|
|
+ crv = (*keydb->db->sdb_SetAttributeValue)(keydb->db, sdbId, &privAttr, 1);
|
|
|
|
keydb->newKey = NULL;
|
|
|
|
if (crv != CKR_OK) {
|
|
|
|
return crv;
|