Python: Switch to a more general os.urandom for randomness source
Signed-off-by: Jan Jancar <johny@neuromancer.sk>
This commit is contained in:
parent
bb05b5687f
commit
001dc1edaa
5 changed files with 11 additions and 9 deletions
|
@ -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",
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue