Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Evert Mouw
gajim-plugins
Commits
c9510f9f
Commit
c9510f9f
authored
7 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
[omemo] Make encrypt_file() method better available
Now we dont need to supply the account
parent
6974e704
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
omemo/file_crypto.py
+10
-0
10 additions, 0 deletions
omemo/file_crypto.py
omemo/omemo/state.py
+0
-8
0 additions, 8 deletions
omemo/omemo/state.py
omemo/omemoplugin.py
+9
-7
9 additions, 7 deletions
omemo/omemoplugin.py
with
19 additions
and
15 deletions
omemo/file_
de
crypt
ion
.py
→
omemo/file_crypt
o
.py
+
10
−
0
View file @
c9510f9f
...
...
@@ -45,6 +45,7 @@ try:
from
cryptography.hazmat.primitives.ciphers
import
algorithms
from
cryptography.hazmat.primitives.ciphers.modes
import
GCM
from
cryptography.hazmat.backends
import
default_backend
from
omemo.omemo.aes_gcm_native
import
aes_encrypt
except
ImportError
:
log
.
exception
(
'
ImportError
'
)
ERROR
=
True
...
...
@@ -59,6 +60,15 @@ except Exception:
log
.
exception
(
'
Error
'
)
def
encrypt_file
(
data
):
key
=
os
.
urandom
(
32
)
iv
=
os
.
urandom
(
16
)
payload
,
tag
=
aes_encrypt
(
key
,
iv
,
data
)
encrypted_data
=
payload
+
tag
return
(
encrypted_data
,
key
,
iv
)
class
File
:
def
__init__
(
self
,
url
):
self
.
url
,
self
.
fragment
=
urldefrag
(
url
)
...
...
This diff is collapsed.
Click to expand it.
omemo/omemo/state.py
+
0
−
8
View file @
c9510f9f
...
...
@@ -217,14 +217,6 @@ 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
)
...
...
This diff is collapsed.
Click to expand it.
omemo/omemoplugin.py
+
9
−
7
View file @
c9510f9f
...
...
@@ -45,7 +45,7 @@ ERROR_MSG = ''
log
=
logging
.
getLogger
(
'
gajim.plugin_system.omemo
'
)
try
:
from
omemo
.file_decryption
import
F
ile
De
crypt
ion
from
omemo
import
f
ile
_
crypt
o
except
Exception
as
error
:
log
.
exception
(
error
)
ERROR_MSG
=
CRYPTOGRAPHY_MISSING
...
...
@@ -188,17 +188,19 @@ class OmemoPlugin(GajimPlugin):
self
.
connections
[
conn
.
name
].
encrypt_message
(
conn
,
obj
,
callback
)
def
_file_decryption
(
self
,
url
,
kind
,
instance
,
window
):
FileDecryption
(
self
).
hyperlink_handler
(
url
,
kind
,
instance
,
window
)
file_decryption
.
FileDecryption
(
self
).
hyperlink_handler
(
url
,
kind
,
instance
,
window
)
def
encrypt_file
(
self
,
file
,
account
,
callback
):
def
encrypt_file
(
self
,
file
,
callback
):
thread
=
threading
.
Thread
(
target
=
self
.
_encrypt_file_thread
,
args
=
(
file
,
account
,
callback
))
args
=
(
file
,
callback
))
thread
.
daemon
=
True
thread
.
start
()
def
_encrypt_file_thread
(
self
,
file
,
account
,
callback
):
omemo
=
self
.
get_omemo
(
account
)
encrypted_data
,
key
,
iv
=
omemo
.
encrypt_file
(
file
.
get_data
(
full
=
True
))
@staticmethod
def
_encrypt_file_thread
(
file
,
callback
):
encrypted_data
,
key
,
iv
=
file_decryption
.
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
'
)
...
...
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