Commit 001dc1ed authored by J08nY's avatar J08nY Committed by Richard van der Hoff
Browse files

Python: Switch to a more general os.urandom for randomness source


Signed-off-by: default avatarJan Jancar <johny@neuromancer.sk>
parent bb05b568
...@@ -10,11 +10,13 @@ import yaml ...@@ -10,11 +10,13 @@ import yaml
from . import * from . import *
def read_base64_file(filename): def read_base64_file(filename):
"""Read a base64 file, dropping any CR/LF characters""" """Read a base64 file, dropping any CR/LF characters"""
with open(filename, "rb") as f: with open(filename, "rb") as f:
return f.read().translate(None, "\r\n") return f.read().translate(None, "\r\n")
def build_arg_parser(): def build_arg_parser():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--key", help="Account encryption key", default="") parser.add_argument("--key", help="Account encryption key", default="")
...@@ -291,7 +293,6 @@ def build_arg_parser(): ...@@ -291,7 +293,6 @@ def build_arg_parser():
default=sys.stdout) default=sys.stdout)
group_decrypt.set_defaults(func=do_group_decrypt) group_decrypt.set_defaults(func=do_group_decrypt)
export_inbound_group = commands.add_parser( export_inbound_group = commands.add_parser(
"export_inbound_group", "export_inbound_group",
help="Export the keys for an inbound group session", help="Export the keys for an inbound group session",
......
...@@ -2,9 +2,6 @@ import os.path ...@@ -2,9 +2,6 @@ import os.path
from ctypes import * from ctypes import *
def read_random(n):
with open("/dev/urandom", "rb") as f:
return f.read(n)
lib = cdll.LoadLibrary(os.path.join( lib = cdll.LoadLibrary(os.path.join(
os.path.dirname(__file__), "..", "..", "build", "libolm.so.2") os.path.dirname(__file__), "..", "..", "build", "libolm.so.2")
......
import json import json
from os import urandom
from ._base import * from ._base import *
...@@ -58,7 +59,7 @@ class Account(object): ...@@ -58,7 +59,7 @@ class Account(object):
def create(self): def create(self):
random_length = lib.olm_create_account_random_length(self.ptr) 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) random_buffer = create_string_buffer(random)
lib.olm_create_account(self.ptr, random_buffer, random_length) lib.olm_create_account(self.ptr, random_buffer, random_length)
...@@ -112,7 +113,7 @@ class Account(object): ...@@ -112,7 +113,7 @@ class Account(object):
random_length = lib.olm_account_generate_one_time_keys_random_length( random_length = lib.olm_account_generate_one_time_keys_random_length(
self.ptr, count self.ptr, count
) )
random = read_random(random_length) random = urandom(random_length)
random_buffer = create_string_buffer(random) random_buffer = create_string_buffer(random)
lib.olm_account_generate_one_time_keys( lib.olm_account_generate_one_time_keys(
self.ptr, count, random_buffer, random_length self.ptr, count, random_buffer, random_length
......
import json import json
from os import urandom
from ._base import * from ._base import *
...@@ -56,7 +57,7 @@ class OutboundGroupSession(object): ...@@ -56,7 +57,7 @@ class OutboundGroupSession(object):
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 = read_random(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)
......
from os import urandom
from ._base import * from ._base import *
...@@ -103,7 +105,7 @@ class Session(object): ...@@ -103,7 +105,7 @@ class Session(object):
def create_outbound(self, account, identity_key, one_time_key): def create_outbound(self, account, identity_key, one_time_key):
r_length = lib.olm_create_outbound_session_random_length(self.ptr) 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) random_buffer = create_string_buffer(random)
identity_key_buffer = create_string_buffer(identity_key) identity_key_buffer = create_string_buffer(identity_key)
one_time_key_buffer = create_string_buffer(one_time_key) one_time_key_buffer = create_string_buffer(one_time_key)
...@@ -157,7 +159,7 @@ class Session(object): ...@@ -157,7 +159,7 @@ class Session(object):
def encrypt(self, plaintext): def encrypt(self, plaintext):
r_length = lib.olm_encrypt_random_length(self.ptr) r_length = lib.olm_encrypt_random_length(self.ptr)
random = read_random(r_length) random = urandom(r_length)
random_buffer = create_string_buffer(random) random_buffer = create_string_buffer(random)
message_type = lib.olm_encrypt_message_type(self.ptr) message_type = lib.olm_encrypt_message_type(self.ptr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment