refactor: write Obfuscation object when new key is generated in dbwrapper
See: * https://github.com/bitcoin/bitcoin/pull/31144#discussion_r2215720251 * https://github.com/bitcoin/bitcoin/pull/31144#discussion_r2223539466 Co-authored-by: maflcko <6399679+maflcko@users.noreply.github.com> Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
1 parent
e5b1b7c557
commit
13f00345c0
1 file changed
+5
-4
+5
-4
@@ -249,11 +249,12 @@ CDBWrapper::CDBWrapper(const DBParams& params)
|
|||||||
LogPrintf("Finished database compaction of %s\n", fs::PathToString(params.path));
|
LogPrintf("Finished database compaction of %s\n", fs::PathToString(params.path));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!m_obfuscation); // Needed for unobfuscated Read()/Write() below
|
|
||||||
if (!Read(OBFUSCATION_KEY, m_obfuscation) && params.obfuscate && IsEmpty()) {
|
if (!Read(OBFUSCATION_KEY, m_obfuscation) && params.obfuscate && IsEmpty()) {
|
||||||
// Generate, write and read back the new obfuscation key, making sure we don't obfuscate the key itself
|
// Generate and write the new obfuscation key.
|
||||||
Write(OBFUSCATION_KEY, FastRandomContext{}.randbytes(Obfuscation::KEY_SIZE));
|
const Obfuscation obfuscation{FastRandomContext{}.randbytes<Obfuscation::KEY_SIZE>()};
|
||||||
Read(OBFUSCATION_KEY, m_obfuscation);
|
assert(!m_obfuscation); // Make sure the key is written without obfuscation.
|
||||||
|
Write(OBFUSCATION_KEY, obfuscation);
|
||||||
|
m_obfuscation = obfuscation;
|
||||||
LogInfo("Wrote new obfuscation key for %s: %s", fs::PathToString(params.path), m_obfuscation.HexKey());
|
LogInfo("Wrote new obfuscation key for %s: %s", fs::PathToString(params.path), m_obfuscation.HexKey());
|
||||||
}
|
}
|
||||||
LogInfo("Using obfuscation key for %s: %s", fs::PathToString(params.path), m_obfuscation.HexKey());
|
LogInfo("Using obfuscation key for %s: %s", fs::PathToString(params.path), m_obfuscation.HexKey());
|
||||||
|
|||||||
Reference in new issue
Block a user