2021-03-09 23:24:35 +01:00
|
|
|
#pragma once
|
2018-12-12 03:15:08 +01:00
|
|
|
|
2021-03-09 23:24:35 +01:00
|
|
|
#include <llarp/config/key_manager.hpp>
|
|
|
|
#include <llarp/constants/proto.hpp>
|
|
|
|
#include <llarp/crypto/types.hpp>
|
2019-12-06 19:21:14 +01:00
|
|
|
#include <memory>
|
2021-03-09 23:24:35 +01:00
|
|
|
#include "info.hpp"
|
|
|
|
#include "intro_set.hpp"
|
|
|
|
#include "vanity.hpp"
|
|
|
|
#include <llarp/util/buffer.hpp>
|
2018-07-09 19:32:11 +02:00
|
|
|
|
2019-05-18 19:34:07 +02:00
|
|
|
#include <tuple>
|
|
|
|
|
2018-07-09 19:32:11 +02:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
// private keys
|
2019-05-24 04:01:36 +02:00
|
|
|
struct Identity
|
2018-07-09 19:32:11 +02:00
|
|
|
{
|
2019-04-22 20:35:19 +02:00
|
|
|
SecretKey enckey;
|
|
|
|
SecretKey signkey;
|
2020-01-30 17:34:05 +01:00
|
|
|
PrivateKey derivedSignKey;
|
2019-04-22 20:35:19 +02:00
|
|
|
PQKeyPair pq;
|
2022-05-26 17:59:44 +02:00
|
|
|
uint64_t version = llarp::constants::proto_version;
|
2018-07-09 19:32:11 +02:00
|
|
|
VanityNonce vanity;
|
|
|
|
|
|
|
|
// public service info
|
|
|
|
ServiceInfo pub;
|
|
|
|
|
|
|
|
// regenerate secret keys
|
|
|
|
void
|
2019-05-28 21:45:08 +02:00
|
|
|
RegenerateKeys();
|
2018-07-09 19:32:11 +02:00
|
|
|
|
|
|
|
bool
|
2019-05-24 04:01:36 +02:00
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
2018-07-09 19:32:11 +02:00
|
|
|
|
2019-12-06 19:21:14 +01:00
|
|
|
/// @param needBackup determines whether existing keys will be cycled
|
2020-09-22 21:04:31 +02:00
|
|
|
void
|
2020-09-23 13:05:37 +02:00
|
|
|
EnsureKeys(fs::path fpath, bool needBackup);
|
2018-07-09 19:32:11 +02:00
|
|
|
|
2018-08-14 01:22:31 +02:00
|
|
|
bool
|
2020-04-07 20:38:56 +02:00
|
|
|
KeyExchange(
|
|
|
|
path_dh_func dh,
|
|
|
|
SharedSecret& sharedkey,
|
|
|
|
const ServiceInfo& other,
|
|
|
|
const KeyExchangeNonce& N) const;
|
2018-08-14 01:22:31 +02:00
|
|
|
|
2018-07-09 19:32:11 +02:00
|
|
|
bool
|
2019-05-24 04:01:36 +02:00
|
|
|
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
|
2018-07-09 19:32:11 +02:00
|
|
|
|
2020-05-01 21:51:15 +02:00
|
|
|
std::optional<EncryptedIntroSet>
|
2020-01-27 22:30:41 +01:00
|
|
|
EncryptAndSignIntroSet(const IntroSet& i, llarp_time_t now) const;
|
2018-08-14 01:22:31 +02:00
|
|
|
|
|
|
|
bool
|
2019-05-28 21:45:08 +02:00
|
|
|
Sign(Signature& sig, const llarp_buffer_t& buf) const;
|
2020-09-28 17:15:07 +02:00
|
|
|
|
|
|
|
/// zero out all secret key members
|
|
|
|
void
|
|
|
|
Clear();
|
2018-07-09 19:32:11 +02:00
|
|
|
};
|
2019-05-18 19:34:07 +02:00
|
|
|
|
|
|
|
inline bool
|
|
|
|
operator==(const Identity& lhs, const Identity& rhs)
|
|
|
|
{
|
|
|
|
return std::tie(lhs.enckey, lhs.signkey, lhs.pq, lhs.version, lhs.vanity)
|
|
|
|
== std::tie(rhs.enckey, rhs.signkey, rhs.pq, rhs.version, rhs.vanity);
|
|
|
|
}
|
2018-07-09 19:32:11 +02:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|