|
|
|
@ -21,8 +21,7 @@ curl_RecvIdentKey(char *ptr, size_t, size_t nmemb, void *userdata)
|
|
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
|
{
|
|
|
|
|
KeyManager::KeyManager()
|
|
|
|
|
: m_initialized(false)
|
|
|
|
|
KeyManager::KeyManager() : m_initialized(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -42,7 +41,6 @@ namespace llarp
|
|
|
|
|
m_lokidRPCUser = config.lokid.lokidRPCUser;
|
|
|
|
|
m_lokidRPCPassword = config.lokid.lokidRPCPassword;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RouterContact rc;
|
|
|
|
|
bool exists = rc.Read(m_rcPath.c_str());
|
|
|
|
|
if(not exists and not genIfAbsent)
|
|
|
|
@ -68,7 +66,8 @@ namespace llarp
|
|
|
|
|
|
|
|
|
|
if(!backupKeyFilesByMoving())
|
|
|
|
|
{
|
|
|
|
|
LogError("Could not mv some key files, please ensure key files"
|
|
|
|
|
LogError(
|
|
|
|
|
"Could not mv some key files, please ensure key files"
|
|
|
|
|
" are backed up if needed and remove");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -78,8 +77,7 @@ namespace llarp
|
|
|
|
|
if(not m_usingLokid)
|
|
|
|
|
{
|
|
|
|
|
// load identity key or create if needed
|
|
|
|
|
auto identityKeygen = [](llarp::SecretKey& key)
|
|
|
|
|
{
|
|
|
|
|
auto identityKeygen = [](llarp::SecretKey& key) {
|
|
|
|
|
// TODO: handle generating from service node seed
|
|
|
|
|
llarp::CryptoManager::instance()->identity_keygen(key);
|
|
|
|
|
};
|
|
|
|
@ -93,16 +91,14 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// load encryption key
|
|
|
|
|
auto encryptionKeygen = [](llarp::SecretKey& key)
|
|
|
|
|
{
|
|
|
|
|
auto encryptionKeygen = [](llarp::SecretKey& key) {
|
|
|
|
|
llarp::CryptoManager::instance()->encryption_keygen(key);
|
|
|
|
|
};
|
|
|
|
|
if(not loadOrCreateKey(m_encKeyPath, m_encKey, encryptionKeygen))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// TODO: transport key (currently done in LinkLayer)
|
|
|
|
|
auto transportKeygen = [](llarp::SecretKey& key)
|
|
|
|
|
{
|
|
|
|
|
auto transportKeygen = [](llarp::SecretKey& key) {
|
|
|
|
|
key.Zero();
|
|
|
|
|
CryptoManager::instance()->encryption_keygen(key);
|
|
|
|
|
};
|
|
|
|
@ -165,12 +161,8 @@ namespace llarp
|
|
|
|
|
return fs::path();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> files = {
|
|
|
|
|
m_rcPath,
|
|
|
|
|
m_idKeyPath,
|
|
|
|
|
m_encKeyPath,
|
|
|
|
|
m_transportKeyPath
|
|
|
|
|
};
|
|
|
|
|
std::vector< std::string > files = {m_rcPath, m_idKeyPath, m_encKeyPath,
|
|
|
|
|
m_transportKeyPath};
|
|
|
|
|
|
|
|
|
|
for(auto& filepath : files)
|
|
|
|
|
{
|
|
|
|
@ -178,7 +170,8 @@ namespace llarp
|
|
|
|
|
bool exists = fs::exists(filepath, ec);
|
|
|
|
|
if(ec)
|
|
|
|
|
{
|
|
|
|
|
LogError("Could not determine status of file ", filepath, ": ", ec.message());
|
|
|
|
|
LogError("Could not determine status of file ", filepath, ": ",
|
|
|
|
|
ec.message());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -195,10 +188,12 @@ namespace llarp
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogInfo("Backing up (moving) key file ", filepath, " to ", newFilepath, "...");
|
|
|
|
|
LogInfo("Backing up (moving) key file ", filepath, " to ", newFilepath,
|
|
|
|
|
"...");
|
|
|
|
|
|
|
|
|
|
fs::rename(filepath, newFilepath, ec);
|
|
|
|
|
if (ec) {
|
|
|
|
|
if(ec)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to move key file ", ec.message());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -209,8 +204,7 @@ namespace llarp
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
KeyManager::loadOrCreateKey(
|
|
|
|
|
const std::string& filepath,
|
|
|
|
|
llarp::SecretKey& key,
|
|
|
|
|
const std::string& filepath, llarp::SecretKey& key,
|
|
|
|
|
std::function< void(llarp::SecretKey& key) > keygen)
|
|
|
|
|
{
|
|
|
|
|
fs::path path(filepath);
|
|
|
|
@ -318,7 +312,8 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
if(ret)
|
|
|
|
|
{
|
|
|
|
|
LogInfo("Got Identity Keys from lokid: ", RouterID(seckey_topublic(m_idKey)));
|
|
|
|
|
LogInfo("Got Identity Keys from lokid: ",
|
|
|
|
|
RouterID(seckey_topublic(m_idKey)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|