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. --- python/olm/__main__.py | 2 +- python/olm/inbound_group_session.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/olm/__main__.py b/python/olm/__main__.py index cf9158d..eb76301 100755 --- a/python/olm/__main__.py +++ b/python/olm/__main__.py @@ -328,7 +328,7 @@ def do_group_decrypt(args): session = InboundGroupSession() session.unpickle(args.key, read_base64_file(args.session_file)) message = args.message_file.read() - plaintext = session.decrypt(message) + plaintext, message_index = session.decrypt(message) with open(args.session_file, "wb") as f: f.write(session.pickle(args.key)) args.plaintext_file.write(plaintext) diff --git a/python/olm/inbound_group_session.py b/python/olm/inbound_group_session.py index d5547fd..27a569c 100644 --- a/python/olm/inbound_group_session.py +++ b/python/olm/inbound_group_session.py @@ -43,6 +43,7 @@ inbound_group_session_function( lib.olm_group_decrypt, c_void_p, c_size_t, # message c_void_p, c_size_t, # plaintext + POINTER(c_uint32), # message_index ) inbound_group_session_function(lib.olm_inbound_group_session_id_length) @@ -82,11 +83,14 @@ class InboundGroupSession(object): ) plaintext_buffer = create_string_buffer(max_plaintext_length) message_buffer = create_string_buffer(message) + + message_index = c_uint32() plaintext_length = lib.olm_group_decrypt( self.ptr, message_buffer, len(message), - plaintext_buffer, max_plaintext_length + plaintext_buffer, max_plaintext_length, + byref(message_index) ) - return plaintext_buffer.raw[:plaintext_length] + return plaintext_buffer.raw[:plaintext_length], message_index def session_id(self): id_length = lib.olm_inbound_group_session_id_length(self.ptr) -- cgit v1.2.3