aboutsummaryrefslogtreecommitdiff
path: root/python/olm/__main__.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-01-06 17:40:39 +0000
committerRichard van der Hoff <richard@matrix.org>2017-01-09 17:45:46 +0000
commita2f0c93a93f6914291954b08a7518b4f17561c11 (patch)
treefc75bc7e84808868bc4b9eb3844115bab277ada2 /python/olm/__main__.py
parent5fbeb3e29b6440a799d9320e871a1d4d509130b8 (diff)
Implement importing group session data
olm_import_inbound_group_session, which reads the format written by olm_export_inbound_group_session to initialise a group session.
Diffstat (limited to 'python/olm/__main__.py')
-rwxr-xr-xpython/olm/__main__.py26
1 files changed, 26 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))