2020-06-25 00:22:13 +03:00
|
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
|
///@file
|
2020-06-25 00:22:13 +03:00
|
|
|
|
|
2024-01-03 22:02:20 +02:00
|
|
|
|
#include "signature/signer.hh"
|
2020-06-25 00:22:13 +03:00
|
|
|
|
#include "path.hh"
|
|
|
|
|
#include "hash.hh"
|
|
|
|
|
#include "content-address.hh"
|
2020-08-04 00:02:28 +03:00
|
|
|
|
|
2020-06-25 00:22:13 +03:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Store;
|
|
|
|
|
|
2020-08-05 02:16:18 +03:00
|
|
|
|
|
2023-01-06 22:36:05 +02:00
|
|
|
|
struct SubstitutablePathInfo
|
2020-08-04 00:02:28 +03:00
|
|
|
|
{
|
|
|
|
|
std::optional<StorePath> deriver;
|
2023-01-14 23:38:43 +02:00
|
|
|
|
StorePathSet references;
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* 0 = unknown or inapplicable
|
|
|
|
|
*/
|
|
|
|
|
uint64_t downloadSize;
|
|
|
|
|
/**
|
|
|
|
|
* 0 = unknown
|
|
|
|
|
*/
|
|
|
|
|
uint64_t narSize;
|
2020-08-04 00:02:28 +03:00
|
|
|
|
};
|
|
|
|
|
|
2023-10-24 21:16:34 +03:00
|
|
|
|
using SubstitutablePathInfos = std::map<StorePath, SubstitutablePathInfo>;
|
2020-08-04 00:02:28 +03:00
|
|
|
|
|
2023-01-14 23:38:43 +02:00
|
|
|
|
|
2023-04-18 00:13:44 +03:00
|
|
|
|
struct UnkeyedValidPathInfo
|
2020-06-25 00:22:13 +03:00
|
|
|
|
{
|
|
|
|
|
std::optional<StorePath> deriver;
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* \todo document this
|
|
|
|
|
*/
|
2020-08-05 21:42:48 +03:00
|
|
|
|
Hash narHash;
|
2023-01-14 23:38:43 +02:00
|
|
|
|
StorePathSet references;
|
2020-06-25 00:22:13 +03:00
|
|
|
|
time_t registrationTime = 0;
|
|
|
|
|
uint64_t narSize = 0; // 0 = unknown
|
2023-10-24 21:16:46 +03:00
|
|
|
|
uint64_t id = 0; // internal use only
|
2020-06-25 00:22:13 +03:00
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* Whether the path is ultimately trusted, that is, it's a
|
|
|
|
|
* derivation output that was built locally.
|
|
|
|
|
*/
|
2020-06-25 00:22:13 +03:00
|
|
|
|
bool ultimate = false;
|
|
|
|
|
|
|
|
|
|
StringSet sigs; // note: not necessarily verified
|
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* If non-empty, an assertion that the path is content-addressed,
|
|
|
|
|
* i.e., that the store path is computed from a cryptographic hash
|
|
|
|
|
* of the contents of the path, plus some other bits of data like
|
|
|
|
|
* the "name" part of the path. Such a path doesn't need
|
|
|
|
|
* signatures, since we don't have to trust anybody's claim that
|
|
|
|
|
* the path is the output of a particular derivation. (In the
|
|
|
|
|
* extensional store model, we have to trust that the *contents*
|
|
|
|
|
* of an output path of a derivation were actually produced by
|
|
|
|
|
* that derivation. In the intensional model, we have to trust
|
|
|
|
|
* that a particular output path was produced by a derivation; the
|
|
|
|
|
* path then implies the contents.)
|
|
|
|
|
*
|
|
|
|
|
* Ideally, the content-addressability assertion would just be a Boolean,
|
|
|
|
|
* and the store path would be computed from the name component, ‘narHash’
|
|
|
|
|
* and ‘references’. However, we support many types of content addresses.
|
|
|
|
|
*/
|
2020-06-25 00:22:13 +03:00
|
|
|
|
std::optional<ContentAddress> ca;
|
|
|
|
|
|
2023-04-18 00:13:44 +03:00
|
|
|
|
UnkeyedValidPathInfo(const UnkeyedValidPathInfo & other) = default;
|
|
|
|
|
|
|
|
|
|
UnkeyedValidPathInfo(Hash narHash) : narHash(narHash) { };
|
|
|
|
|
|
|
|
|
|
DECLARE_CMP(UnkeyedValidPathInfo);
|
|
|
|
|
|
|
|
|
|
virtual ~UnkeyedValidPathInfo() { }
|
2023-10-23 04:12:54 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param includeImpureInfo If true, variable elements such as the
|
|
|
|
|
* registration time are included.
|
|
|
|
|
*/
|
|
|
|
|
virtual nlohmann::json toJSON(
|
|
|
|
|
const Store & store,
|
|
|
|
|
bool includeImpureInfo,
|
|
|
|
|
HashFormat hashFormat) const;
|
|
|
|
|
static UnkeyedValidPathInfo fromJSON(
|
|
|
|
|
const Store & store,
|
|
|
|
|
const nlohmann::json & json);
|
2023-04-18 00:13:44 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ValidPathInfo : UnkeyedValidPathInfo {
|
|
|
|
|
StorePath path;
|
|
|
|
|
|
|
|
|
|
DECLARE_CMP(ValidPathInfo);
|
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* Return a fingerprint of the store path to be used in binary
|
|
|
|
|
* cache signatures. It contains the store path, the base-32
|
|
|
|
|
* SHA-256 hash of the NAR serialisation of the path, the size of
|
|
|
|
|
* the NAR, and the sorted references. The size field is strictly
|
|
|
|
|
* speaking superfluous, but might prevent endless/excessive data
|
|
|
|
|
* attacks.
|
|
|
|
|
*/
|
2020-06-25 00:22:13 +03:00
|
|
|
|
std::string fingerprint(const Store & store) const;
|
|
|
|
|
|
2024-01-03 22:02:20 +02:00
|
|
|
|
void sign(const Store & store, const Signer & signer);
|
2020-06-25 00:22:13 +03:00
|
|
|
|
|
2023-04-18 00:13:44 +03:00
|
|
|
|
/**
|
|
|
|
|
* @return The `ContentAddressWithReferences` that determines the
|
|
|
|
|
* store path for a content-addressed store object, `std::nullopt`
|
|
|
|
|
* for an input-addressed store object.
|
|
|
|
|
*/
|
2023-02-28 18:34:18 +02:00
|
|
|
|
std::optional<ContentAddressWithReferences> contentAddressWithReferences() const;
|
2020-10-07 16:52:20 +03:00
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* @return true iff the path is verifiably content-addressed.
|
|
|
|
|
*/
|
2020-06-25 00:22:13 +03:00
|
|
|
|
bool isContentAddressed(const Store & store) const;
|
|
|
|
|
|
|
|
|
|
static const size_t maxSigs = std::numeric_limits<size_t>::max();
|
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* Return the number of signatures on this .narinfo that were
|
|
|
|
|
* produced by one of the specified keys, or maxSigs if the path
|
|
|
|
|
* is content-addressed.
|
|
|
|
|
*/
|
2020-06-25 00:22:13 +03:00
|
|
|
|
size_t checkSignatures(const Store & store, const PublicKeys & publicKeys) const;
|
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* Verify a single signature.
|
|
|
|
|
*/
|
2020-06-25 00:22:13 +03:00
|
|
|
|
bool checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const;
|
|
|
|
|
|
|
|
|
|
Strings shortRefs() const;
|
|
|
|
|
|
|
|
|
|
ValidPathInfo(const ValidPathInfo & other) = default;
|
|
|
|
|
|
2023-04-18 00:13:44 +03:00
|
|
|
|
ValidPathInfo(StorePath && path, UnkeyedValidPathInfo info) : UnkeyedValidPathInfo(info), path(std::move(path)) { };
|
|
|
|
|
ValidPathInfo(const StorePath & path, UnkeyedValidPathInfo info) : UnkeyedValidPathInfo(info), path(path) { };
|
2020-06-25 00:22:13 +03:00
|
|
|
|
|
2020-10-07 16:52:20 +03:00
|
|
|
|
ValidPathInfo(const Store & store,
|
2023-01-23 19:58:11 +02:00
|
|
|
|
std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
|
2020-10-07 16:52:20 +03:00
|
|
|
|
|
2020-06-25 00:22:13 +03:00
|
|
|
|
virtual ~ValidPathInfo() { }
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-24 21:16:34 +03:00
|
|
|
|
using ValidPathInfos = std::map<StorePath, ValidPathInfo>;
|
2020-06-25 01:46:27 +03:00
|
|
|
|
|
2020-06-25 00:22:13 +03:00
|
|
|
|
}
|