diff options
Diffstat (limited to 'python/olm')
-rwxr-xr-x | python/olm/__main__.py | 26 | ||||
-rw-r--r-- | python/olm/inbound_group_session.py | 10 |
2 files changed, 36 insertions, 0 deletions
diff --git a/python/olm/__main__.py b/python/olm/__main__.py index f195591..5f78f76 100755 --- a/python/olm/__main__.py +++ b/python/olm/__main__.py @@ -268,6 +268,19 @@ def build_arg_parser(): default=sys.stdin) inbound_group.set_defaults(func=do_inbound_group) + import_inbound_group = commands.add_parser( + "import_inbound_group", + help="Create an inbound group session based an exported inbound group" + ) + import_inbound_group.add_argument("session_file", help="Local inbound group session file") + import_inbound_group.add_argument( + "export_file", + help="File to read credentials from (default stdin)", + type=argparse.FileType('r'), nargs='?', + default=sys.stdin, + ) + import_inbound_group.set_defaults(func=do_import_inbound_group) + group_decrypt = commands.add_parser("group_decrypt", help="Decrypt a group message") group_decrypt.add_argument("session_file", help="Local inbound group session file") group_decrypt.add_argument("message_file", help="Message file (default stdin)", @@ -345,6 +358,19 @@ def do_inbound_group(args): with open(args.session_file, "wb") as f: f.write(session.pickle(args.key)) +def do_import_inbound_group(args): + if os.path.exists(args.session_file): + sys.stderr.write("Session %r file already exists\n" % ( + args.session_file, + )) + sys.exit(1) + data = args.export_file.read().translate(None, "\r\n") + + session = InboundGroupSession() + session.import_session(data) + with open(args.session_file, "wb") as f: + f.write(session.pickle(args.key)) + def do_group_decrypt(args): session = InboundGroupSession() session.unpickle(args.key, read_base64_file(args.session_file)) diff --git a/python/olm/inbound_group_session.py b/python/olm/inbound_group_session.py index 67906b2..4390b34 100644 --- a/python/olm/inbound_group_session.py +++ b/python/olm/inbound_group_session.py @@ -37,6 +37,10 @@ inbound_group_session_function( ) inbound_group_session_function( + lib.olm_import_inbound_group_session, c_void_p, c_size_t +) + +inbound_group_session_function( lib.olm_group_decrypt_max_plaintext_length, c_void_p, c_size_t ) inbound_group_session_function( @@ -83,6 +87,12 @@ class InboundGroupSession(object): self.ptr, key_buffer, len(session_key) ) + def import_session(self, session_key): + key_buffer = create_string_buffer(session_key) + lib.olm_import_inbound_group_session( + self.ptr, key_buffer, len(session_key) + ) + def decrypt(self, message): message_buffer = create_string_buffer(message) max_plaintext_length = lib.olm_group_decrypt_max_plaintext_length( |