diff options
author | Mark Haines <mjark@negativecurvature.net> | 2016-10-25 14:42:10 +0100 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2016-10-25 14:42:10 +0100 |
commit | 7e9f3bebb8390f975a76c0188ce4cb460fe6692e (patch) | |
tree | 6f9946318828921f3dbd1344e0d2672e417af97c | |
parent | 64130c1f8b0a2dd09379ac02544897ad5a2bfb75 (diff) |
Document the return values for olm_matches_inbound_session
-rw-r--r-- | include/olm/olm.h | 6 | ||||
-rw-r--r-- | tests/test_olm.cpp | 32 |
2 files changed, 34 insertions, 4 deletions
diff --git a/include/olm/olm.h b/include/olm/olm.h index 3257e53..5764eb2 100644 --- a/include/olm/olm.h +++ b/include/olm/olm.h @@ -320,7 +320,8 @@ int olm_session_has_received_message( /** Checks if the PRE_KEY message is for this in-bound session. This can happen * if multiple messages are sent to this account before this account sends a - * message in reply. Returns olm_error() on failure. If the base64 + * message in reply. Returns 1 if the session matches. Returns 0 if the session + * does not match. Returns olm_error() on failure. If the base64 * couldn't be decoded then olm_session_last_error will be "INVALID_BASE64". * If the message was for an unsupported protocol version then * olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message @@ -333,7 +334,8 @@ size_t olm_matches_inbound_session( /** Checks if the PRE_KEY message is for this in-bound session. This can happen * if multiple messages are sent to this account before this account sends a - * message in reply. Returns olm_error() on failure. If the base64 + * message in reply. Returns 1 if the session matches. Returns 0 if the session + * does not match. Returns olm_error() on failure. If the base64 * couldn't be decoded then olm_session_last_error will be "INVALID_BASE64". * If the message was for an unsupported protocol version then * olm_session_last_error() will be "BAD_MESSAGE_VERSION". If the message diff --git a/tests/test_olm.cpp b/tests/test_olm.cpp index 4619558..b24cd90 100644 --- a/tests/test_olm.cpp +++ b/tests/test_olm.cpp @@ -165,6 +165,9 @@ std::uint8_t o_random[::olm_account_generate_one_time_keys_random_length( mock_random_b(o_random, sizeof(o_random)); ::olm_account_generate_one_time_keys(b_account, 42, o_random, sizeof(o_random)); +std::uint8_t a_id_keys[::olm_account_identity_keys_length(a_account)]; +::olm_account_identity_keys(a_account, a_id_keys, sizeof(a_id_keys)); + std::uint8_t b_id_keys[::olm_account_identity_keys_length(b_account)]; std::uint8_t b_ot_keys[::olm_account_one_time_keys_length(b_account)]; ::olm_account_identity_keys(b_account, b_id_keys, sizeof(b_id_keys)); @@ -176,8 +179,8 @@ std::uint8_t a_rand[::olm_create_outbound_session_random_length(a_session)]; mock_random_a(a_rand, sizeof(a_rand)); assert_not_equals(std::size_t(-1), ::olm_create_outbound_session( a_session, a_account, - b_id_keys + 15, 43, - b_ot_keys + 25, 43, + b_id_keys + 15, 43, // B's curve25519 identity key + b_ot_keys + 25, 43, // B's curve25519 one time key a_rand, sizeof(a_rand) )); @@ -202,6 +205,31 @@ std::uint8_t b_session_buffer[::olm_account_size()]; b_session, b_account, tmp_message_1, sizeof(message_1) ); +// Check that the inbound session matches the message it was created from. +std::memcpy(tmp_message_1, message_1, sizeof(message_1)); +assert_equals(std::size_t(1), ::olm_matches_inbound_session( + b_session, + tmp_message_1, sizeof(message_1) +)); + +// Check that the inbound session matches the key this message is supposed +// to be from. +std::memcpy(tmp_message_1, message_1, sizeof(message_1)); +assert_equals(std::size_t(1), ::olm_matches_inbound_session_from( + b_session, + a_id_keys + 15, 43, // A's curve125519 identity key. + tmp_message_1, sizeof(message_1) +)); + +// Check that the inbound session isn't from a different user. +std::memcpy(tmp_message_1, message_1, sizeof(message_1)); +assert_equals(std::size_t(0), ::olm_matches_inbound_session_from( + b_session, + b_id_keys + 15, 43, // B's curve25519 identity key. + tmp_message_1, sizeof(message_1) +)); + +// Check that we can decrypt the message. std::memcpy(tmp_message_1, message_1, sizeof(message_1)); std::uint8_t plaintext_1[::olm_decrypt_max_plaintext_length( b_session, 0, tmp_message_1, sizeof(message_1) |