зеркало из https://github.com/microsoft/CCF.git
Fix reported `TxID` term during public recovery (#2879)
This commit is contained in:
Родитель
3f88055b15
Коммит
eb82ab0117
|
@ -24,17 +24,21 @@ namespace crypto
|
|||
constexpr static size_t RAW_DATA_SIZE = sizeof(tag) + sizeof(iv);
|
||||
|
||||
GcmHeader() = default;
|
||||
GcmHeader(const std::vector<uint8_t>& data)
|
||||
GcmHeader(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (data.size() != RAW_DATA_SIZE)
|
||||
if (size != RAW_DATA_SIZE)
|
||||
{
|
||||
throw std::logic_error("Incompatible IV size");
|
||||
}
|
||||
|
||||
memcpy(tag, data.data(), sizeof(tag));
|
||||
memcpy(iv, data.data() + sizeof(tag), sizeof(iv));
|
||||
memcpy(tag, data, sizeof(tag));
|
||||
memcpy(iv, data + sizeof(tag), sizeof(iv));
|
||||
}
|
||||
|
||||
GcmHeader(const std::vector<uint8_t>& data) :
|
||||
GcmHeader(data.data(), data.size())
|
||||
{}
|
||||
|
||||
void set_iv_seq(uint64_t seq)
|
||||
{
|
||||
*reinterpret_cast<uint64_t*>(iv) = seq;
|
||||
|
|
|
@ -61,8 +61,8 @@ namespace kv
|
|||
|
||||
ApplyResult apply() override
|
||||
{
|
||||
kv::Version max_conflict_version;
|
||||
kv::Term view;
|
||||
kv::Version max_conflict_version = 0;
|
||||
kv::Term view = 0;
|
||||
if (!store->fill_maps(
|
||||
data,
|
||||
public_only,
|
||||
|
|
|
@ -40,6 +40,11 @@ namespace kv
|
|||
return S::RAW_DATA_SIZE;
|
||||
}
|
||||
|
||||
uint64_t get_term(const uint8_t* data, size_t size) override
|
||||
{
|
||||
return S(data, size).get_term();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt data and return serialised GCM header and cipher.
|
||||
*
|
||||
|
|
|
@ -282,7 +282,7 @@ namespace kv
|
|||
}
|
||||
|
||||
// If the kv store has no encryptor, assume that the serialised tx is
|
||||
// public only with no header
|
||||
// public only with no header (test only)
|
||||
if (!crypto_util)
|
||||
{
|
||||
public_reader.init(data_, size_);
|
||||
|
@ -303,6 +303,12 @@ namespace kv
|
|||
domain_restriction.has_value() &&
|
||||
domain_restriction.value() == SecurityDomain::PUBLIC)
|
||||
{
|
||||
// Retrieve term from GCM header, even if the domain restriction is set
|
||||
// to public and the decryption is skipped, so that the term for the
|
||||
// deserialised entry can be reported
|
||||
term =
|
||||
crypto_util->get_term(gcm_hdr_data, crypto_util->get_header_length());
|
||||
|
||||
return std::make_tuple(version, max_conflict_version);
|
||||
}
|
||||
|
||||
|
|
|
@ -521,6 +521,7 @@ namespace kv
|
|||
virtual void rollback(Version version) = 0;
|
||||
|
||||
virtual size_t get_header_length() = 0;
|
||||
virtual uint64_t get_term(const uint8_t* data, size_t size) = 0;
|
||||
};
|
||||
|
||||
using EncryptorPtr = std::shared_ptr<AbstractTxEncryptor>;
|
||||
|
|
|
@ -40,6 +40,11 @@ namespace kv
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint64_t get_term(const uint8_t* data, size_t size) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rollback(Version version) override {}
|
||||
};
|
||||
}
|
Загрузка…
Ссылка в новой задаче