mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 00:12:43 +01:00
Signer infrastructure: Prep for #9076
This sets up infrastructure in libutil to allow for signing other than by a secret key in memory. #9076 uses this to implement remote signing. (Split from that PR to allow reviewing in smaller chunks.) Co-Authored-By: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
parent
315aade89d
commit
12bb8cdd38
24 changed files with 233 additions and 70 deletions
61
src/libutil/signature/signer.hh
Normal file
61
src/libutil/signature/signer.hh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.hh"
|
||||
#include "signature/local-keys.hh"
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
* An abstract signer
|
||||
*
|
||||
* Derive from this class to implement a custom signature scheme.
|
||||
*
|
||||
* It is only necessary to implement signature of bytes and provide a
|
||||
* public key.
|
||||
*/
|
||||
struct Signer
|
||||
{
|
||||
virtual ~Signer() = default;
|
||||
|
||||
/**
|
||||
* Sign the given data, creating a (detached) signature.
|
||||
*
|
||||
* @param data data to be signed.
|
||||
*
|
||||
* @return the [detached
|
||||
* signature](https://en.wikipedia.org/wiki/Detached_signature),
|
||||
* i.e. just the signature itself without a copy of the signed data.
|
||||
*/
|
||||
virtual std::string signDetached(std::string_view data) const = 0;
|
||||
|
||||
/**
|
||||
* View the public key associated with this `Signer`.
|
||||
*/
|
||||
virtual const PublicKey & getPublicKey() = 0;
|
||||
};
|
||||
|
||||
using Signers = std::map<std::string, Signer*>;
|
||||
|
||||
/**
|
||||
* Local signer
|
||||
*
|
||||
* The private key is held in this machine's RAM
|
||||
*/
|
||||
struct LocalSigner : Signer
|
||||
{
|
||||
LocalSigner(SecretKey && privateKey);
|
||||
|
||||
std::string signDetached(std::string_view s) const override;
|
||||
|
||||
const PublicKey & getPublicKey() override;
|
||||
|
||||
private:
|
||||
|
||||
SecretKey privateKey;
|
||||
PublicKey publicKey;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue