diff options
author | Richard van der Hoff <richard@matrix.org> | 2016-06-30 11:27:25 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2016-06-30 11:38:01 +0100 |
commit | 8dd3c182ee568b9121a336b106aaaceedd1cc470 (patch) | |
tree | 24560387e186d7235decfb251ce748401b585004 /src | |
parent | 757c422578b417f5184fa9e17a32587de676b9d1 (diff) |
Make space in the session pickle for chain index
Keeping track of the chain index is a useful thing to do, but is only required
if we've enabled diagnostics. Extend the session pickle format to make a space
for it, so that pickles can be transferred between the logging_enabled branch
and the master branch without loss of information.
Also add some tests for session pickling which explicitly check that we can
unpickle both formats of pickle.
Diffstat (limited to 'src')
-rw-r--r-- | src/ratchet.cpp | 18 | ||||
-rw-r--r-- | src/session.cpp | 22 |
2 files changed, 34 insertions, 6 deletions
diff --git a/src/ratchet.cpp b/src/ratchet.cpp index dd1d42c..671d260 100644 --- a/src/ratchet.cpp +++ b/src/ratchet.cpp @@ -363,6 +363,10 @@ std::size_t olm::pickle_length( length += olm::pickle_length(value.sender_chain); length += olm::pickle_length(value.receiver_chains); length += olm::pickle_length(value.skipped_message_keys); + + // the logging_enabled branch includes a 'chain_index' field + length += olm::pickle_length(std::uint32_t(0)); + return length; } @@ -374,18 +378,30 @@ std::uint8_t * olm::pickle( pos = pickle(pos, value.sender_chain); pos = pickle(pos, value.receiver_chains); pos = pickle(pos, value.skipped_message_keys); + + // the logging_enabled branch includes a 'chain_index' field; for us, it is + // empty. + pos = pickle(pos, std::uint32_t(0)); + return pos; } std::uint8_t const * olm::unpickle( std::uint8_t const * pos, std::uint8_t const * end, - olm::Ratchet & value + olm::Ratchet & value, + bool includes_chain_index ) { pos = unpickle(pos, end, value.root_key); pos = unpickle(pos, end, value.sender_chain); pos = unpickle(pos, end, value.receiver_chains); pos = unpickle(pos, end, value.skipped_message_keys); + + // pickle v2 includes a chain index; pickle v1 did not. + if (includes_chain_index) { + std::uint32_t dummy; + pos = unpickle(pos, end, dummy); + } return pos; } diff --git a/src/session.cpp b/src/session.cpp index c148c97..b76a6b8 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -396,7 +396,7 @@ std::size_t olm::Session::decrypt( } namespace { -static const std::uint32_t SESSION_PICKLE_VERSION = 1; +static const std::uint32_t SESSION_PICKLE_VERSION = 2; } std::size_t olm::pickle_length( @@ -433,14 +433,26 @@ std::uint8_t const * olm::unpickle( ) { uint32_t pickle_version; pos = olm::unpickle(pos, end, pickle_version); - if (pickle_version != SESSION_PICKLE_VERSION) { - value.last_error = OlmErrorCode::OLM_UNKNOWN_PICKLE_VERSION; - return end; + + bool includes_chain_index; + switch (pickle_version) { + case 1: + includes_chain_index = false; + break; + + case 2: + includes_chain_index = true; + break; + + default: + value.last_error = OlmErrorCode::OLM_UNKNOWN_PICKLE_VERSION; + return end; } + pos = olm::unpickle(pos, end, value.received_message); pos = olm::unpickle(pos, end, value.alice_identity_key); pos = olm::unpickle(pos, end, value.alice_base_key); pos = olm::unpickle(pos, end, value.bob_one_time_key); - pos = olm::unpickle(pos, end, value.ratchet); + pos = olm::unpickle(pos, end, value.ratchet, includes_chain_index); return pos; } |