From 9848f8445292ad3f7ff92bd4abfeb8f2d08ec32d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 26 Apr 2016 11:44:32 +0100 Subject: Add some logging to help understand what's going on --- include/olm/crypto.hh | 2 ++ include/olm/logging.hh | 1 + include/olm/memory.hh | 24 +++++++++++++++++++++++- include/olm/ratchet.hh | 13 +++++++++++-- 4 files changed, 37 insertions(+), 3 deletions(-) (limited to 'include/olm') diff --git a/include/olm/crypto.hh b/include/olm/crypto.hh index 7a05f8d..159bac7 100644 --- a/include/olm/crypto.hh +++ b/include/olm/crypto.hh @@ -17,6 +17,7 @@ #include #include +#include namespace olm { @@ -26,6 +27,7 @@ static const std::size_t IV_LENGTH = 16; struct Curve25519PublicKey { std::uint8_t public_key[KEY_LENGTH]; + std::string to_string() const; }; diff --git a/include/olm/logging.hh b/include/olm/logging.hh index 76c8053..f174712 100644 --- a/include/olm/logging.hh +++ b/include/olm/logging.hh @@ -23,6 +23,7 @@ const unsigned int LOG_ERROR = 2; const unsigned int LOG_WARNING = 3; const unsigned int LOG_INFO = 4; const unsigned int LOG_DEBUG = 5; +const unsigned int LOG_TRACE = 6; void set_log_level(unsigned int log_level); diff --git a/include/olm/memory.hh b/include/olm/memory.hh index 128990a..89afd99 100644 --- a/include/olm/memory.hh +++ b/include/olm/memory.hh @@ -1,4 +1,4 @@ -/* Copyright 2015 OpenMarket Ltd +/* Copyright 2015, 2016 OpenMarket Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include #include namespace olm { @@ -84,4 +87,23 @@ std::uint8_t * store_array( return destination + sizeof(T); } +/** convert an array of bytes to a string representation */ +template +std::string bytes_to_string(T start, T end) { + std::ostringstream ss; + ss << std::hex << std::setfill('0'); + while (start != end) { + ss << std::setw(2) << static_cast(*start++); + if (start != end) { + ss << ":"; + } + } + return ss.str(); +} + +template +std::string bytes_to_string(T start, size_t len) { + return bytes_to_string(start, start+len); +} + } // namespace olm diff --git a/include/olm/ratchet.hh b/include/olm/ratchet.hh index 2393e5b..071e349 100644 --- a/include/olm/ratchet.hh +++ b/include/olm/ratchet.hh @@ -29,7 +29,6 @@ struct ChainKey { SharedKey key; }; - struct MessageKey { std::uint32_t index; SharedKey key; @@ -82,8 +81,18 @@ struct Ratchet { /** The last error that happened encrypting or decrypting a message. */ ErrorCode last_error; + /** + * A count of the number of times the root key has been advanced; this is + * maintained purely for diagnostics. + * + * If sender_chain is empty, this will be the index of the current receiver + * chain (odd for Alice, even for Bob); otherwise, the index of the current + * sender chain (even for Alice, odd for Bob). + */ + std::uint32_t chain_index; + /** The root key is used to generate chain keys from the ephemeral keys. - * A new root_key derived each time a chain key is derived. */ + * A new root_key derived each time a new chain is started. */ SharedKey root_key; /** The sender chain is used to send messages. Each time a new ephemeral -- cgit v1.2.3