llarp::KeyManager

KeyManager manages the cryptographic keys stored on disk for the local node. More...

#include <key_manager.hpp>

Public Functions

Name
bool backupFileByMoving(const fs::path & filepath)
Utility function to backup a file by moving it.
KeyManager()
Constructor.
bool initialize(const llarp::Config & config, bool genIfAbsent, bool isSNode)
Initializes keys using the provided config, loading from disk.
bool getRouterContact(llarp::RouterContact & rc) const
Obtain the self-signed RouterContact.
bool needBackup() const
Return whether or not we need to backup keys as we load them.

Public Attributes

Name
llarp::SecretKey identityKey
llarp::SecretKey encryptionKey
llarp::SecretKey transportKey
fs::path m_rcPath
fs::path m_idKeyPath
fs::path m_encKeyPath
fs::path m_transportKeyPath

Detailed Description

struct llarp::KeyManager;

KeyManager manages the cryptographic keys stored on disk for the local node.

This includes private keys as well as the self-signed router contact file (e.g. "self.signed").

Keys are either read from disk if they exist and are valid (see below) or are generated and written to disk.

In addition, the KeyManager detects when the keys obsolete (e.g. as a result of a software upgrade) and backs up existing keys before writing out new ones.

Public Functions Documentation

function backupFileByMoving

static bool backupFileByMoving(
    const fs::path & filepath
)

Utility function to backup a file by moving it.

Parameters:

  • filepath is the name of the original file to backup.

Return: true if the file could be moved or didn't exist, false otherwise

Attempts to find a new filename based on the original that doesn't exist, then moves it. The pattern used is originalFile.N.bak where N is the lowest integer matching a filename that doesn't exist.

function KeyManager

KeyManager()

Constructor.

function initialize

bool initialize(
    const llarp::Config & config,
    bool genIfAbsent,
    bool isSNode
)

Initializes keys using the provided config, loading from disk.

Parameters:

  • config should be a prepared config object
  • genIfAbsent determines whether or not we will create files if they do not exist.
  • isSNode

Return: true on success, false otherwise

NOTE: Must be called prior to obtaining any keys. NOTE: blocks on I/O

function getRouterContact

bool getRouterContact(
    llarp::RouterContact & rc
) const

Obtain the self-signed RouterContact.

Parameters:

Return: true on success, false otherwise

function needBackup

inline bool needBackup() const

Return whether or not we need to backup keys as we load them.

Public Attributes Documentation

variable identityKey

llarp::SecretKey identityKey;

variable encryptionKey

llarp::SecretKey encryptionKey;

variable transportKey

llarp::SecretKey transportKey;

variable m_rcPath

fs::path m_rcPath;

variable m_idKeyPath

fs::path m_idKeyPath;

variable m_encKeyPath

fs::path m_encKeyPath;

variable m_transportKeyPath

fs::path m_transportKeyPath;

Updated on 2026-01-10 at 22:49:45 +0000