Skip to content

Commit b240e24

Browse files
authored
check HKDF return value in release builds to prevent zero-key signing (#34332)
fix brave/brave-browser#53225
1 parent 1ca2ad1 commit b240e24

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

components/brave_rewards/core/engine/util/signer.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ std::optional<Signer> Signer::FromRecoverySeed(
5656
recovery_seed.data(), kSeedLength, kHkdfSalt, kSaltLength,
5757
info, sizeof(info) / sizeof(info[0]));
5858

59-
DCHECK(hkdf_res);
59+
if (!hkdf_res) {
60+
return std::nullopt;
61+
}
6062

6163
std::vector<uint8_t> public_key(crypto_sign_PUBLICKEYBYTES);
6264
secret_key.resize(crypto_sign_SECRETKEYBYTES);

components/brave_sync/crypto/crypto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright 2019 The Brave Authors. All rights reserved.
22
* This Source Code Form is subject to the terms of the Mozilla Public
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
4-
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
55

66
#include "brave/components/brave_sync/crypto/crypto.h"
77

@@ -37,7 +37,7 @@ std::vector<uint8_t> HKDFSha512(const std::vector<uint8_t>& ikm,
3737
HKDF(derived_key.data(), derived_key.size(), EVP_sha512(), ikm.data(),
3838
ikm.size(), salt ? salt->data() : nullptr, salt ? salt->size() : 0,
3939
info ? info->data() : nullptr, info ? info->size() : 0);
40-
DCHECK(result);
40+
CHECK(result);
4141
return derived_key;
4242
}
4343

0 commit comments

Comments
 (0)