2020-06-24 21:22:13 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-08-06 18:31:48 +00:00
|
|
|
|
#include "crypto.hh"
|
2020-06-24 21:22:13 +00:00
|
|
|
|
#include "path.hh"
|
|
|
|
|
#include "hash.hh"
|
|
|
|
|
#include "content-address.hh"
|
2020-08-03 21:02:28 +00:00
|
|
|
|
|
2020-06-24 21:22:13 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Store;
|
|
|
|
|
|
2020-08-04 23:16:18 +00:00
|
|
|
|
|
2023-01-06 20:36:05 +00:00
|
|
|
|
struct SubstitutablePathInfo
|
2020-08-03 21:02:28 +00:00
|
|
|
|
{
|
|
|
|
|
std::optional<StorePath> deriver;
|
2023-01-14 21:38:43 +00:00
|
|
|
|
StorePathSet references;
|
2020-08-03 21:02:28 +00:00
|
|
|
|
uint64_t downloadSize; /* 0 = unknown or inapplicable */
|
|
|
|
|
uint64_t narSize; /* 0 = unknown */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::map<StorePath, SubstitutablePathInfo> SubstitutablePathInfos;
|
|
|
|
|
|
2023-01-14 21:38:43 +00:00
|
|
|
|
|
2023-01-06 20:36:05 +00:00
|
|
|
|
struct ValidPathInfo
|
2020-06-24 21:22:13 +00:00
|
|
|
|
{
|
|
|
|
|
StorePath path;
|
|
|
|
|
std::optional<StorePath> deriver;
|
2020-08-05 18:42:48 +00:00
|
|
|
|
Hash narHash;
|
2023-01-14 21:38:43 +00:00
|
|
|
|
StorePathSet references;
|
2020-06-24 21:22:13 +00:00
|
|
|
|
time_t registrationTime = 0;
|
|
|
|
|
uint64_t narSize = 0; // 0 = unknown
|
|
|
|
|
uint64_t id; // internal use only
|
|
|
|
|
|
|
|
|
|
/* Whether the path is ultimately trusted, that is, it's a
|
|
|
|
|
derivation output that was built locally. */
|
|
|
|
|
bool ultimate = false;
|
|
|
|
|
|
|
|
|
|
StringSet sigs; // note: not necessarily verified
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
|
|
|
|
std::optional<ContentAddress> ca;
|
|
|
|
|
|
|
|
|
|
bool operator == (const ValidPathInfo & i) const
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
path == i.path
|
|
|
|
|
&& narHash == i.narHash
|
|
|
|
|
&& references == i.references;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
|
std::string fingerprint(const Store & store) const;
|
|
|
|
|
|
|
|
|
|
void sign(const Store & store, const SecretKey & secretKey);
|
|
|
|
|
|
2020-10-07 13:52:20 +00:00
|
|
|
|
std::optional<StorePathDescriptor> fullStorePathDescriptorOpt() const;
|
|
|
|
|
|
2020-06-24 21:22:13 +00:00
|
|
|
|
/* Return true iff the path is verifiably content-addressed. */
|
|
|
|
|
bool isContentAddressed(const Store & store) const;
|
|
|
|
|
|
|
|
|
|
static const size_t maxSigs = std::numeric_limits<size_t>::max();
|
|
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
|
size_t checkSignatures(const Store & store, const PublicKeys & publicKeys) const;
|
|
|
|
|
|
|
|
|
|
/* Verify a single signature. */
|
|
|
|
|
bool checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const;
|
|
|
|
|
|
|
|
|
|
Strings shortRefs() const;
|
|
|
|
|
|
|
|
|
|
ValidPathInfo(const ValidPathInfo & other) = default;
|
|
|
|
|
|
2020-08-06 18:31:48 +00:00
|
|
|
|
ValidPathInfo(StorePath && path, Hash narHash) : path(std::move(path)), narHash(narHash) { };
|
|
|
|
|
ValidPathInfo(const StorePath & path, Hash narHash) : path(path), narHash(narHash) { };
|
2020-06-24 21:22:13 +00:00
|
|
|
|
|
2020-10-07 13:52:20 +00:00
|
|
|
|
ValidPathInfo(const Store & store,
|
|
|
|
|
StorePathDescriptor && ca, Hash narHash);
|
|
|
|
|
|
2020-06-24 21:22:13 +00:00
|
|
|
|
virtual ~ValidPathInfo() { }
|
2021-07-26 11:31:09 +00:00
|
|
|
|
|
|
|
|
|
static ValidPathInfo read(Source & source, const Store & store, unsigned int format);
|
|
|
|
|
static ValidPathInfo read(Source & source, const Store & store, unsigned int format, StorePath && path);
|
|
|
|
|
|
|
|
|
|
void write(Sink & sink, const Store & store, unsigned int format, bool includePath = true) const;
|
2020-06-24 21:22:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-11-03 11:52:57 +00:00
|
|
|
|
typedef std::map<StorePath, ValidPathInfo> ValidPathInfos;
|
2020-06-24 22:46:27 +00:00
|
|
|
|
|
2020-06-24 21:22:13 +00:00
|
|
|
|
}
|