Skip to content

Commit 971f65b

Browse files
committed
Bug 198090 - Part 2: Use AES in the SDR (m-c) r=simonf,nss-reviewers,rrelyea
Differential Revision: https://phabricator.services.mozilla.com/D251031
1 parent d56a0fa commit 971f65b

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

modules/libpref/init/StaticPrefList.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17225,6 +17225,15 @@
1722517225
value: false
1722617226
mirror: always
1722717227

17228+
# Which mechanism the secret decoder ring should use for encryption. Decryption
17229+
# can always happen with all mechanisms.
17230+
# 0 - DES3_CBC
17231+
# 1 - AES_CBC
17232+
- name: security.sdr.mechanism
17233+
type: RelaxedAtomicUint32
17234+
value: 0
17235+
mirror: always
17236+
1722817237
#---------------------------------------------------------------------------
1722917238
# Prefs starting with "signon."
1723017239
#---------------------------------------------------------------------------

security/manager/ssl/SecretDecoderRing.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mozilla/Casting.h"
1212
#include "mozilla/Logging.h"
1313
#include "mozilla/Services.h"
14+
#include "mozilla/StaticPrefs_security.h"
1415
#include "mozilla/ErrorResult.h"
1516
#include "mozilla/dom/Promise.h"
1617
#include "nsCOMPtr.h"
@@ -23,7 +24,7 @@
2324
#include "nsNetCID.h"
2425
#include "nsPK11TokenDB.h"
2526
#include "pk11func.h"
26-
#include "pk11sdr.h" // For PK11SDR_Encrypt, PK11SDR_Decrypt
27+
#include "pk11sdr.h"
2728

2829
static mozilla::LazyLogModule gSDRLog("sdrlog");
2930

@@ -108,7 +109,8 @@ void BackgroundSdrDecryptStrings(const nsTArray<nsCString>& encryptedStrings,
108109
NS_DispatchToMainThread(runnable.forget());
109110
}
110111

111-
nsresult SecretDecoderRing::Encrypt(const nsACString& data,
112+
nsresult SecretDecoderRing::Encrypt(CK_MECHANISM_TYPE type,
113+
const nsACString& data,
112114
/*out*/ nsACString& result) {
113115
UniquePK11SlotInfo slot(PK11_GetInternalKeySlot());
114116
if (!slot) {
@@ -135,7 +137,8 @@ nsresult SecretDecoderRing::Encrypt(const nsACString& data,
135137
request.data = BitwiseCast<unsigned char*, const char*>(data.BeginReading());
136138
request.len = data.Length();
137139
ScopedAutoSECItem reply;
138-
if (PK11SDR_Encrypt(&keyid, &request, &reply, ctx) != SECSuccess) {
140+
if (PK11SDR_EncryptWithMechanism(slot.get(), &keyid, type, &request, &reply,
141+
ctx) != SECSuccess) {
139142
return NS_ERROR_FAILURE;
140143
}
141144

@@ -172,8 +175,19 @@ nsresult SecretDecoderRing::Decrypt(const nsACString& data,
172175
NS_IMETHODIMP
173176
SecretDecoderRing::EncryptString(const nsACString& text,
174177
/*out*/ nsACString& encryptedBase64Text) {
178+
CK_MECHANISM_TYPE type;
179+
nsCString prefix;
180+
switch (StaticPrefs::security_sdr_mechanism()) {
181+
case 0:
182+
type = CKM_DES3_CBC;
183+
break;
184+
case 1:
185+
default:
186+
type = CKM_AES_CBC;
187+
break;
188+
}
175189
nsAutoCString encryptedText;
176-
nsresult rv = Encrypt(text, encryptedText);
190+
nsresult rv = Encrypt(type, text, encryptedText);
177191
if (NS_FAILED(rv)) {
178192
return rv;
179193
}

security/manager/ssl/SecretDecoderRing.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define SecretDecoderRing_h
99

1010
#include "nsISecretDecoderRing.h"
11-
#include "nsString.h"
11+
#include "pkcs11t.h"
1212

1313
#define NS_SECRETDECODERRING_CONTRACTID "@mozilla.org/security/sdr;1"
1414

@@ -26,7 +26,8 @@ class SecretDecoderRing : public nsISecretDecoderRing {
2626
virtual ~SecretDecoderRing() = default;
2727

2828
private:
29-
nsresult Encrypt(const nsACString& data, /*out*/ nsACString& result);
29+
nsresult Encrypt(CK_MECHANISM_TYPE type, const nsACString& data,
30+
/*out*/ nsACString& result);
3031
nsresult Decrypt(const nsACString& data, /*out*/ nsACString& result);
3132
};
3233

security/nss.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ PK11_ReferenceSlot
444444
PK11_ReferenceSymKey
445445
PK11_ResetToken
446446
PK11SDR_Decrypt
447-
PK11SDR_Encrypt
447+
PK11SDR_EncryptWithMechanism
448448
PK11_SetPasswordFunc
449449
PK11_SetSymKeyNickname
450450
PK11_Sign

0 commit comments

Comments
 (0)