Merge branch 'master'
Merge master into patched branch to fix conflicts prior to merge back to master
This commit is contained in:
commit
853ea8fbc7
7 changed files with 389 additions and 72 deletions
225
python/.gdb_history
Normal file
225
python/.gdb_history
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
b _olm_enc_input
|
||||||
|
r
|
||||||
|
l
|
||||||
|
p key
|
||||||
|
p key_lenght
|
||||||
|
p key_length
|
||||||
|
b _olm_enc_input
|
||||||
|
r
|
||||||
|
key[12]
|
||||||
|
p key[12]
|
||||||
|
p key[11]
|
||||||
|
key[11]='\0'
|
||||||
|
p key[11]='\0'
|
||||||
|
p key[11]
|
||||||
|
key_length=12
|
||||||
|
p key_length=12
|
||||||
|
n
|
||||||
|
c
|
||||||
|
b _olm_enc_input
|
||||||
|
r
|
||||||
|
r
|
||||||
|
r
|
||||||
|
b olm_decrypt
|
||||||
|
r
|
||||||
|
l
|
||||||
|
b 677
|
||||||
|
c
|
||||||
|
s
|
||||||
|
fin
|
||||||
|
s
|
||||||
|
s
|
||||||
|
fin
|
||||||
|
s
|
||||||
|
s
|
||||||
|
fin
|
||||||
|
s
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
l
|
||||||
|
s
|
||||||
|
s
|
||||||
|
n
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
p reader
|
||||||
|
p *this
|
||||||
|
n
|
||||||
|
p chain
|
||||||
|
p receiver_chains
|
||||||
|
p receiver_chains.length()
|
||||||
|
p receiver_chains.size()
|
||||||
|
p reader
|
||||||
|
p reader.ratchet_key
|
||||||
|
r
|
||||||
|
r
|
||||||
|
b olm_account_one_time_keys
|
||||||
|
r
|
||||||
|
l
|
||||||
|
s
|
||||||
|
n
|
||||||
|
p *this
|
||||||
|
p one_time_keys
|
||||||
|
p one_time_keys.length
|
||||||
|
p one_time_keys.length()
|
||||||
|
p one_time_keys.len()
|
||||||
|
p one_time_keys.size()
|
||||||
|
p one_time_keys.count()
|
||||||
|
p one_time_keys.data
|
||||||
|
p one_time_keys._data
|
||||||
|
p &one_time_keys._data
|
||||||
|
l
|
||||||
|
n
|
||||||
|
q
|
||||||
|
r
|
||||||
|
b olm_create_inbound_session
|
||||||
|
r
|
||||||
|
b olm_create_inbound_session_from
|
||||||
|
r
|
||||||
|
r
|
||||||
|
r
|
||||||
|
b olm_create_inbound_session_from
|
||||||
|
r
|
||||||
|
b olm_create_inbound_session
|
||||||
|
b olm_create_inbound_session
|
||||||
|
r
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
s
|
||||||
|
b olm_create_inbound_session
|
||||||
|
r
|
||||||
|
l
|
||||||
|
l
|
||||||
|
n
|
||||||
|
s
|
||||||
|
f
|
||||||
|
s
|
||||||
|
fin
|
||||||
|
s
|
||||||
|
s
|
||||||
|
fin
|
||||||
|
s
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
l -
|
||||||
|
l
|
||||||
|
l
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p our_one_time_key
|
||||||
|
p *our_one_time_key
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p bob_one_time_key
|
||||||
|
p alice_identity_key
|
||||||
|
p alice_base_key
|
||||||
|
p bob_identity_key
|
||||||
|
x alice_identity_key
|
||||||
|
x &alice_identity_key
|
||||||
|
x /32x &alice_identity_key
|
||||||
|
x /32b &alice_identity_key
|
||||||
|
l
|
||||||
|
l
|
||||||
|
l
|
||||||
|
n
|
||||||
|
b olm_decrypt
|
||||||
|
c
|
||||||
|
l
|
||||||
|
l
|
||||||
|
b 'olm::Session::decrypt'
|
||||||
|
c
|
||||||
|
l
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p reader
|
||||||
|
p reader
|
||||||
|
5*128
|
||||||
|
p 5*128
|
||||||
|
p 0xb0 - 0x80
|
||||||
|
p 0xb0 - 0x80 + 640
|
||||||
|
l
|
||||||
|
n
|
||||||
|
s
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p reader
|
||||||
|
n
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p max_length
|
||||||
|
p reader.ciphertext_length
|
||||||
|
l
|
||||||
|
n
|
||||||
|
l
|
||||||
|
p receiver_chains
|
||||||
|
p &receiver_chains ._data
|
||||||
|
p &receiver_chains ._data[1]
|
||||||
|
n
|
||||||
|
s
|
||||||
|
s
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p new_chain.index
|
||||||
|
p reader.counter
|
||||||
|
n
|
||||||
|
l
|
||||||
|
l
|
||||||
|
n
|
||||||
|
s
|
||||||
|
s
|
||||||
|
n
|
||||||
|
l
|
||||||
|
x key
|
||||||
|
x /16b key
|
||||||
|
l
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p keys
|
||||||
|
_olm_crypto_aes_decrypt_cbc&keys.aes_key, &keys.aes_iv, ciphertext, ciphertext_length, plaintext
|
||||||
|
p _olm_crypto_aes_decrypt_cbc(&keys.aes_key, &keys.aes_iv, ciphertext, ciphertext_length, plaintext)
|
||||||
|
p plaintext
|
||||||
|
r
|
||||||
|
b olm_account_identity_keys
|
||||||
|
l
|
||||||
|
r
|
||||||
|
b olm_unpickle_account
|
||||||
|
r
|
||||||
|
l
|
||||||
|
n
|
||||||
|
p object.last_error
|
||||||
|
l
|
||||||
|
l -
|
||||||
|
l
|
||||||
|
b 268
|
||||||
|
r
|
||||||
|
c
|
||||||
|
s
|
||||||
|
l
|
||||||
|
l
|
||||||
|
p end-pos
|
||||||
|
x /246b pos
|
||||||
|
x /246x pos
|
||||||
|
x /82x pos+164
|
||||||
|
x /82x pos+132
|
||||||
|
pos
|
||||||
|
p pos
|
||||||
|
x /246x pos
|
||||||
|
r
|
||||||
|
r
|
||||||
|
b olm_create_outbound_session
|
||||||
|
r
|
||||||
|
n
|
||||||
|
l
|
||||||
|
p id_key_length
|
||||||
|
p ot_key_length
|
||||||
|
p olm::decode_base64_length(id_key_length)
|
||||||
|
p olm::decode_base64_length(ot_key_length)
|
||||||
|
p CURVE25519_KEY_LENGTH
|
|
@ -1,4 +1,4 @@
|
||||||
#! /usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ def build_arg_parser():
|
||||||
parser.add_argument("--key", help="Account encryption key", default="")
|
parser.add_argument("--key", help="Account encryption key", default="")
|
||||||
commands = parser.add_subparsers()
|
commands = parser.add_subparsers()
|
||||||
|
|
||||||
create_account = commands.add_parser("create_account", help="Create a new account")
|
create_account = commands.add_parser("create_account",
|
||||||
|
help="Create a new account")
|
||||||
create_account.add_argument("account_file", help="Local account file")
|
create_account.add_argument("account_file", help="Local account file")
|
||||||
|
|
||||||
def do_create_account(args):
|
def do_create_account(args):
|
||||||
|
@ -64,7 +65,8 @@ def build_arg_parser():
|
||||||
account.unpickle(args.key, read_base64_file(args.account_file))
|
account.unpickle(args.key, read_base64_file(args.account_file))
|
||||||
print(account.identity_keys()['curve25519'])
|
print(account.identity_keys()['curve25519'])
|
||||||
|
|
||||||
id_key = commands.add_parser("identity_key", help="Get the identity key for an account")
|
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.add_argument("account_file", help="Local account file")
|
||||||
id_key.set_defaults(func=do_id_key)
|
id_key.set_defaults(func=do_id_key)
|
||||||
|
|
||||||
|
@ -75,21 +77,22 @@ def build_arg_parser():
|
||||||
key_num = args.key_num
|
key_num = args.key_num
|
||||||
if key_num < 1 or key_num > len(keys):
|
if key_num < 1 or key_num > len(keys):
|
||||||
print(
|
print(
|
||||||
"Invalid key number %i: %i keys available" %
|
"Invalid key number %i: %i keys available" % (
|
||||||
(key_num, len(keys)),
|
key_num, len(keys),
|
||||||
file=sys.stderr
|
), file=sys.stderr,
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
print (keys[key_num-1])
|
print(keys[key_num-1])
|
||||||
|
|
||||||
one_time_key = commands.add_parser("one_time_key",
|
one_time_key = commands.add_parser(
|
||||||
help="Get a one-time key for the account")
|
"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("account_file", help="Local account file")
|
||||||
one_time_key.add_argument("--key-num", "-n", type=int, default=1,
|
one_time_key.add_argument("--key-num", "-n", type=int, default=1,
|
||||||
help="Index of key to retrieve (default: 1)")
|
help="Index of key to retrieve (default: 1)")
|
||||||
one_time_key.set_defaults(func=do_one_time_key)
|
one_time_key.set_defaults(func=do_one_time_key)
|
||||||
|
|
||||||
|
|
||||||
sign = commands.add_parser("sign", help="Sign a message")
|
sign = commands.add_parser("sign", help="Sign a message")
|
||||||
sign.add_argument("account_file", help="Local account file")
|
sign.add_argument("account_file", help="Local account file")
|
||||||
sign.add_argument("message_file", help="Message to sign")
|
sign.add_argument("message_file", help="Message to sign")
|
||||||
|
@ -99,17 +102,18 @@ def build_arg_parser():
|
||||||
account = Account()
|
account = Account()
|
||||||
account.unpickle(args.key, read_base64_file(args.account_file))
|
account.unpickle(args.key, read_base64_file(args.account_file))
|
||||||
with open_in(args.message_file) as f:
|
with open_in(args.message_file) as f:
|
||||||
message = f.read()
|
message = f.read()
|
||||||
signature = account.sign(message)
|
signature = account.sign(message)
|
||||||
with open_out(args.signature_file) as f:
|
with open_out(args.signature_file) as f:
|
||||||
f.write(signature)
|
f.write(signature)
|
||||||
|
|
||||||
sign.set_defaults(func=do_sign)
|
sign.set_defaults(func=do_sign)
|
||||||
|
|
||||||
|
generate_keys = commands.add_parser("generate_keys",
|
||||||
generate_keys = commands.add_parser("generate_keys", help="Generate one time keys")
|
help="Generate one time keys")
|
||||||
generate_keys.add_argument("account_file", help="Local account file")
|
generate_keys.add_argument("account_file", help="Local account file")
|
||||||
generate_keys.add_argument("count", type=int, help="Number of keys to generate")
|
generate_keys.add_argument("count", type=int,
|
||||||
|
help="Number of keys to generate")
|
||||||
|
|
||||||
def do_generate_keys(args):
|
def do_generate_keys(args):
|
||||||
account = Account()
|
account = Account()
|
||||||
|
@ -120,8 +124,8 @@ def build_arg_parser():
|
||||||
|
|
||||||
generate_keys.set_defaults(func=do_generate_keys)
|
generate_keys.set_defaults(func=do_generate_keys)
|
||||||
|
|
||||||
|
outbound = commands.add_parser("outbound",
|
||||||
outbound = commands.add_parser("outbound", help="Create an outbound session")
|
help="Create an outbound session")
|
||||||
outbound.add_argument("account_file", help="Local account file")
|
outbound.add_argument("account_file", help="Local account file")
|
||||||
outbound.add_argument("session_file", help="Local session file")
|
outbound.add_argument("session_file", help="Local session file")
|
||||||
outbound.add_argument("identity_key", help="Remote identity key")
|
outbound.add_argument("identity_key", help="Remote identity key")
|
||||||
|
@ -238,43 +242,66 @@ def build_arg_parser():
|
||||||
|
|
||||||
decrypt.set_defaults(func=do_decrypt)
|
decrypt.set_defaults(func=do_decrypt)
|
||||||
|
|
||||||
outbound_group = commands.add_parser("outbound_group", help="Create an outbound group session")
|
outbound_group = commands.add_parser(
|
||||||
outbound_group.add_argument("session_file", help="Local group session file")
|
"outbound_group",
|
||||||
|
help="Create an outbound group session",
|
||||||
|
)
|
||||||
|
outbound_group.add_argument("session_file",
|
||||||
|
help="Local group session file")
|
||||||
outbound_group.set_defaults(func=do_outbound_group)
|
outbound_group.set_defaults(func=do_outbound_group)
|
||||||
|
|
||||||
group_credentials = commands.add_parser("group_credentials", help="Export the current outbound group session credentials")
|
group_credentials = commands.add_parser(
|
||||||
group_credentials.add_argument("session_file", help="Local outbound group session file")
|
"group_credentials",
|
||||||
group_credentials.add_argument("credentials_file", help="File to write credentials to (default stdout)",
|
help="Export the current outbound group session credentials",
|
||||||
type=argparse.FileType('w'), nargs='?',
|
)
|
||||||
default=sys.stdout)
|
group_credentials.add_argument(
|
||||||
|
"session_file",
|
||||||
|
help="Local outbound group session file",
|
||||||
|
)
|
||||||
|
group_credentials.add_argument(
|
||||||
|
"credentials_file",
|
||||||
|
help="File to write credentials to (default stdout)",
|
||||||
|
type=argparse.FileType('w'), nargs='?',
|
||||||
|
default=sys.stdout,
|
||||||
|
)
|
||||||
group_credentials.set_defaults(func=do_group_credentials)
|
group_credentials.set_defaults(func=do_group_credentials)
|
||||||
|
|
||||||
group_encrypt = commands.add_parser("group_encrypt", help="Encrypt a group message")
|
group_encrypt = commands.add_parser(
|
||||||
group_encrypt.add_argument("session_file", help="Local outbound group session file")
|
"group_encrypt",
|
||||||
group_encrypt.add_argument("plaintext_file", help="Plaintext file (default stdin)",
|
help="Encrypt a group message",
|
||||||
|
)
|
||||||
|
group_encrypt.add_argument("session_file",
|
||||||
|
help="Local outbound group session file")
|
||||||
|
group_encrypt.add_argument("plaintext_file",
|
||||||
|
help="Plaintext file (default stdin)",
|
||||||
type=argparse.FileType('rb'), nargs='?',
|
type=argparse.FileType('rb'), nargs='?',
|
||||||
default=sys.stdin)
|
default=sys.stdin)
|
||||||
group_encrypt.add_argument("message_file", help="Message file (default stdout)",
|
group_encrypt.add_argument("message_file",
|
||||||
|
help="Message file (default stdout)",
|
||||||
type=argparse.FileType('w'), nargs='?',
|
type=argparse.FileType('w'), nargs='?',
|
||||||
default=sys.stdout)
|
default=sys.stdout)
|
||||||
group_encrypt.set_defaults(func=do_group_encrypt)
|
group_encrypt.set_defaults(func=do_group_encrypt)
|
||||||
|
|
||||||
inbound_group = commands.add_parser(
|
inbound_group = commands.add_parser(
|
||||||
"inbound_group",
|
"inbound_group",
|
||||||
help=("Create an inbound group session based on credentials from an "+
|
help=("Create an inbound group session based on credentials from an " +
|
||||||
"outbound group session"))
|
"outbound group session"))
|
||||||
inbound_group.add_argument("session_file", help="Local inbound group session file")
|
inbound_group.add_argument("session_file",
|
||||||
inbound_group.add_argument("credentials_file",
|
help="Local inbound group session file")
|
||||||
help="File to read credentials from (default stdin)",
|
inbound_group.add_argument(
|
||||||
type=argparse.FileType('r'), nargs='?',
|
"credentials_file",
|
||||||
default=sys.stdin)
|
help="File to read credentials from (default stdin)",
|
||||||
|
type=argparse.FileType('r'), nargs='?',
|
||||||
|
default=sys.stdin,
|
||||||
|
)
|
||||||
inbound_group.set_defaults(func=do_inbound_group)
|
inbound_group.set_defaults(func=do_inbound_group)
|
||||||
|
|
||||||
import_inbound_group = commands.add_parser(
|
import_inbound_group = commands.add_parser(
|
||||||
"import_inbound_group",
|
"import_inbound_group",
|
||||||
help="Create an inbound group session based an exported 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("session_file",
|
||||||
|
help="Local inbound group session file")
|
||||||
import_inbound_group.add_argument(
|
import_inbound_group.add_argument(
|
||||||
"export_file",
|
"export_file",
|
||||||
help="File to read credentials from (default stdin)",
|
help="File to read credentials from (default stdin)",
|
||||||
|
@ -283,12 +310,16 @@ def build_arg_parser():
|
||||||
)
|
)
|
||||||
import_inbound_group.set_defaults(func=do_import_inbound_group)
|
import_inbound_group.set_defaults(func=do_import_inbound_group)
|
||||||
|
|
||||||
group_decrypt = commands.add_parser("group_decrypt", help="Decrypt a group message")
|
group_decrypt = commands.add_parser("group_decrypt",
|
||||||
group_decrypt.add_argument("session_file", help="Local inbound group session file")
|
help="Decrypt a group message")
|
||||||
group_decrypt.add_argument("message_file", help="Message file (default stdin)",
|
group_decrypt.add_argument("session_file",
|
||||||
|
help="Local inbound group session file")
|
||||||
|
group_decrypt.add_argument("message_file",
|
||||||
|
help="Message file (default stdin)",
|
||||||
type=argparse.FileType('r'), nargs='?',
|
type=argparse.FileType('r'), nargs='?',
|
||||||
default=sys.stdin)
|
default=sys.stdin)
|
||||||
group_decrypt.add_argument("plaintext_file", help="Plaintext file (default stdout)",
|
group_decrypt.add_argument("plaintext_file",
|
||||||
|
help="Plaintext file (default stdout)",
|
||||||
type=argparse.FileType('wb'), nargs='?',
|
type=argparse.FileType('wb'), nargs='?',
|
||||||
default=sys.stdout)
|
default=sys.stdout)
|
||||||
group_decrypt.set_defaults(func=do_group_decrypt)
|
group_decrypt.set_defaults(func=do_group_decrypt)
|
||||||
|
@ -307,7 +338,8 @@ def build_arg_parser():
|
||||||
)
|
)
|
||||||
export_inbound_group.add_argument(
|
export_inbound_group.add_argument(
|
||||||
"--message_index",
|
"--message_index",
|
||||||
help="Index to export session at. Defaults to the earliest known index",
|
help=("Index to export session at. Defaults to the earliest known " +
|
||||||
|
"index"),
|
||||||
type=int,
|
type=int,
|
||||||
)
|
)
|
||||||
export_inbound_group.set_defaults(func=do_export_inbound_group)
|
export_inbound_group.set_defaults(func=do_export_inbound_group)
|
||||||
|
@ -317,6 +349,7 @@ def build_arg_parser():
|
||||||
ed25519_verify.set_defaults(func=do_verify_ed25519_signature)
|
ed25519_verify.set_defaults(func=do_verify_ed25519_signature)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def do_outbound_group(args):
|
def do_outbound_group(args):
|
||||||
if os.path.exists(args.session_file):
|
if os.path.exists(args.session_file):
|
||||||
sys.stderr.write("Session %r file already exists" % (
|
sys.stderr.write("Session %r file already exists" % (
|
||||||
|
@ -327,6 +360,7 @@ def do_outbound_group(args):
|
||||||
with open(args.session_file, "wb") as f:
|
with open(args.session_file, "wb") as f:
|
||||||
f.write(session.pickle(args.key))
|
f.write(session.pickle(args.key))
|
||||||
|
|
||||||
|
|
||||||
def do_group_encrypt(args):
|
def do_group_encrypt(args):
|
||||||
session = OutboundGroupSession()
|
session = OutboundGroupSession()
|
||||||
session.unpickle(args.key, read_base64_file(args.session_file))
|
session.unpickle(args.key, read_base64_file(args.session_file))
|
||||||
|
@ -336,6 +370,7 @@ def do_group_encrypt(args):
|
||||||
f.write(session.pickle(args.key))
|
f.write(session.pickle(args.key))
|
||||||
args.message_file.write(message)
|
args.message_file.write(message)
|
||||||
|
|
||||||
|
|
||||||
def do_group_credentials(args):
|
def do_group_credentials(args):
|
||||||
session = OutboundGroupSession()
|
session = OutboundGroupSession()
|
||||||
session.unpickle(args.key, read_base64_file(args.session_file))
|
session.unpickle(args.key, read_base64_file(args.session_file))
|
||||||
|
@ -345,6 +380,7 @@ def do_group_credentials(args):
|
||||||
}
|
}
|
||||||
json.dump(result, args.credentials_file, indent=4)
|
json.dump(result, args.credentials_file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def do_inbound_group(args):
|
def do_inbound_group(args):
|
||||||
if os.path.exists(args.session_file):
|
if os.path.exists(args.session_file):
|
||||||
sys.stderr.write("Session %r file already exists\n" % (
|
sys.stderr.write("Session %r file already exists\n" % (
|
||||||
|
@ -353,15 +389,16 @@ def do_inbound_group(args):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
credentials = json.load(args.credentials_file)
|
credentials = json.load(args.credentials_file)
|
||||||
for k in ('session_key', ):
|
for k in ('session_key', ):
|
||||||
if not k in credentials:
|
if k not in credentials:
|
||||||
sys.stderr.write("Credentials file is missing %s\n" % k)
|
sys.stderr.write("Credentials file is missing %s\n" % k)
|
||||||
sys.exit(1);
|
sys.exit(1)
|
||||||
|
|
||||||
session = InboundGroupSession()
|
session = InboundGroupSession()
|
||||||
session.init(credentials['session_key'])
|
session.init(credentials['session_key'])
|
||||||
with open(args.session_file, "wb") as f:
|
with open(args.session_file, "wb") as f:
|
||||||
f.write(session.pickle(args.key))
|
f.write(session.pickle(args.key))
|
||||||
|
|
||||||
|
|
||||||
def do_import_inbound_group(args):
|
def do_import_inbound_group(args):
|
||||||
if os.path.exists(args.session_file):
|
if os.path.exists(args.session_file):
|
||||||
sys.stderr.write("Session %r file already exists\n" % (
|
sys.stderr.write("Session %r file already exists\n" % (
|
||||||
|
@ -375,6 +412,7 @@ def do_import_inbound_group(args):
|
||||||
with open(args.session_file, "wb") as f:
|
with open(args.session_file, "wb") as f:
|
||||||
f.write(session.pickle(args.key))
|
f.write(session.pickle(args.key))
|
||||||
|
|
||||||
|
|
||||||
def do_group_decrypt(args):
|
def do_group_decrypt(args):
|
||||||
session = InboundGroupSession()
|
session = InboundGroupSession()
|
||||||
session.unpickle(args.key, read_base64_file(args.session_file))
|
session.unpickle(args.key, read_base64_file(args.session_file))
|
||||||
|
@ -384,6 +422,7 @@ def do_group_decrypt(args):
|
||||||
f.write(session.pickle(args.key))
|
f.write(session.pickle(args.key))
|
||||||
args.plaintext_file.write(plaintext)
|
args.plaintext_file.write(plaintext)
|
||||||
|
|
||||||
|
|
||||||
def do_export_inbound_group(args):
|
def do_export_inbound_group(args):
|
||||||
session = InboundGroupSession()
|
session = InboundGroupSession()
|
||||||
session.unpickle(args.key, read_base64_file(args.session_file))
|
session.unpickle(args.key, read_base64_file(args.session_file))
|
||||||
|
@ -393,6 +432,7 @@ def do_export_inbound_group(args):
|
||||||
index = session.first_known_index()
|
index = session.first_known_index()
|
||||||
args.export_file.write(session.export_session(index))
|
args.export_file.write(session.export_session(index))
|
||||||
|
|
||||||
|
|
||||||
def do_verify_ed25519_signature(args):
|
def do_verify_ed25519_signature(args):
|
||||||
account = Account()
|
account = Account()
|
||||||
account.create()
|
account.create()
|
||||||
|
@ -401,6 +441,7 @@ def do_verify_ed25519_signature(args):
|
||||||
signature = account.sign(message)
|
signature = account.sign(message)
|
||||||
ed25519_verify(ed25519_key, message, signature)
|
ed25519_verify(ed25519_key, message, signature)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = build_arg_parser()
|
parser = build_arg_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
|
@ -12,5 +12,6 @@ lib.olm_error.restypes = c_size_t
|
||||||
|
|
||||||
ERR = lib.olm_error()
|
ERR = lib.olm_error()
|
||||||
|
|
||||||
|
|
||||||
class OlmError(Exception):
|
class OlmError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -12,6 +12,7 @@ lib.olm_account.restype = c_void_p
|
||||||
lib.olm_account_last_error.argtypes = [c_void_p]
|
lib.olm_account_last_error.argtypes = [c_void_p]
|
||||||
lib.olm_account_last_error.restype = c_char_p
|
lib.olm_account_last_error.restype = c_char_p
|
||||||
|
|
||||||
|
|
||||||
def account_errcheck(res, func, args):
|
def account_errcheck(res, func, args):
|
||||||
if res == ERR:
|
if res == ERR:
|
||||||
raise OlmError("%s: %s" % (
|
raise OlmError("%s: %s" % (
|
||||||
|
@ -52,6 +53,8 @@ account_function(
|
||||||
c_size_t,
|
c_size_t,
|
||||||
c_void_p, c_size_t
|
c_void_p, c_size_t
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Account(object):
|
class Account(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.buf = create_string_buffer(lib.olm_account_size())
|
self.buf = create_string_buffer(lib.olm_account_size())
|
||||||
|
|
|
@ -11,6 +11,7 @@ lib.olm_inbound_group_session.restype = c_void_p
|
||||||
lib.olm_inbound_group_session_last_error.argtypes = [c_void_p]
|
lib.olm_inbound_group_session_last_error.argtypes = [c_void_p]
|
||||||
lib.olm_inbound_group_session_last_error.restype = c_char_p
|
lib.olm_inbound_group_session_last_error.restype = c_char_p
|
||||||
|
|
||||||
|
|
||||||
def inbound_group_session_errcheck(res, func, args):
|
def inbound_group_session_errcheck(res, func, args):
|
||||||
if res == ERR:
|
if res == ERR:
|
||||||
raise OlmError("%s: %s" % (
|
raise OlmError("%s: %s" % (
|
||||||
|
@ -26,10 +27,12 @@ def inbound_group_session_function(func, *types):
|
||||||
|
|
||||||
|
|
||||||
inbound_group_session_function(
|
inbound_group_session_function(
|
||||||
lib.olm_pickle_inbound_group_session, c_void_p, c_size_t, c_void_p, c_size_t
|
lib.olm_pickle_inbound_group_session,
|
||||||
|
c_void_p, c_size_t, c_void_p, c_size_t,
|
||||||
)
|
)
|
||||||
inbound_group_session_function(
|
inbound_group_session_function(
|
||||||
lib.olm_unpickle_inbound_group_session, c_void_p, c_size_t, c_void_p, c_size_t
|
lib.olm_unpickle_inbound_group_session,
|
||||||
|
c_void_p, c_size_t, c_void_p, c_size_t,
|
||||||
)
|
)
|
||||||
|
|
||||||
inbound_group_session_function(
|
inbound_group_session_function(
|
||||||
|
@ -45,19 +48,28 @@ inbound_group_session_function(
|
||||||
)
|
)
|
||||||
inbound_group_session_function(
|
inbound_group_session_function(
|
||||||
lib.olm_group_decrypt,
|
lib.olm_group_decrypt,
|
||||||
c_void_p, c_size_t, # message
|
c_void_p, c_size_t, # message
|
||||||
c_void_p, c_size_t, # plaintext
|
c_void_p, c_size_t, # plaintext
|
||||||
POINTER(c_uint32), # message_index
|
POINTER(c_uint32), # message_index
|
||||||
)
|
)
|
||||||
|
|
||||||
inbound_group_session_function(lib.olm_inbound_group_session_id_length)
|
inbound_group_session_function(
|
||||||
inbound_group_session_function(lib.olm_inbound_group_session_id, c_void_p, c_size_t)
|
lib.olm_inbound_group_session_id_length,
|
||||||
|
)
|
||||||
|
inbound_group_session_function(
|
||||||
|
lib.olm_inbound_group_session_id,
|
||||||
|
c_void_p, c_size_t,
|
||||||
|
)
|
||||||
|
|
||||||
lib.olm_inbound_group_session_first_known_index.argtypes = (c_void_p,)
|
lib.olm_inbound_group_session_first_known_index.argtypes = (c_void_p,)
|
||||||
lib.olm_inbound_group_session_first_known_index.restypes = c_uint32
|
lib.olm_inbound_group_session_first_known_index.restypes = c_uint32
|
||||||
|
|
||||||
inbound_group_session_function(lib.olm_export_inbound_group_session_length)
|
inbound_group_session_function(
|
||||||
inbound_group_session_function(lib.olm_export_inbound_group_session, c_void_p, c_size_t, c_uint32)
|
lib.olm_export_inbound_group_session_length,
|
||||||
|
)
|
||||||
|
inbound_group_session_function(
|
||||||
|
lib.olm_export_inbound_group_session, c_void_p, c_size_t, c_uint32,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InboundGroupSession(object):
|
class InboundGroupSession(object):
|
||||||
|
@ -107,7 +119,7 @@ class InboundGroupSession(object):
|
||||||
plaintext_buffer, max_plaintext_length,
|
plaintext_buffer, max_plaintext_length,
|
||||||
byref(message_index)
|
byref(message_index)
|
||||||
)
|
)
|
||||||
return plaintext_buffer.raw[:plaintext_length], message_index
|
return plaintext_buffer.raw[:plaintext_length], message_index.value
|
||||||
|
|
||||||
def session_id(self):
|
def session_id(self):
|
||||||
id_length = lib.olm_inbound_group_session_id_length(self.ptr)
|
id_length = lib.olm_inbound_group_session_id_length(self.ptr)
|
||||||
|
|
|
@ -12,6 +12,7 @@ lib.olm_outbound_group_session.restype = c_void_p
|
||||||
lib.olm_outbound_group_session_last_error.argtypes = [c_void_p]
|
lib.olm_outbound_group_session_last_error.argtypes = [c_void_p]
|
||||||
lib.olm_outbound_group_session_last_error.restype = c_char_p
|
lib.olm_outbound_group_session_last_error.restype = c_char_p
|
||||||
|
|
||||||
|
|
||||||
def outbound_group_session_errcheck(res, func, args):
|
def outbound_group_session_errcheck(res, func, args):
|
||||||
if res == ERR:
|
if res == ERR:
|
||||||
raise OlmError("%s: %s" % (
|
raise OlmError("%s: %s" % (
|
||||||
|
@ -27,28 +28,49 @@ def outbound_group_session_function(func, *types):
|
||||||
|
|
||||||
|
|
||||||
outbound_group_session_function(
|
outbound_group_session_function(
|
||||||
lib.olm_pickle_outbound_group_session, c_void_p, c_size_t, c_void_p, c_size_t
|
lib.olm_pickle_outbound_group_session,
|
||||||
|
c_void_p, c_size_t, c_void_p, c_size_t,
|
||||||
)
|
)
|
||||||
outbound_group_session_function(
|
outbound_group_session_function(
|
||||||
lib.olm_unpickle_outbound_group_session, c_void_p, c_size_t, c_void_p, c_size_t
|
lib.olm_unpickle_outbound_group_session,
|
||||||
|
c_void_p, c_size_t, c_void_p, c_size_t,
|
||||||
)
|
)
|
||||||
|
|
||||||
outbound_group_session_function(lib.olm_init_outbound_group_session_random_length)
|
outbound_group_session_function(
|
||||||
outbound_group_session_function(lib.olm_init_outbound_group_session, c_void_p, c_size_t)
|
lib.olm_init_outbound_group_session_random_length,
|
||||||
|
)
|
||||||
|
outbound_group_session_function(
|
||||||
|
lib.olm_init_outbound_group_session,
|
||||||
|
c_void_p, c_size_t,
|
||||||
|
)
|
||||||
|
|
||||||
lib.olm_outbound_group_session_message_index.argtypes = [c_void_p]
|
lib.olm_outbound_group_session_message_index.argtypes = [c_void_p]
|
||||||
lib.olm_outbound_group_session_message_index.restype = c_uint32
|
lib.olm_outbound_group_session_message_index.restype = c_uint32
|
||||||
|
|
||||||
outbound_group_session_function(lib.olm_group_encrypt_message_length, c_size_t)
|
outbound_group_session_function(
|
||||||
outbound_group_session_function(lib.olm_group_encrypt,
|
lib.olm_group_encrypt_message_length,
|
||||||
|
c_size_t,
|
||||||
|
)
|
||||||
|
outbound_group_session_function(
|
||||||
|
lib.olm_group_encrypt,
|
||||||
c_void_p, c_size_t, # Plaintext
|
c_void_p, c_size_t, # Plaintext
|
||||||
c_void_p, c_size_t, # Message
|
c_void_p, c_size_t, # Message
|
||||||
)
|
)
|
||||||
|
|
||||||
outbound_group_session_function(lib.olm_outbound_group_session_id_length)
|
outbound_group_session_function(
|
||||||
outbound_group_session_function(lib.olm_outbound_group_session_id, c_void_p, c_size_t)
|
lib.olm_outbound_group_session_id_length,
|
||||||
outbound_group_session_function(lib.olm_outbound_group_session_key_length)
|
)
|
||||||
outbound_group_session_function(lib.olm_outbound_group_session_key, c_void_p, c_size_t)
|
outbound_group_session_function(
|
||||||
|
lib.olm_outbound_group_session_id,
|
||||||
|
c_void_p, c_size_t,
|
||||||
|
)
|
||||||
|
outbound_group_session_function(
|
||||||
|
lib.olm_outbound_group_session_key_length,
|
||||||
|
)
|
||||||
|
outbound_group_session_function(
|
||||||
|
lib.olm_outbound_group_session_key,
|
||||||
|
c_void_p, c_size_t,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OutboundGroupSession(object):
|
class OutboundGroupSession(object):
|
||||||
|
@ -56,10 +78,14 @@ class OutboundGroupSession(object):
|
||||||
self.buf = create_string_buffer(lib.olm_outbound_group_session_size())
|
self.buf = create_string_buffer(lib.olm_outbound_group_session_size())
|
||||||
self.ptr = lib.olm_outbound_group_session(self.buf)
|
self.ptr = lib.olm_outbound_group_session(self.buf)
|
||||||
|
|
||||||
random_length = lib.olm_init_outbound_group_session_random_length(self.ptr)
|
random_length = lib.olm_init_outbound_group_session_random_length(
|
||||||
|
self.ptr
|
||||||
|
)
|
||||||
random = urandom(random_length)
|
random = urandom(random_length)
|
||||||
random_buffer = create_string_buffer(random)
|
random_buffer = create_string_buffer(random)
|
||||||
lib.olm_init_outbound_group_session(self.ptr, random_buffer, random_length)
|
lib.olm_init_outbound_group_session(
|
||||||
|
self.ptr, random_buffer, random_length
|
||||||
|
)
|
||||||
|
|
||||||
def pickle(self, key):
|
def pickle(self, key):
|
||||||
key_buffer = create_string_buffer(key)
|
key_buffer = create_string_buffer(key)
|
||||||
|
@ -95,7 +121,7 @@ class OutboundGroupSession(object):
|
||||||
def session_id(self):
|
def session_id(self):
|
||||||
id_length = lib.olm_outbound_group_session_id_length(self.ptr)
|
id_length = lib.olm_outbound_group_session_id_length(self.ptr)
|
||||||
id_buffer = create_string_buffer(id_length)
|
id_buffer = create_string_buffer(id_length)
|
||||||
lib.olm_outbound_group_session_id(self.ptr, id_buffer, id_length);
|
lib.olm_outbound_group_session_id(self.ptr, id_buffer, id_length)
|
||||||
return id_buffer.raw
|
return id_buffer.raw
|
||||||
|
|
||||||
def message_index(self):
|
def message_index(self):
|
||||||
|
@ -104,5 +130,5 @@ class OutboundGroupSession(object):
|
||||||
def session_key(self):
|
def session_key(self):
|
||||||
key_length = lib.olm_outbound_group_session_key_length(self.ptr)
|
key_length = lib.olm_outbound_group_session_key_length(self.ptr)
|
||||||
key_buffer = create_string_buffer(key_length)
|
key_buffer = create_string_buffer(key_length)
|
||||||
lib.olm_outbound_group_session_key(self.ptr, key_buffer, key_length);
|
lib.olm_outbound_group_session_key(self.ptr, key_buffer, key_length)
|
||||||
return key_buffer.raw
|
return key_buffer.raw
|
||||||
|
|
|
@ -69,7 +69,7 @@ session_function(
|
||||||
c_void_p, c_size_t, # Plaintext
|
c_void_p, c_size_t, # Plaintext
|
||||||
c_void_p, c_size_t, # Random
|
c_void_p, c_size_t, # Random
|
||||||
c_void_p, c_size_t, # Message
|
c_void_p, c_size_t, # Message
|
||||||
);
|
)
|
||||||
session_function(
|
session_function(
|
||||||
lib.olm_decrypt_max_plaintext_length,
|
lib.olm_decrypt_max_plaintext_length,
|
||||||
c_size_t, # Message Type
|
c_size_t, # Message Type
|
||||||
|
@ -82,6 +82,7 @@ session_function(
|
||||||
c_void_p, c_size_t, # Plaintext
|
c_void_p, c_size_t, # Plaintext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Session(object):
|
class Session(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.buf = create_string_buffer(lib.olm_session_size())
|
self.buf = create_string_buffer(lib.olm_session_size())
|
||||||
|
@ -118,7 +119,9 @@ class Session(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_inbound(self, account, one_time_key_message):
|
def create_inbound(self, account, one_time_key_message):
|
||||||
one_time_key_message_buffer = create_string_buffer(one_time_key_message)
|
one_time_key_message_buffer = create_string_buffer(
|
||||||
|
one_time_key_message
|
||||||
|
)
|
||||||
lib.olm_create_inbound_session(
|
lib.olm_create_inbound_session(
|
||||||
self.ptr,
|
self.ptr,
|
||||||
account.ptr,
|
account.ptr,
|
||||||
|
@ -127,7 +130,9 @@ class Session(object):
|
||||||
|
|
||||||
def create_inbound_from(self, account, identity_key, one_time_key_message):
|
def create_inbound_from(self, account, identity_key, one_time_key_message):
|
||||||
identity_key_buffer = create_string_buffer(identity_key)
|
identity_key_buffer = create_string_buffer(identity_key)
|
||||||
one_time_key_message_buffer = create_string_buffer(one_time_key_message)
|
one_time_key_message_buffer = create_string_buffer(
|
||||||
|
one_time_key_message
|
||||||
|
)
|
||||||
lib.olm_create_inbound_session_from(
|
lib.olm_create_inbound_session_from(
|
||||||
self.ptr,
|
self.ptr,
|
||||||
account.ptr,
|
account.ptr,
|
||||||
|
@ -138,11 +143,13 @@ class Session(object):
|
||||||
def session_id(self):
|
def session_id(self):
|
||||||
id_length = lib.olm_session_id_length(self.ptr)
|
id_length = lib.olm_session_id_length(self.ptr)
|
||||||
id_buffer = create_string_buffer(id_length)
|
id_buffer = create_string_buffer(id_length)
|
||||||
lib.olm_session_id(self.ptr, id_buffer, id_length);
|
lib.olm_session_id(self.ptr, id_buffer, id_length)
|
||||||
return id_buffer.raw
|
return id_buffer.raw
|
||||||
|
|
||||||
def matches_inbound(self, one_time_key_message):
|
def matches_inbound(self, one_time_key_message):
|
||||||
one_time_key_message_buffer = create_string_buffer(one_time_key_message)
|
one_time_key_message_buffer = create_string_buffer(
|
||||||
|
one_time_key_message,
|
||||||
|
)
|
||||||
return bool(lib.olm_matches_inbound_session(
|
return bool(lib.olm_matches_inbound_session(
|
||||||
self.ptr,
|
self.ptr,
|
||||||
one_time_key_message_buffer, len(one_time_key_message)
|
one_time_key_message_buffer, len(one_time_key_message)
|
||||||
|
@ -150,7 +157,9 @@ class Session(object):
|
||||||
|
|
||||||
def matches_inbound_from(self, identity_key, one_time_key_message):
|
def matches_inbound_from(self, identity_key, one_time_key_message):
|
||||||
identity_key_buffer = create_string_buffer(identity_key)
|
identity_key_buffer = create_string_buffer(identity_key)
|
||||||
one_time_key_message_buffer = create_string_buffer(one_time_key_message)
|
one_time_key_message_buffer = create_string_buffer(
|
||||||
|
one_time_key_message,
|
||||||
|
)
|
||||||
return bool(lib.olm_matches_inbound_session(
|
return bool(lib.olm_matches_inbound_session(
|
||||||
self.ptr,
|
self.ptr,
|
||||||
identity_key_buffer, len(identity_key),
|
identity_key_buffer, len(identity_key),
|
||||||
|
|
Loading…
Reference in a new issue