From a7310c5821513d5c5b0609ec506dad1ae51603d3 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 24 Oct 2016 10:06:06 +0100 Subject: Return the base64-encoded length of pickles make olm_pickle_* return the lengths of the base64-encoded pickles, rather than the raw pickle. (From the application's POV, the format of the pickle is opaque: it doesn't even know that it is base64-encoded. So returning the length of the raw pickle is particularly unhelpful.) --- tests/test_olm.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests/test_olm.cpp') diff --git a/tests/test_olm.cpp b/tests/test_olm.cpp index af2c9f7..4619558 100644 --- a/tests/test_olm.cpp +++ b/tests/test_olm.cpp @@ -49,7 +49,9 @@ mock_random(ot_random, sizeof(ot_random)); std::size_t pickle_length = ::olm_pickle_account_length(account); std::uint8_t pickle1[pickle_length]; -::olm_pickle_account(account, "secret_key", 10, pickle1, pickle_length); +std::size_t res = ::olm_pickle_account(account, "secret_key", 10, pickle1, pickle_length); +assert_equals(pickle_length, res); + std::uint8_t pickle2[pickle_length]; std::memcpy(pickle2, pickle1, pickle_length); @@ -59,10 +61,10 @@ assert_not_equals(std::size_t(-1), ::olm_unpickle_account( account2, "secret_key", 10, pickle2, pickle_length )); assert_equals(pickle_length, ::olm_pickle_account_length(account2)); -::olm_pickle_account(account2, "secret_key", 10, pickle2, pickle_length); +res = ::olm_pickle_account(account2, "secret_key", 10, pickle2, pickle_length); +assert_equals(pickle_length, res); assert_equals(pickle1, pickle2, pickle_length); - } @@ -122,7 +124,9 @@ mock_random(random2, sizeof(random2)); std::size_t pickle_length = ::olm_pickle_session_length(session); std::uint8_t pickle1[pickle_length]; -::olm_pickle_session(session, "secret_key", 10, pickle1, pickle_length); +std::size_t res = ::olm_pickle_session(session, "secret_key", 10, pickle1, pickle_length); +assert_equals(pickle_length, res); + std::uint8_t pickle2[pickle_length]; std::memcpy(pickle2, pickle1, pickle_length); @@ -132,10 +136,10 @@ assert_not_equals(std::size_t(-1), ::olm_unpickle_session( session2, "secret_key", 10, pickle2, pickle_length )); assert_equals(pickle_length, ::olm_pickle_session_length(session2)); -::olm_pickle_session(session2, "secret_key", 10, pickle2, pickle_length); +res = ::olm_pickle_session(session2, "secret_key", 10, pickle2, pickle_length); +assert_equals(pickle_length, res); assert_equals(pickle1, pickle2, pickle_length); - } { /** Loopback test */ -- cgit v1.2.3 From 7e9f3bebb8390f975a76c0188ce4cb460fe6692e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 25 Oct 2016 14:42:10 +0100 Subject: Document the return values for olm_matches_inbound_session --- tests/test_olm.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'tests/test_olm.cpp') 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) -- cgit v1.2.3