Replace NSS with Pale Moon's

This commit is contained in:
wuggy 2026-06-29 21:29:25 +01:00
commit 8c2e376f94
2870 changed files with 1762232 additions and 1374220 deletions

View file

@ -14,6 +14,7 @@
#include "secpkcs7.h"
#include "secasn1.h"
#include "secerr.h"
#include "sechash.h"
#include "pk11func.h"
#include "p12plcy.h"
#include "p12local.h"
@ -379,11 +380,18 @@ SEC_PKCS12CreatePasswordPrivSafe(SEC_PKCS12ExportContext *p12ctxt,
safeInfo->itemCount = 0;
/* create the encrypted safe */
if (!SEC_PKCS5IsAlgorithmPBEAlgTag(privAlg) &&
PK11_AlgtagToMechanism(privAlg) == CKM_AES_CBC) {
if (!SEC_PKCS5IsAlgorithmPBEAlgTag(privAlg)) {
SECOidTag prfAlg = SEC_OID_UNKNOWN;
/* if we have password integrity set, use that to set the integrity
* hash algorithm to set our password PRF. If we haven't set it, just
* let the low level code pick it */
if (p12ctxt->integrityEnabled && p12ctxt->pwdIntegrity) {
prfAlg = HASH_GetHMACOidTagByHashOidTag(
p12ctxt->integrityInfo.pwdInfo.algorithm);
}
safeInfo->cinfo = SEC_PKCS7CreateEncryptedDataWithPBEV2(SEC_OID_PKCS5_PBES2,
privAlg,
SEC_OID_UNKNOWN,
prfAlg,
0,
p12ctxt->pwfn,
p12ctxt->pwfnarg);
@ -1213,6 +1221,7 @@ SEC_PKCS12AddKeyForCert(SEC_PKCS12ExportContext *p12ctxt, SEC_PKCS12SafeInfo *sa
/* extract the key encrypted */
SECKEYEncryptedPrivateKeyInfo *epki = NULL;
PK11SlotInfo *slot = NULL;
SECOidTag prfAlg = SEC_OID_UNKNOWN;
if (!sec_pkcs12_encode_password(p12ctxt->arena, &uniPwitem, algorithm,
pwitem)) {
@ -1220,6 +1229,14 @@ SEC_PKCS12AddKeyForCert(SEC_PKCS12ExportContext *p12ctxt, SEC_PKCS12SafeInfo *sa
goto loser;
}
/* if we have password integrity set, use that to set the integrity
* hash algorithm to set our password PRF. If we haven't set it, just
* let the low level code pick it */
if (p12ctxt->integrityEnabled && p12ctxt->pwdIntegrity) {
prfAlg = HASH_GetHMACOidTagByHashOidTag(
p12ctxt->integrityInfo.pwdInfo.algorithm);
}
/* we want to make sure to take the key out of the key slot */
if (PK11_IsInternal(p12ctxt->slot)) {
slot = PK11_GetInternalKeySlot();
@ -1227,10 +1244,15 @@ SEC_PKCS12AddKeyForCert(SEC_PKCS12ExportContext *p12ctxt, SEC_PKCS12SafeInfo *sa
slot = PK11_ReferenceSlot(p12ctxt->slot);
}
epki = PK11_ExportEncryptedPrivateKeyInfo(slot, algorithm,
&uniPwitem, cert,
NSS_PBE_DEFAULT_ITERATION_COUNT,
p12ctxt->wincx);
/* passing algorithm as the pbe will force the PBE code to
* automatically handle the selection between using the algorithm
* as a the pbe algorithm, or using the algorithm as a cipher
* and building a pkcs5 pbe */
epki = PK11_ExportEncryptedPrivateKeyInfoV2(slot, algorithm,
SEC_OID_UNKNOWN, prfAlg,
&uniPwitem, cert,
NSS_PBE_DEFAULT_ITERATION_COUNT,
p12ctxt->wincx);
PK11_FreeSlot(slot);
if (!epki) {
PORT_SetError(SEC_ERROR_PKCS12_UNABLE_TO_EXPORT_KEY);
@ -1595,18 +1617,10 @@ sec_pkcs12_encoder_start_context(SEC_PKCS12ExportContext *p12exp)
SECITEM_ZfreeItem(&pwd, PR_FALSE);
/* get the PBA Mechanism to generate the key */
switch (p12exp->integrityInfo.pwdInfo.algorithm) {
case SEC_OID_SHA1:
integrityMechType = CKM_PBA_SHA1_WITH_SHA1_HMAC;
break;
case SEC_OID_MD5:
integrityMechType = CKM_NETSCAPE_PBE_MD5_HMAC_KEY_GEN;
break;
case SEC_OID_MD2:
integrityMechType = CKM_NETSCAPE_PBE_MD2_HMAC_KEY_GEN;
break;
default:
goto loser;
integrityMechType = sec_pkcs12_algtag_to_keygen_mech(
p12exp->integrityInfo.pwdInfo.algorithm);
if (integrityMechType == CKM_INVALID_MECHANISM) {
goto loser;
}
/* generate the key */
@ -1837,7 +1851,8 @@ loser:
static SECStatus
sec_Pkcs12FinishMac(sec_PKCS12EncoderContext *p12ecx)
{
SECItem hmac = { siBuffer, NULL, 0 };
unsigned char hmacData[HASH_LENGTH_MAX];
unsigned int hmacLen;
SECStatus rv;
SGNDigestInfo *di = NULL;
void *dummy;
@ -1856,13 +1871,8 @@ sec_Pkcs12FinishMac(sec_PKCS12EncoderContext *p12ecx)
}
/* finish the hmac */
hmac.data = (unsigned char *)PORT_ZAlloc(SHA1_LENGTH);
if (!hmac.data) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return SECFailure;
}
rv = PK11_DigestFinal(p12ecx->hmacCx, hmac.data, &hmac.len, SHA1_LENGTH);
rv = PK11_DigestFinal(p12ecx->hmacCx, hmacData, &hmacLen, HASH_LENGTH_MAX);
if (rv != SECSuccess) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
@ -1871,7 +1881,7 @@ sec_Pkcs12FinishMac(sec_PKCS12EncoderContext *p12ecx)
/* create the digest info */
di = SGN_CreateDigestInfo(p12ecx->p12exp->integrityInfo.pwdInfo.algorithm,
hmac.data, hmac.len);
hmacData, hmacLen);
if (!di) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
rv = SECFailure;
@ -1896,11 +1906,9 @@ loser:
if (di) {
SGN_DestroyDigestInfo(di);
}
if (hmac.data) {
SECITEM_ZfreeItem(&hmac, PR_FALSE);
}
PK11_DestroyContext(p12ecx->hmacCx, PR_TRUE);
p12ecx->hmacCx = NULL;
PORT_Memset(hmacData, 0, hmacLen);
return rv;
}