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
fe8d23e4
Commit
fe8d23e4
authored
8 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
[httpupload] Fix and simplify encryption
parent
ff135bee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
httpupload/httpupload.py
+10
-18
10 additions, 18 deletions
httpupload/httpupload.py
with
10 additions
and
18 deletions
httpupload/httpupload.py
+
10
−
18
View file @
fe8d23e4
...
@@ -21,7 +21,7 @@ import urllib
...
@@ -21,7 +21,7 @@ import urllib
from
urllib.request
import
Request
,
urlopen
from
urllib.request
import
Request
,
urlopen
import
mimetypes
import
mimetypes
import
logging
import
logging
import
binascii
from
binascii
import
hexlify
import
certifi
import
certifi
import
nbxmpp
import
nbxmpp
...
@@ -35,10 +35,7 @@ from dialogs import FileChooserDialog, ErrorDialog
...
@@ -35,10 +35,7 @@ from dialogs import FileChooserDialog, ErrorDialog
log
=
logging
.
getLogger
(
'
gajim.plugin_system.httpupload
'
)
log
=
logging
.
getLogger
(
'
gajim.plugin_system.httpupload
'
)
try
:
try
:
if
os
.
name
==
'
nt
'
:
from
cryptography.hazmat.backends
import
default_backend
from
cryptography.hazmat.backends.openssl
import
backend
else
:
from
cryptography.hazmat.backends
import
default_backend
from
cryptography.hazmat.primitives.ciphers
import
Cipher
from
cryptography.hazmat.primitives.ciphers
import
Cipher
from
cryptography.hazmat.primitives.ciphers
import
algorithms
from
cryptography.hazmat.primitives.ciphers
import
algorithms
from
cryptography.hazmat.primitives.ciphers.modes
import
GCM
from
cryptography.hazmat.primitives.ciphers.modes
import
GCM
...
@@ -172,8 +169,8 @@ class Base(object):
...
@@ -172,8 +169,8 @@ class Base(object):
if
type
(
plugin
).
__name__
==
'
OmemoPlugin
'
:
if
type
(
plugin
).
__name__
==
'
OmemoPlugin
'
:
state
=
plugin
.
get_omemo_state
(
self
.
account
)
state
=
plugin
.
get_omemo_state
(
self
.
account
)
encryption
=
state
.
encryption
.
is_active
(
jid
)
encryption
=
state
.
encryption
.
is_active
(
jid
)
log
.
info
(
'
Encryption is: %s
'
,
encryption
)
log
.
info
(
'
Encryption is: %s
'
,
bool
(
encryption
)
)
return
encryption
return
bool
(
encryption
)
log
.
info
(
'
OMEMO not found, encryption disabled
'
)
log
.
info
(
'
OMEMO not found, encryption disabled
'
)
return
False
return
False
...
@@ -298,7 +295,7 @@ class Base(object):
...
@@ -298,7 +295,7 @@ class Base(object):
transfer
=
urlopen
(
request
,
timeout
=
30
)
transfer
=
urlopen
(
request
,
timeout
=
30
)
file
.
stream
.
close
()
file
.
stream
.
close
()
log
.
info
(
'
Urllib upload request done, response code: %s
'
,
log
.
info
(
'
Urllib upload request done, response code: %s
'
,
transfer
.
getcode
())
transfer
.
getcode
())
GLib
.
idle_add
(
self
.
upload_complete
,
transfer
.
getcode
(),
file
)
GLib
.
idle_add
(
self
.
upload_complete
,
transfer
.
getcode
(),
file
)
return
return
except
UploadAbortedException
as
exc
:
except
UploadAbortedException
as
exc
:
...
@@ -322,7 +319,7 @@ class Base(object):
...
@@ -322,7 +319,7 @@ class Base(object):
log
.
info
(
"
Upload completed successfully
"
)
log
.
info
(
"
Upload completed successfully
"
)
message
=
file
.
get
message
=
file
.
get
if
file
.
encrypted
:
if
file
.
encrypted
:
message
+=
'
#
'
+
binascii
.
hexlify
(
file
.
iv
+
file
.
key
)
message
+=
'
#
'
+
hexlify
(
file
.
iv
+
file
.
key
)
.
decode
(
'
utf-8
'
)
file
.
control
.
send_message
(
message
=
message
)
file
.
control
.
send_message
(
message
=
message
)
file
.
control
.
msg_textview
.
grab_focus
()
file
.
control
.
msg_textview
.
grab_focus
()
else
:
else
:
...
@@ -353,17 +350,13 @@ class StreamFileWithProgress:
...
@@ -353,17 +350,13 @@ class StreamFileWithProgress:
def
__init__
(
self
,
file
,
mode
,
*
args
):
def
__init__
(
self
,
file
,
mode
,
*
args
):
self
.
event
=
file
.
event
self
.
event
=
file
.
event
self
.
backing
=
open
(
file
.
path
,
mode
)
self
.
backing
=
open
(
file
.
path
,
mode
)
self
.
encrypted
_upload
=
file
.
encrypted
self
.
encrypted
=
file
.
encrypted
self
.
backing
.
seek
(
0
,
os
.
SEEK_END
)
self
.
backing
.
seek
(
0
,
os
.
SEEK_END
)
if
self
.
encrypted_upload
:
if
self
.
encrypted
:
if
os
.
name
==
'
nt
'
:
self
.
backend
=
backend
else
:
self
.
backend
=
default_backend
()
self
.
encryptor
=
Cipher
(
self
.
encryptor
=
Cipher
(
algorithms
.
AES
(
file
.
key
),
algorithms
.
AES
(
file
.
key
),
GCM
(
file
.
iv
),
GCM
(
file
.
iv
),
backend
=
self
.
backend
).
encryptor
()
backend
=
default_
backend
()
).
encryptor
()
self
.
_total
=
self
.
backing
.
tell
()
+
TAGSIZE
self
.
_total
=
self
.
backing
.
tell
()
+
TAGSIZE
else
:
else
:
self
.
_total
=
self
.
backing
.
tell
()
self
.
_total
=
self
.
backing
.
tell
()
...
@@ -378,7 +371,7 @@ class StreamFileWithProgress:
...
@@ -378,7 +371,7 @@ class StreamFileWithProgress:
def
read
(
self
,
size
):
def
read
(
self
,
size
):
if
self
.
event
.
isSet
():
if
self
.
event
.
isSet
():
raise
UploadAbortedException
raise
UploadAbortedException
if
self
.
encrypted
_upload
:
if
self
.
encrypted
:
data
=
self
.
backing
.
read
(
size
)
data
=
self
.
backing
.
read
(
size
)
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
data
=
self
.
encryptor
.
update
(
data
)
data
=
self
.
encryptor
.
update
(
data
)
...
@@ -415,7 +408,6 @@ class ProgressWindow:
...
@@ -415,7 +408,6 @@ class ProgressWindow:
self
.
dialog
.
set_title
(
'
HTTP Upload
'
)
self
.
dialog
.
set_title
(
'
HTTP Upload
'
)
self
.
label
=
self
.
xml
.
get_object
(
'
label
'
)
self
.
label
=
self
.
xml
.
get_object
(
'
label
'
)
self
.
label
.
set_text
(
_
(
'
Requesting HTTP Upload Slot...
'
))
self
.
label
.
set_text
(
_
(
'
Requesting HTTP Upload Slot...
'
))
# self.label.set_markup('<big>' + during_text + '</big>')
self
.
progressbar
=
self
.
xml
.
get_object
(
'
progressbar
'
)
self
.
progressbar
=
self
.
xml
.
get_object
(
'
progressbar
'
)
self
.
dialog
.
show_all
()
self
.
dialog
.
show_all
()
self
.
xml
.
connect_signals
(
self
)
self
.
xml
.
connect_signals
(
self
)
...
...
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