Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gajim
gajim-plugins
Commits
3e287d2a
Commit
3e287d2a
authored
Jun 09, 2017
by
Philipp Hörist
Browse files
[omemo] Add encrypt_file method
The HTTPUploadPlugin calls that if encryption is enabled
parent
c4f2c658
Changes
2
Hide whitespace changes
Inline
Side-by-side
omemo/omemo/state.py
View file @
3e287d2a
...
...
@@ -19,6 +19,7 @@
import
logging
import
time
import
os
from
base64
import
b64encode
from
axolotl.ecc.djbec
import
DjbECPublicKey
...
...
@@ -216,6 +217,14 @@ class OmemoState:
log
.
debug
(
"Decrypted Message => "
+
result
)
return
result
def
encrypt_file
(
self
,
data
):
key
=
os
.
urandom
(
32
)
iv
=
os
.
urandom
(
16
)
payload
,
tag
=
encrypt
(
key
,
iv
,
data
)
encrypted_data
=
payload
+
tag
return
(
encrypted_data
,
key
,
iv
)
def
create_msg
(
self
,
from_jid
,
jid
,
plaintext
):
key
=
get_random_bytes
(
16
)
iv
=
get_random_bytes
(
16
)
...
...
omemo/omemoplugin.py
View file @
3e287d2a
...
...
@@ -25,7 +25,10 @@ import os
import
sqlite3
import
shutil
import
nbxmpp
import
binascii
import
threading
from
gi.repository
import
GLib
from
nbxmpp.simplexml
import
Node
from
nbxmpp
import
NS_ADDRESS
...
...
@@ -201,6 +204,23 @@ class OmemoPlugin(GajimPlugin):
def
file_decryption
(
self
,
url
,
kind
,
instance
,
window
):
FileDecryption
(
self
).
hyperlink_handler
(
url
,
kind
,
instance
,
window
)
def
encrypt_file
(
self
,
file
,
account
,
callback
):
thread
=
threading
.
Thread
(
target
=
self
.
_encrypt_file_thread
,
args
=
(
file
,
account
,
callback
))
thread
.
daemon
=
True
thread
.
start
()
def
_encrypt_file_thread
(
self
,
file
,
account
,
callback
):
state
=
self
.
get_omemo_state
(
account
)
encrypted_data
,
key
,
iv
=
state
.
encrypt_file
(
file
.
get_data
(
full
=
True
))
file
.
encrypted
=
True
file
.
size
=
len
(
encrypted_data
)
file
.
user_data
=
binascii
.
hexlify
(
iv
+
key
).
decode
(
'utf-8'
)
file
.
data
=
encrypted_data
if
file
.
event
.
isSet
():
return
GLib
.
idle_add
(
callback
,
file
)
def
signed_in
(
self
,
event
):
""" Method called on SignIn
...
...
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