Skip to content

Commit

Permalink
enforce trusted catchup
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Jan 4, 2023
1 parent d0f6c0e commit d260875
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,16 @@ parseCatchup(std::string const& catchup, std::string const& hash,
throw std::runtime_error(errorMessage);
}

Hash validHash;
try
{
validHash = hexToBin256(hash);
}
catch (std::exception&)
{
throw std::runtime_error("Invalid trusted hash");
}

try
{
auto mode = extraValidation
Expand All @@ -516,8 +526,7 @@ parseCatchup(std::string const& catchup, std::string const& hash,
else
{
return CatchupConfiguration(
{ledger, std::make_optional<Hash>(hexToBin256(hash))}, count,
mode);
{ledger, std::make_optional<Hash>(validHash)}, count, mode);
}
}
catch (std::exception&)
Expand Down Expand Up @@ -901,12 +910,12 @@ runCatchup(CommandLineArgs const& args)
}
else if (hash.empty() && !forceUntrusted)
{
CLOG_WARNING(
History,
std::string msg =
"Unsafe command: use --trusted-checkpoint-hashes or "
"--trusted-hash to ensure catchup integrity. If you "
"want to run untrusted catchup, use "
"--force-untrusted-catchup.");
"--force-untrusted-catchup";
throw std::runtime_error(msg);
}

Json::Value catchupInfo;
Expand Down

0 comments on commit d260875

Please sign in to comment.