CCF
Loading...
Searching...
No Matches
shares.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/service/map.h"
6
7#include <map>
8#include <optional>
9#include <vector>
10
11namespace ccf
12{
13 using EncryptedShare = std::vector<uint8_t>;
14 using EncryptedSharesMap = std::map<MemberId, EncryptedShare>;
15
17 {
18 // Latest ledger secret wrapped with the ledger secret wrapping key
19 std::vector<uint8_t> wrapped_latest_ledger_secret;
20
21 // Recovery shares encrypted with each active recovery member's public
22 // encryption key
24
25 // Version at which the previous ledger secret was written to the store
26 std::optional<ccf::kv::Version> previous_secret_stored_version =
27 std::nullopt;
28 };
29
32 RecoverySharesInfo, wrapped_latest_ledger_secret, encrypted_shares)
34 RecoverySharesInfo, previous_secret_stored_version)
35
37 {
38 // Past ledger secret encrypted with the latest ledger secret
39 std::vector<uint8_t> encrypted_data = {};
40
41 // Version at which the ledger secret is applicable from
42 ccf::kv::Version version = ccf::kv::NoVersion;
43
44 // Version at which the ledger secret _before_ this one was written to the
45 // store
46 std::optional<ccf::kv::Version> previous_secret_stored_version =
47 std::nullopt;
48
50
52 std::vector<uint8_t>&& encrypted_data_,
53 ccf::kv::Version version_,
54 std::optional<ccf::kv::Version> stored_version_) :
55 encrypted_data(std::move(encrypted_data_)),
56 version(version_),
57 previous_secret_stored_version(stored_version_)
58 {}
59
60 bool operator==(const PreviousLedgerSecretInfo& other) const
61 {
62 return encrypted_data == other.encrypted_data &&
63 version == other.version &&
64 previous_secret_stored_version == other.previous_secret_stored_version;
65 }
66
67 bool operator!=(const PreviousLedgerSecretInfo& other) const
68 {
69 return !(*this == other);
70 }
71 };
72
73 DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(PreviousLedgerSecretInfo)
75 PreviousLedgerSecretInfo, encrypted_data, version)
77 PreviousLedgerSecretInfo, previous_secret_stored_version)
78
80 {
81 // Previous ledger secret info, encrypted with the current ledger secret.
82 // Unset on service opening.
83 std::optional<PreviousLedgerSecretInfo> previous_ledger_secret =
84 std::nullopt;
85
86 // Version at which the _next_ ledger secret is applicable from
87 // Note: In most cases (e.g. re-key, member removal), this is unset and
88 // the version at which the next ledger secret is applicable from is
89 // derived from the local hook on recovery. In one case (i.e. after recovery
90 // of the public ledger), a new ledger secret is created to protect the
91 // integrity on the public-only transactions. However, the corresponding
92 // shares are only written at a later version, once the previous ledger
93 // secrets have been restored.
94 std::optional<ccf::kv::Version> next_version = std::nullopt;
95 };
96
97 // Note: Both fields are never empty at the same time
101 EncryptedLedgerSecretInfo, previous_ledger_secret, next_version)
102
103 // The following two tables are distinct because some operations trigger a
104 // re-share without requiring the ledger secrets to be updated (e.g. updating
105 // the recovery threshold), and vice versa (e.g. ledger rekey). For historical
106 // queries, when recovering ledger secrets from the ledger, the version at
107 // which the previous ledger secret was _written_ to the store must be known
108 // and can be deduced to the version at which the
109 // EncryptedPastLedgerSecret map was updated.
110
111 // This table is updated every time the member recovery shares are updated,
112 // e.g. when the recovery threshold is modified and when the ledger secret is
113 // updated
114 using RecoveryShares = ServiceValue<RecoverySharesInfo>;
115
116 // This table is updated every time the ledger secret is updated, e.g. at
117 // startup or on ledger rekey. It is not updated on a pure re-share.
119
120 namespace Tables
121 {
122 static constexpr auto SHARES = "public:ccf.internal.recovery_shares";
123 static constexpr auto ENCRYPTED_PAST_LEDGER_SECRET =
124 "public:ccf.internal.historical_encrypted_ledger_secret";
125 }
126}
Definition value.h:32
#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
uint64_t Version
Definition version.h:8
Definition app_interface.h:14
std::map< MemberId, EncryptedShare > EncryptedSharesMap
Definition shares.h:14
std::vector< uint8_t > EncryptedShare
Definition shares.h:13
STL namespace.
Definition shares.h:80
Definition shares.h:37
PreviousLedgerSecretInfo(std::vector< uint8_t > &&encrypted_data_, ccf::kv::Version version_, std::optional< ccf::kv::Version > stored_version_)
Definition shares.h:51
ccf::kv::Version version
Definition shares.h:42
std::optional< ccf::kv::Version > previous_secret_stored_version
Definition shares.h:46
bool operator==(const PreviousLedgerSecretInfo &other) const
Definition shares.h:60
std::vector< uint8_t > encrypted_data
Definition shares.h:39
bool operator!=(const PreviousLedgerSecretInfo &other) const
Definition shares.h:67
Definition shares.h:17
EncryptedSharesMap encrypted_shares
Definition shares.h:23
std::optional< ccf::kv::Version > previous_secret_stored_version
Definition shares.h:26
std::vector< uint8_t > wrapped_latest_ledger_secret
Definition shares.h:19