aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rwxr-xr-xpython/olm/__main__.py35
-rwxr-xr-xpython/test_olm.sh6
2 files changed, 39 insertions, 2 deletions
diff --git a/python/olm/__main__.py b/python/olm/__main__.py
index 3fcf24d..a34d52a 100755
--- a/python/olm/__main__.py
+++ b/python/olm/__main__.py
@@ -1,5 +1,7 @@
#! /usr/bin/env python
+from __future__ import print_function
+
import argparse
import json
import os
@@ -51,6 +53,39 @@ def build_arg_parser():
keys.set_defaults(func=do_keys)
+ def do_id_key(args):
+ account = Account()
+ with open(args.account_file, "rb") as f:
+ account.unpickle(args.key, f.read())
+ print(account.identity_keys()['curve25519'])
+
+ id_key = commands.add_parser("identity_key", help="Get the identity key for an account")
+ id_key.add_argument("account_file", help="Local account file")
+ id_key.set_defaults(func=do_id_key)
+
+ def do_one_time_key(args):
+ account = Account()
+ with open(args.account_file, "rb") as f:
+ account.unpickle(args.key, f.read())
+ keys = account.one_time_keys()['curve25519'].values()
+ key_num = args.key_num
+ if key_num < 1 or key_num > len(keys):
+ print(
+ "Invalid key number %i: %i keys available" %
+ (key_num, len(keys)),
+ file=sys.stderr
+ )
+ sys.exit(1)
+ print (keys[key_num-1])
+
+ one_time_key = commands.add_parser("one_time_key",
+ help="Get a one-time key for the account")
+ one_time_key.add_argument("account_file", help="Local account file")
+ one_time_key.add_argument("--key-num", "-n", type=int, default=1,
+ help="Index of key to retrieve (default: 1)")
+ one_time_key.set_defaults(func=do_one_time_key)
+
+
sign = commands.add_parser("sign", help="Sign a message")
sign.add_argument("account_file", help="Local account file")
sign.add_argument("message_file", help="Message to sign")
diff --git a/python/test_olm.sh b/python/test_olm.sh
index da69581..989e166 100755
--- a/python/test_olm.sh
+++ b/python/test_olm.sh
@@ -1,5 +1,7 @@
#! /bin/bash
+cd `dirname $0`
+
OLM="python -m olm"
ALICE_ACCOUNT=alice.account
@@ -17,8 +19,8 @@ $OLM create_account $ALICE_ACCOUNT
$OLM create_account $BOB_ACCOUNT
$OLM generate_keys $BOB_ACCOUNT 1
-BOB_IDENTITY_KEY="$($OLM keys --json $BOB_ACCOUNT | jq -r .account_keys.curve25519)"
-BOB_ONE_TIME_KEY="$($OLM keys --json $BOB_ACCOUNT | jq -r '.one_time_keys.curve25519|to_entries[0].value')"
+BOB_IDENTITY_KEY="$($OLM identity_key $BOB_ACCOUNT)"
+BOB_ONE_TIME_KEY="$($OLM one_time_key $BOB_ACCOUNT)"
$OLM outbound $ALICE_ACCOUNT $ALICE_SESSION "$BOB_IDENTITY_KEY" "$BOB_ONE_TIME_KEY"