2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_SERVICE_IDENTITY_HPP
|
|
|
|
#define LLARP_SERVICE_IDENTITY_HPP
|
2018-12-12 02:15:08 +00:00
|
|
|
|
2019-12-06 18:21:14 +00:00
|
|
|
#include <config/key_manager.hpp>
|
2019-05-24 02:01:36 +00:00
|
|
|
#include <constants/proto.hpp>
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-12-06 18:21:14 +00:00
|
|
|
#include <memory>
|
2019-04-22 18:35:19 +00:00
|
|
|
#include <service/info.hpp>
|
|
|
|
#include <service/intro_set.hpp>
|
|
|
|
#include <service/vanity.hpp>
|
2019-05-24 02:01:36 +00:00
|
|
|
#include <util/buffer.hpp>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2019-05-18 17:34:07 +00:00
|
|
|
#include <tuple>
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
// private keys
|
2019-05-24 02:01:36 +00:00
|
|
|
struct Identity
|
2018-07-09 17:32:11 +00:00
|
|
|
{
|
2019-04-22 18:35:19 +00:00
|
|
|
SecretKey enckey;
|
|
|
|
SecretKey signkey;
|
2020-01-30 16:34:05 +00:00
|
|
|
PrivateKey derivedSignKey;
|
2019-04-22 18:35:19 +00:00
|
|
|
PQKeyPair pq;
|
2019-05-24 02:01:36 +00:00
|
|
|
uint64_t version = LLARP_PROTO_VERSION;
|
2018-07-09 17:32:11 +00:00
|
|
|
VanityNonce vanity;
|
|
|
|
|
|
|
|
// public service info
|
|
|
|
ServiceInfo pub;
|
|
|
|
|
|
|
|
// regenerate secret keys
|
|
|
|
void
|
2019-05-28 19:45:08 +00:00
|
|
|
RegenerateKeys();
|
2018-07-09 17:32:11 +00:00
|
|
|
|
|
|
|
bool
|
2019-05-24 02:01:36 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2019-12-06 18:21:14 +00:00
|
|
|
/// @param needBackup determines whether existing keys will be cycled
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
2019-12-06 18:21:14 +00:00
|
|
|
EnsureKeys(const std::string& fpath, bool needBackup);
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-08-13 23:22:31 +00:00
|
|
|
bool
|
2019-04-22 18:35:19 +00:00
|
|
|
KeyExchange(path_dh_func dh, SharedSecret& sharedkey,
|
2019-01-02 01:04:04 +00:00
|
|
|
const ServiceInfo& other, const KeyExchangeNonce& N) const;
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
2019-05-24 02:01:36 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2020-02-19 21:58:01 +00:00
|
|
|
nonstd::optional< EncryptedIntroSet >
|
2020-01-27 21:30:41 +00:00
|
|
|
EncryptAndSignIntroSet(const IntroSet& i, llarp_time_t now) const;
|
2018-08-13 23:22:31 +00:00
|
|
|
|
|
|
|
bool
|
2019-05-28 19:45:08 +00:00
|
|
|
Sign(Signature& sig, const llarp_buffer_t& buf) const;
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
2019-05-18 17:34:07 +00: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 17:32:11 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-11-05 11:27:12 +00:00
|
|
|
#endif
|