Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
cfcee54a
Commit
cfcee54a
authored
8 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Handle non-base64 chars in pickle files
parent
047927d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/olm/__main__.py
+18
-26
18 additions, 26 deletions
python/olm/__main__.py
with
18 additions
and
26 deletions
python/olm/__main__.py
+
18
−
26
View file @
cfcee54a
...
...
@@ -10,6 +10,11 @@ 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
=
""
)
...
...
@@ -37,8 +42,7 @@ def build_arg_parser():
def
do_keys
(
args
):
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
result
=
{
"
account_keys
"
:
account
.
identity_keys
(),
"
one_time_keys
"
:
account
.
one_time_keys
(),
...
...
@@ -55,8 +59,7 @@ def build_arg_parser():
def
do_id_key
(
args
):
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
print
(
account
.
identity_keys
()[
'
curve25519
'
])
id_key
=
commands
.
add_parser
(
"
identity_key
"
,
help
=
"
Get the identity key for an account
"
)
...
...
@@ -65,8 +68,7 @@ def build_arg_parser():
def
do_one_time_key
(
args
):
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
keys
=
account
.
one_time_keys
()[
'
curve25519
'
].
values
()
key_num
=
args
.
key_num
if
key_num
<
1
or
key_num
>
len
(
keys
):
...
...
@@ -93,8 +95,7 @@ def build_arg_parser():
def
do_sign
(
args
):
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
with
open_in
(
args
.
message_file
)
as
f
:
message
=
f
.
read
()
signature
=
account
.
sign
(
message
)
...
...
@@ -110,8 +111,7 @@ def build_arg_parser():
def
do_generate_keys
(
args
):
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
account
.
generate_one_time_keys
(
args
.
count
)
with
open
(
args
.
account_file
,
"
wb
"
)
as
f
:
f
.
write
(
account
.
pickle
(
args
.
key
))
...
...
@@ -132,8 +132,7 @@ def build_arg_parser():
))
sys
.
exit
(
1
)
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
session
=
Session
()
session
.
create_outbound
(
account
,
args
.
identity_key
,
args
.
one_time_key
...
...
@@ -168,8 +167,7 @@ def build_arg_parser():
))
sys
.
exit
(
1
)
account
=
Account
()
with
open
(
args
.
account_file
,
"
rb
"
)
as
f
:
account
.
unpickle
(
args
.
key
,
f
.
read
())
account
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
account_file
))
with
open_in
(
args
.
message_file
)
as
f
:
message_type
=
f
.
read
(
8
)
message
=
f
.
read
()
...
...
@@ -191,8 +189,7 @@ def build_arg_parser():
def
do_session_id
(
args
):
session
=
Session
()
with
open
(
args
.
session_file
,
"
rb
"
)
as
f
:
session
.
unpickle
(
args
.
key
,
f
.
read
())
session
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
session_file
))
sys
.
stdout
.
write
(
session
.
session_id
()
+
"
\n
"
)
session_id
.
set_defaults
(
func
=
do_session_id
)
...
...
@@ -204,8 +201,7 @@ def build_arg_parser():
def
do_encrypt
(
args
):
session
=
Session
()
with
open
(
args
.
session_file
,
"
rb
"
)
as
f
:
session
.
unpickle
(
args
.
key
,
f
.
read
())
session
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
session_file
))
with
open_in
(
args
.
plaintext_file
)
as
f
:
plaintext
=
f
.
read
()
message_type
,
message
=
session
.
encrypt
(
plaintext
)
...
...
@@ -224,8 +220,7 @@ def build_arg_parser():
def
do_decrypt
(
args
):
session
=
Session
()
with
open
(
args
.
session_file
,
"
rb
"
)
as
f
:
session
.
unpickle
(
args
.
key
,
f
.
read
())
session
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
session_file
))
with
open_in
(
args
.
message_file
)
as
f
:
message_type
=
f
.
read
(
8
)
message
=
f
.
read
()
...
...
@@ -296,8 +291,7 @@ def do_outbound_group(args):
def
do_group_encrypt
(
args
):
session
=
OutboundGroupSession
()
with
open
(
args
.
session_file
,
"
rb
"
)
as
f
:
session
.
unpickle
(
args
.
key
,
f
.
read
())
session
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
session_file
))
plaintext
=
args
.
plaintext_file
.
read
()
message
=
session
.
encrypt
(
plaintext
)
with
open
(
args
.
session_file
,
"
wb
"
)
as
f
:
...
...
@@ -306,8 +300,7 @@ def do_group_encrypt(args):
def
do_group_credentials
(
args
):
session
=
OutboundGroupSession
()
with
open
(
args
.
session_file
,
"
rb
"
)
as
f
:
session
.
unpickle
(
args
.
key
,
f
.
read
())
session
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
session_file
))
result
=
{
'
message_index
'
:
session
.
message_index
(),
'
session_key
'
:
session
.
session_key
(),
...
...
@@ -333,8 +326,7 @@ def do_inbound_group(args):
def
do_group_decrypt
(
args
):
session
=
InboundGroupSession
()
with
open
(
args
.
session_file
,
"
rb
"
)
as
f
:
session
.
unpickle
(
args
.
key
,
f
.
read
())
session
.
unpickle
(
args
.
key
,
read_base64_file
(
args
.
session_file
))
message
=
args
.
message_file
.
read
()
plaintext
=
session
.
decrypt
(
message
)
with
open
(
args
.
session_file
,
"
wb
"
)
as
f
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment