lokinet/llarp/service/identity.hpp

71 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
2018-12-12 02:15:08 +00:00
#include <llarp/config/key_manager.hpp>
#include <llarp/constants/proto.hpp>
#include <llarp/crypto/types.hpp>
#include <memory>
#include "info.hpp"
#include "intro_set.hpp"
#include "vanity.hpp"
#include <llarp/util/buffer.hpp>
2018-07-09 17:32:11 +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
{
SecretKey enckey;
SecretKey signkey;
PrivateKey derivedSignKey;
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
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
/// @param needBackup determines whether existing keys will be cycled
void
EnsureKeys(fs::path fpath, bool needBackup);
2018-07-09 17:32:11 +00:00
bool
KeyExchange(
path_dh_func dh,
SharedSecret& sharedkey,
const ServiceInfo& other,
const KeyExchangeNonce& N) const;
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
std::optional<EncryptedIntroSet>
2020-01-27 21:30:41 +00:00
EncryptAndSignIntroSet(const IntroSet& i, llarp_time_t now) const;
bool
Sign(Signature& sig, const llarp_buffer_t& buf) const;
/// zero out all secret key members
void
Clear();
2018-07-09 17:32:11 +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