12#include <openssl/crypto.h>
21 static constexpr uint8_t commit_secret_label_[] = {
22 'C',
'o',
'm',
'm',
'i',
't',
' ',
'S'};
23 static std::span<const uint8_t> commit_secret_label{
24 commit_secret_label_,
sizeof(commit_secret_label_)};
28 std::shared_ptr<ccf::crypto::KeyAesGcm>
key;
66 std::vector<uint8_t>&& raw_key_,
67 std::optional<ccf::kv::Version> previous_secret_stored_version_ =
70 key(
ccf::crypto::make_key_aes_gcm(
std::move(raw_key_))),
83 return std::make_shared<LedgerSecret>(
89 const std::vector<uint8_t>& encrypted_previous_secret_raw)
92 encrypted_ls.
deserialise(encrypted_previous_secret_raw);
93 std::vector<uint8_t> decrypted_ls_raw;
95 if (!ledger_secret->key->decrypt(
102 throw std::logic_error(
"Decryption of previous ledger secret failed");
105 return decrypted_ls_raw;
112 struct adl_serializer<
ccf::LedgerSecretPtr>
116 if (s.get() !=
nullptr)
135 s = std::make_shared<ccf::LedgerSecret>(ls);
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:718
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:694
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:790
HashBytes hmac(MDType type, const std::span< const uint8_t > &key, const std::span< const 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:81
std::shared_ptr< LedgerSecret > LedgerSecretPtr
Definition ledger_secret.h:79
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:87
Definition json_schema.h:15
Definition ledger_secret.h:110
Definition ledger_secret.h:26
LedgerSecret(const LedgerSecret &other)
Definition ledger_secret.h:59
LedgerSecret(std::vector< uint8_t > &&raw_key_, std::optional< ccf::kv::Version > previous_secret_stored_version_=std::nullopt)
Definition ledger_secret.h:65
std::optional< ccf::crypto::HashBytes > commit_secret
Definition ledger_secret.h:31
const ccf::crypto::HashBytes & get_commit_secret()
Definition ledger_secret.h:33
std::optional< ccf::kv::Version > previous_secret_stored_version
Definition ledger_secret.h:29
std::shared_ptr< ccf::crypto::KeyAesGcm > key
Definition ledger_secret.h:28
~LedgerSecret()
Definition ledger_secret.h:51
bool operator==(const LedgerSecret &other) const
Definition ledger_secret.h:43
std::vector< uint8_t > raw_key
Definition ledger_secret.h:27
Definition symmetric_key.h:58
void deserialise(const std::vector< uint8_t > &serial)
Definition symmetric_key.cpp:93
StandardGcmHeader hdr
Definition symmetric_key.h:59
std::vector< uint8_t > cipher
Definition symmetric_key.h:60
static void to_json(json &j, const ccf::LedgerSecretPtr &s)
Definition ledger_secret.h:114
static void from_json(const json &j, ccf::LedgerSecretPtr &s)
Definition ledger_secret.h:126