Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
001dc1ed
Commit
001dc1ed
authored
Apr 02, 2017
by
J08nY
Committed by
Richard van der Hoff
Apr 04, 2017
Browse files
Python: Switch to a more general os.urandom for randomness source
Signed-off-by:
Jan Jancar
<
johny@neuromancer.sk
>
parent
bb05b568
Changes
5
Hide whitespace changes
Inline
Side-by-side
python/olm/__main__.py
View file @
001dc1ed
...
...
@@ -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"
,
...
...
python/olm/_base.py
View file @
001dc1ed
...
...
@@ -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"
)
...
...
python/olm/account.py
View file @
001dc1ed
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
=
u
random
(
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
=
u
random
(
random_length
)
random_buffer
=
create_string_buffer
(
random
)
lib
.
olm_account_generate_one_time_keys
(
self
.
ptr
,
count
,
random_buffer
,
random_length
...
...
python/olm/outbound_group_session.py
View file @
001dc1ed
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
=
u
random
(
random_length
)
random_buffer
=
create_string_buffer
(
random
)
lib
.
olm_init_outbound_group_session
(
self
.
ptr
,
random_buffer
,
random_length
)
...
...
python/olm/session.py
View file @
001dc1ed
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
=
u
random
(
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
=
u
random
(
r_length
)
random_buffer
=
create_string_buffer
(
random
)
message_type
=
lib
.
olm_encrypt_message_type
(
self
.
ptr
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment