2020-06-08 12:42:10 +00:00
|
|
|
#include <llarp.hpp>
|
|
|
|
#include <config/config.hpp>
|
|
|
|
#include <router/abstractrouter.hpp>
|
|
|
|
#include <service/context.hpp>
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
2020-07-01 14:38:56 +00:00
|
|
|
llarp::RuntimeOptions opts = {false, false, false};
|
|
|
|
|
2021-04-26 10:19:46 +00:00
|
|
|
/// make a context with 1 endpoint that specifies a keyfile
|
2020-06-29 19:55:59 +00:00
|
|
|
static std::shared_ptr<llarp::Context>
|
2020-06-08 19:36:47 +00:00
|
|
|
make_context(std::optional<fs::path> keyfile)
|
2020-06-08 12:42:10 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
auto conf = std::make_shared<llarp::Config>(fs::current_path());
|
2021-03-23 19:00:46 +00:00
|
|
|
conf->Load(std::nullopt, opts.isSNode);
|
2021-02-02 14:35:40 +00:00
|
|
|
conf->network.m_endpointType = "null";
|
|
|
|
conf->network.m_keyfile = keyfile;
|
|
|
|
conf->bootstrap.seednode = true;
|
|
|
|
conf->api.m_enableRPCServer = false;
|
2020-06-29 19:55:59 +00:00
|
|
|
|
2020-07-06 19:13:01 +00:00
|
|
|
auto context = std::make_shared<llarp::Context>();
|
|
|
|
REQUIRE_NOTHROW(context->Configure(std::move(conf)));
|
2020-06-29 19:55:59 +00:00
|
|
|
|
|
|
|
return context;
|
2020-06-08 12:42:10 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 19:36:47 +00:00
|
|
|
/// test that we dont back up all keys when self.signed is missing or invalid as client
|
2020-06-08 12:42:10 +00:00
|
|
|
TEST_CASE("key backup bug regression test", "[regress]")
|
|
|
|
{
|
2020-06-08 19:36:47 +00:00
|
|
|
// kill logging, this code is noisy
|
|
|
|
// test 2 explicitly provided keyfiles, empty keyfile and no keyfile
|
|
|
|
for (std::optional<fs::path> path : {std::optional<fs::path>{"regress-1.private"},
|
|
|
|
std::optional<fs::path>{"regress-2.private"},
|
|
|
|
std::optional<fs::path>{""},
|
|
|
|
{std::nullopt}})
|
2020-06-08 13:26:53 +00:00
|
|
|
{
|
|
|
|
llarp::service::Address endpointAddress{};
|
2020-06-08 19:36:47 +00:00
|
|
|
// try 10 start up and shut downs and see if our key changes or not
|
2020-06-08 13:26:53 +00:00
|
|
|
for (size_t index = 0; index < 10; index++)
|
2020-06-08 13:07:49 +00:00
|
|
|
{
|
2020-06-29 19:55:59 +00:00
|
|
|
auto ctx = make_context(path);
|
2020-07-01 14:38:56 +00:00
|
|
|
REQUIRE_NOTHROW(ctx->Setup(opts));
|
2020-06-08 13:26:53 +00:00
|
|
|
ctx->CallSafe([ctx, index, &endpointAddress, &path]() {
|
|
|
|
auto ep = ctx->router->hiddenServiceContext().GetDefault();
|
|
|
|
REQUIRE(ep != nullptr);
|
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
REQUIRE(endpointAddress.IsZero());
|
2020-06-08 19:36:47 +00:00
|
|
|
// first iteration, we are getting our identity that we start with
|
2020-06-08 13:26:53 +00:00
|
|
|
endpointAddress = ep->GetIdentity().pub.Addr();
|
|
|
|
REQUIRE(not endpointAddress.IsZero());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
REQUIRE(not endpointAddress.IsZero());
|
2020-06-08 19:36:47 +00:00
|
|
|
if (path.has_value() and not path->empty())
|
2020-06-08 13:07:49 +00:00
|
|
|
{
|
2020-06-08 19:36:47 +00:00
|
|
|
// we have a keyfile provided
|
|
|
|
// after the first iteration we expect the keys to stay the same
|
|
|
|
REQUIRE(endpointAddress == ep->GetIdentity().pub.Addr());
|
2020-06-08 13:07:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-08 19:36:47 +00:00
|
|
|
// we want the keys to shift because no keyfile was provided
|
|
|
|
REQUIRE(endpointAddress != ep->GetIdentity().pub.Addr());
|
2020-06-08 13:07:49 +00:00
|
|
|
}
|
2020-06-08 13:26:53 +00:00
|
|
|
}
|
2020-06-16 11:28:20 +00:00
|
|
|
// close the router right away
|
|
|
|
ctx->router->Die();
|
2020-06-08 13:26:53 +00:00
|
|
|
});
|
2020-06-29 19:55:59 +00:00
|
|
|
REQUIRE(ctx->Run({}) == 0);
|
|
|
|
ctx.reset();
|
2020-06-08 13:07:49 +00:00
|
|
|
}
|
2020-06-08 19:36:47 +00:00
|
|
|
// remove keys if provied
|
|
|
|
if (path.has_value() and not path->empty())
|
|
|
|
fs::remove(*path);
|
2020-06-08 13:26:53 +00:00
|
|
|
}
|
2020-06-08 12:42:10 +00:00
|
|
|
}
|