From 653790eacbf7dcf94cbf181657cdb0c30c890c3f Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 20 Oct 2016 09:58:55 +0100 Subject: Return the message index when decrypting group messages. Applications can use the index to detect replays of the same message. --- tests/test_group_session.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/test_group_session.cpp') diff --git a/tests/test_group_session.cpp b/tests/test_group_session.cpp index 9930927..b15875c 100644 --- a/tests/test_group_session.cpp +++ b/tests/test_group_session.cpp @@ -161,8 +161,9 @@ int main() { memcpy(msgcopy, msg, msglen); size = olm_group_decrypt_max_plaintext_length(inbound_session, msgcopy, msglen); uint8_t plaintext_buf[size]; + uint32_t message_index; res = olm_group_decrypt(inbound_session, msg, msglen, - plaintext_buf, size); + plaintext_buf, size, &message_index); assert_equals(plaintext_length, res); assert_equals(plaintext, plaintext_buf, res); } @@ -208,8 +209,9 @@ int main() { memcpy(msgcopy, message, msglen); uint8_t plaintext_buf[size]; + uint32_t message_index; res = olm_group_decrypt( - inbound_session, msgcopy, msglen, plaintext_buf, size + inbound_session, msgcopy, msglen, plaintext_buf, size, &message_index ); assert_equals(plaintext_length, res); assert_equals(plaintext, plaintext_buf, res); @@ -227,7 +229,7 @@ int main() { memcpy(msgcopy, message, msglen); res = olm_group_decrypt( inbound_session, msgcopy, msglen, - plaintext_buf, size + plaintext_buf, size, &message_index ); assert_equals((size_t)-1, res); assert_equals( -- cgit v1.2.3 From 9a8d2d15d97dc17d8f33b7d45b0fefc1267b57c4 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 20 Oct 2016 11:51:56 +0100 Subject: Check the message index in the tests --- tests/test_group_session.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_group_session.cpp') diff --git a/tests/test_group_session.cpp b/tests/test_group_session.cpp index b15875c..df46f0e 100644 --- a/tests/test_group_session.cpp +++ b/tests/test_group_session.cpp @@ -166,6 +166,7 @@ int main() { plaintext_buf, size, &message_index); assert_equals(plaintext_length, res); assert_equals(plaintext, plaintext_buf, res); + assert_equals(message_index, uint32_t(0)); } { @@ -213,6 +214,7 @@ int main() { res = olm_group_decrypt( inbound_session, msgcopy, msglen, plaintext_buf, size, &message_index ); + assert_equals(message_index, uint32_t(0)); assert_equals(plaintext_length, res); assert_equals(plaintext, plaintext_buf, res); -- cgit v1.2.3 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_group_session.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'tests/test_group_session.cpp') diff --git a/tests/test_group_session.cpp b/tests/test_group_session.cpp index df46f0e..ad67adb 100644 --- a/tests/test_group_session.cpp +++ b/tests/test_group_session.cpp @@ -28,23 +28,26 @@ int main() { size_t pickle_length = olm_pickle_outbound_group_session_length(session); uint8_t pickle1[pickle_length]; - olm_pickle_outbound_group_session(session, - "secret_key", 10, - pickle1, pickle_length); + size_t res = olm_pickle_outbound_group_session( + session, "secret_key", 10, pickle1, pickle_length + ); + assert_equals(pickle_length, res); + uint8_t pickle2[pickle_length]; memcpy(pickle2, pickle1, pickle_length); uint8_t buffer2[size]; OlmOutboundGroupSession *session2 = olm_outbound_group_session(buffer2); - size_t res = olm_unpickle_outbound_group_session(session2, - "secret_key", 10, - pickle2, pickle_length); + res = olm_unpickle_outbound_group_session( + session2, "secret_key", 10, pickle2, pickle_length + ); assert_not_equals((size_t)-1, res); assert_equals(pickle_length, olm_pickle_outbound_group_session_length(session2)); - olm_pickle_outbound_group_session(session2, - "secret_key", 10, - pickle2, pickle_length); + res = olm_pickle_outbound_group_session( + session2, "secret_key", 10, pickle2, pickle_length + ); + assert_equals(pickle_length, res); assert_equals(pickle1, pickle2, pickle_length); } @@ -59,23 +62,25 @@ int main() { size_t pickle_length = olm_pickle_inbound_group_session_length(session); uint8_t pickle1[pickle_length]; - olm_pickle_inbound_group_session(session, - "secret_key", 10, - pickle1, pickle_length); + size_t res = olm_pickle_inbound_group_session( + session, "secret_key", 10, pickle1, pickle_length + ); + assert_equals(pickle_length, res); + uint8_t pickle2[pickle_length]; memcpy(pickle2, pickle1, pickle_length); uint8_t buffer2[size]; OlmInboundGroupSession *session2 = olm_inbound_group_session(buffer2); - size_t res = olm_unpickle_inbound_group_session(session2, - "secret_key", 10, - pickle2, pickle_length); + res = olm_unpickle_inbound_group_session( + session2, "secret_key", 10, pickle2, pickle_length + ); assert_not_equals((size_t)-1, res); assert_equals(pickle_length, olm_pickle_inbound_group_session_length(session2)); - olm_pickle_inbound_group_session(session2, - "secret_key", 10, - pickle2, pickle_length); + res = olm_pickle_inbound_group_session( + session2, "secret_key", 10, pickle2, pickle_length + ); assert_equals(pickle1, pickle2, pickle_length); } -- cgit v1.2.3