12#include <openssl/crypto.h>
16 static constexpr auto commit_secret_label_ =
"Commit Secret Label";
21 std::shared_ptr<ccf::crypto::KeyAesGcm>
key;
33 {commit_secret_label_,
34 commit_secret_label_ +
sizeof(commit_secret_label_)});
62 std::vector<uint8_t>&& raw_key_,
63 std::optional<ccf::kv::Version> previous_secret_stored_version_ =
66 key(
ccf::crypto::make_key_aes_gcm(
std::move(raw_key_))),
79 return std::make_shared<LedgerSecret>(
85 const std::vector<uint8_t>& encrypted_previous_secret_raw)
88 encrypted_ls.
deserialise(encrypted_previous_secret_raw);
89 std::vector<uint8_t> decrypted_ls_raw;
91 if (!ledger_secret->key->decrypt(
98 throw std::logic_error(
"Decryption of previous ledger secret failed");
101 return decrypted_ls_raw;
108 struct adl_serializer<
ccf::LedgerSecretPtr>
131 s = std::make_shared<ccf::LedgerSecret>(ls);
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:714
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:690
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:786
HashBytes hmac(MDType type, const std::vector< uint8_t > &key, const std::vector< uint8_t > &data)
Definition hmac.cpp:43
std::vector< uint8_t > HashBytes
Definition hash_bytes.h:10
EntropyPtr get_entropy()
Definition entropy.cpp:10
constexpr size_t GCM_DEFAULT_KEY_SIZE
Definition symmetric_key.h:12
Definition app_interface.h:14
LedgerSecretPtr make_ledger_secret()
Definition ledger_secret.h:77
std::shared_ptr< LedgerSecret > LedgerSecretPtr
Definition ledger_secret.h:75
std::vector< uint8_t > decrypt_previous_ledger_secret_raw(const LedgerSecretPtr &ledger_secret, const std::vector< uint8_t > &encrypted_previous_secret_raw)
Definition ledger_secret.h:83
Definition json_schema.h:15
Definition ledger_secret.h:106
Definition ledger_secret.h:19
LedgerSecret(const LedgerSecret &other)
Definition ledger_secret.h:55
LedgerSecret(std::vector< uint8_t > &&raw_key_, std::optional< ccf::kv::Version > previous_secret_stored_version_=std::nullopt)
Definition ledger_secret.h:61
std::optional< ccf::crypto::HashBytes > commit_secret
Definition ledger_secret.h:24
const ccf::crypto::HashBytes & get_commit_secret()
Definition ledger_secret.h:26
std::optional< ccf::kv::Version > previous_secret_stored_version
Definition ledger_secret.h:22
std::shared_ptr< ccf::crypto::KeyAesGcm > key
Definition ledger_secret.h:21
~LedgerSecret()
Definition ledger_secret.h:47
bool operator==(const LedgerSecret &other) const
Definition ledger_secret.h:39
std::vector< uint8_t > raw_key
Definition ledger_secret.h:20
Definition symmetric_key.h:57
void deserialise(const std::vector< uint8_t > &serial)
Definition symmetric_key.cpp:93
StandardGcmHeader hdr
Definition symmetric_key.h:58
std::vector< uint8_t > cipher
Definition symmetric_key.h:59
static void to_json(json &j, const ccf::LedgerSecretPtr &s)
Definition ledger_secret.h:110
static void from_json(const json &j, ccf::LedgerSecretPtr &s)
Definition ledger_secret.h:122