2019-01-13 14:00:50 +00:00
|
|
|
#include <crypto/crypto.hpp>
|
2019-01-26 15:40:58 +00:00
|
|
|
#include <crypto/crypto_libsodium.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/path.hpp>
|
2019-01-11 00:12:43 +00:00
|
|
|
#include <service/address.hpp>
|
2019-04-22 18:35:19 +00:00
|
|
|
#include <service/identity.hpp>
|
|
|
|
#include <service/intro_set.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/time.hpp>
|
2018-07-06 16:08:30 +00:00
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2018-07-06 16:08:30 +00:00
|
|
|
struct HiddenServiceTest : public ::testing::Test
|
|
|
|
{
|
2019-01-26 15:40:58 +00:00
|
|
|
llarp::sodium::CryptoLibSodium crypto;
|
2018-07-06 16:08:30 +00:00
|
|
|
llarp::service::Identity ident;
|
|
|
|
|
2019-01-26 15:40:58 +00:00
|
|
|
HiddenServiceTest()
|
2018-07-06 16:08:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-11 00:53:11 +00:00
|
|
|
llarp::Crypto*
|
2018-07-06 16:08:30 +00:00
|
|
|
Crypto()
|
|
|
|
{
|
|
|
|
return &crypto;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetUp()
|
|
|
|
{
|
|
|
|
ident.RegenerateKeys(Crypto());
|
2018-08-10 21:34:11 +00:00
|
|
|
ident.pub.RandomizeVanity();
|
2018-08-02 00:48:43 +00:00
|
|
|
ident.pub.UpdateAddr();
|
2018-07-06 16:08:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(HiddenServiceTest, TestGenerateIntroSet)
|
|
|
|
{
|
|
|
|
llarp::service::Address addr;
|
2019-01-02 01:03:53 +00:00
|
|
|
ASSERT_TRUE(ident.pub.CalculateAddress(addr.as_array()));
|
2018-07-06 16:08:30 +00:00
|
|
|
llarp::service::IntroSet I;
|
2018-11-19 22:45:37 +00:00
|
|
|
auto now = llarp::time_now_ms();
|
2018-10-29 16:49:09 +00:00
|
|
|
I.T = now;
|
2018-07-06 16:08:30 +00:00
|
|
|
while(I.I.size() < 10)
|
|
|
|
{
|
|
|
|
llarp::service::Introduction intro;
|
2019-04-05 14:58:22 +00:00
|
|
|
intro.expiresAt = now + (llarp::path::default_lifetime / 2);
|
2018-07-06 16:08:30 +00:00
|
|
|
intro.router.Randomize();
|
|
|
|
intro.pathID.Randomize();
|
2019-04-05 14:58:22 +00:00
|
|
|
I.I.emplace_back(std::move(intro));
|
2018-07-06 16:08:30 +00:00
|
|
|
}
|
2018-10-29 16:49:09 +00:00
|
|
|
ASSERT_TRUE(ident.SignIntroSet(I, Crypto(), now));
|
|
|
|
ASSERT_TRUE(I.Verify(Crypto(), now));
|
2018-08-02 00:48:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(HiddenServiceTest, TestAddressToFromString)
|
|
|
|
{
|
|
|
|
auto str = ident.pub.Addr().ToString();
|
|
|
|
llarp::service::Address addr;
|
|
|
|
ASSERT_TRUE(addr.FromString(str));
|
|
|
|
ASSERT_TRUE(addr == ident.pub.Addr());
|
2018-09-02 18:25:42 +00:00
|
|
|
}
|