aboutsummaryrefslogtreecommitdiff
path: root/python/olm
diff options
context:
space:
mode:
authorJ08nY <johny@neuromancer.sk>2017-04-02 00:35:55 +0200
committerRichard van der Hoff <richard@matrix.org>2017-04-04 10:45:11 +0100
commit001dc1edaa4c5306fbb7c625202788458dadeafa (patch)
treeef9201b107d717c34b19f3fb9d4dca56d0fa32fe /python/olm
parentbb05b5687f12782cc2e87ffdf2dc0dfe0f6dcfb6 (diff)
Python: Switch to a more general os.urandom for randomness source
Signed-off-by: Jan Jancar <johny@neuromancer.sk>
Diffstat (limited to 'python/olm')
-rwxr-xr-xpython/olm/__main__.py3
-rw-r--r--python/olm/_base.py3
-rw-r--r--python/olm/account.py5
-rw-r--r--python/olm/outbound_group_session.py3
-rw-r--r--python/olm/session.py6
5 files changed, 11 insertions, 9 deletions
diff --git a/python/olm/__main__.py b/python/olm/__main__.py
index 5f78f76..cb7f164 100755
--- a/python/olm/__main__.py
+++ b/python/olm/__main__.py
@@ -10,11 +10,13 @@ import yaml
from . import *
+
def read_base64_file(filename):
"""Read a base64 file, dropping any CR/LF characters"""
with open(filename, "rb") as f:
return f.read().translate(None, "\r\n")
+
def build_arg_parser():
parser = argparse.ArgumentParser()
parser.add_argument("--key", help="Account encryption key", default="")
@@ -291,7 +293,6 @@ def build_arg_parser():
default=sys.stdout)
group_decrypt.set_defaults(func=do_group_decrypt)
-
export_inbound_group = commands.add_parser(
"export_inbound_group",
help="Export the keys for an inbound group session",
diff --git a/python/olm/_base.py b/python/olm/_base.py
index 80720d9..64cb98b 100644
--- a/python/olm/_base.py
+++ b/python/olm/_base.py
@@ -2,9 +2,6 @@ import os.path
from ctypes import *
-def read_random(n):
- with open("/dev/urandom", "rb") as f:
- return f.read(n)
lib = cdll.LoadLibrary(os.path.join(
os.path.dirname(__file__), "..", "..", "build", "libolm.so.2")
diff --git a/python/olm/account.py b/python/olm/account.py
index 3fa1049..e2dcca2 100644
--- a/python/olm/account.py
+++ b/python/olm/account.py
@@ -1,4 +1,5 @@
import json
+from os import urandom
from ._base import *
@@ -58,7 +59,7 @@ class Account(object):
def create(self):
random_length = lib.olm_create_account_random_length(self.ptr)
- random = read_random(random_length)
+ random = urandom(random_length)
random_buffer = create_string_buffer(random)
lib.olm_create_account(self.ptr, random_buffer, random_length)
@@ -112,7 +113,7 @@ class Account(object):
random_length = lib.olm_account_generate_one_time_keys_random_length(
self.ptr, count
)
- random = read_random(random_length)
+ random = urandom(random_length)
random_buffer = create_string_buffer(random)
lib.olm_account_generate_one_time_keys(
self.ptr, count, random_buffer, random_length
diff --git a/python/olm/outbound_group_session.py b/python/olm/outbound_group_session.py
index 56f0962..e888f41 100644
--- a/python/olm/outbound_group_session.py
+++ b/python/olm/outbound_group_session.py
@@ -1,4 +1,5 @@
import json
+from os import urandom
from ._base import *
@@ -56,7 +57,7 @@ class OutboundGroupSession(object):
self.ptr = lib.olm_outbound_group_session(self.buf)
random_length = lib.olm_init_outbound_group_session_random_length(self.ptr)
- random = read_random(random_length)
+ random = urandom(random_length)
random_buffer = create_string_buffer(random)
lib.olm_init_outbound_group_session(self.ptr, random_buffer, random_length)
diff --git a/python/olm/session.py b/python/olm/session.py
index 19d43d3..ff733b3 100644
--- a/python/olm/session.py
+++ b/python/olm/session.py
@@ -1,3 +1,5 @@
+from os import urandom
+
from ._base import *
@@ -103,7 +105,7 @@ class Session(object):
def create_outbound(self, account, identity_key, one_time_key):
r_length = lib.olm_create_outbound_session_random_length(self.ptr)
- random = read_random(r_length)
+ random = urandom(r_length)
random_buffer = create_string_buffer(random)
identity_key_buffer = create_string_buffer(identity_key)
one_time_key_buffer = create_string_buffer(one_time_key)
@@ -157,7 +159,7 @@ class Session(object):
def encrypt(self, plaintext):
r_length = lib.olm_encrypt_random_length(self.ptr)
- random = read_random(r_length)
+ random = urandom(r_length)
random_buffer = create_string_buffer(random)
message_type = lib.olm_encrypt_message_type(self.ptr)