Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
264c9d71
Commit
264c9d71
authored
Aug 15, 2022
by
Tijmen de Mes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable import PGP keys dialog
parent
480d5ed5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
5 deletions
+85
-5
messages.py
blink/messages.py
+85
-5
No files found.
blink/messages.py
View file @
264c9d71
...
...
@@ -521,6 +521,32 @@ class MessageManager(object, metaclass=Singleton):
data
=
data
if
isinstance
(
data
,
bytes
)
else
data
.
encode
()
f
.
write
(
data
)
def
check_encryption
(
self
,
content_type
,
body
):
if
(
content_type
.
lower
()
.
startswith
(
'text/'
)
and
'-----BEGIN PGP MESSAGE-----'
in
body
and
body
.
strip
()
.
endswith
(
'-----END PGP MESSAGE-----'
)
and
content_type
!=
'text/pgp-private-key'
):
return
'OpenPGP'
else
:
return
None
def
_compare_public_key
(
self
,
account
,
public_key
):
settings
=
SIPSimpleSettings
()
id
=
account
.
id
.
replace
(
'/'
,
'_'
)
extension
=
'pubkey'
directory
=
os
.
path
.
join
(
settings
.
chat
.
keys_directory
.
normalized
,
'private'
)
filename
=
os
.
path
.
join
(
directory
,
f
'{id}.{extension}'
)
if
os
.
path
.
exists
(
filename
):
try
:
with
open
(
filename
)
as
f
:
content
=
f
.
read
()
except
Exception
as
e
:
pass
else
:
if
content
==
public_key
:
print
(
'Import skipped, public keys are the same'
)
return
True
return
False
def
_send_message
(
self
,
outgoing_message
):
self
.
_outgoing_message_queue
.
append
(
outgoing_message
)
self
.
_send_outgoing_messages
()
...
...
@@ -535,6 +561,40 @@ class MessageManager(object, metaclass=Singleton):
handler
=
getattr
(
self
,
'_NH_
%
s'
%
notification
.
name
,
Null
)
handler
(
notification
)
@
run_in_thread
(
'file-io'
)
def
_SH_ImportPGPKeys
(
self
,
request
,
decrypted_message
):
public_key
=
None
private_key
=
None
regex
=
"(?P<public_key>-----BEGIN PGP PUBLIC KEY BLOCK-----.*-----END PGP PUBLIC KEY BLOCK-----).*(?P<private_key>-----BEGIN PGP PRIVATE KEY BLOCK-----.*-----END PGP PRIVATE KEY BLOCK-----)"
matches
=
re
.
search
(
regex
,
decrypted_message
,
re
.
DOTALL
)
try
:
public_key
=
matches
.
group
(
'public_key'
)
private_key
=
matches
.
group
(
'private_key'
)
except
AttributeError
:
return
if
private_key
is
None
or
public_key
is
None
:
return
if
self
.
_compare_public_key
(
request
.
account
,
public_key
):
return
settings
=
SIPSimpleSettings
()
directory
=
os
.
path
.
join
(
settings
.
chat
.
keys_directory
.
normalized
,
'private'
)
filename
=
os
.
path
.
join
(
directory
,
request
.
account
.
id
)
makedirs
(
directory
)
with
open
(
f
'{filename}.privkey'
,
'wb'
)
as
f
:
f
.
write
(
str
(
private_key
)
.
encode
())
with
open
(
f
'{filename}.pubkey'
,
'wb'
)
as
f
:
f
.
write
(
str
(
public_key
)
.
encode
())
request
.
account
.
sms
.
private_key
=
f
'{filename}.privkey'
request
.
account
.
sms
.
public_key
=
f
'{filename}.pubkey'
request
.
account
.
save
()
def
_SH_ExportPGPKeys
(
self
,
request
,
message
):
account
=
request
.
account
from
blink.contacts
import
URIUtils
...
...
@@ -580,11 +640,31 @@ class MessageManager(object, metaclass=Singleton):
disposition
=
None
message_id
=
str
(
uuid
.
uuid4
())
if
(
content_type
.
lower
()
.
startswith
(
'text/'
)
and
'-----BEGIN PGP MESSAGE-----'
in
body
and
body
.
strip
()
.
endswith
(
'-----END PGP MESSAGE-----'
)
and
content_type
!=
'text/pgp-private-key'
):
return
encryption
=
self
.
check_encryption
(
content_type
,
body
)
if
encryption
==
'OpenPGP'
:
if
not
account
.
sms
.
enable_pgp
:
return
if
content_type
.
lower
()
==
'text/pgp-private-key'
:
if
not
account
.
sms
.
enable_pgp
:
return
regex
=
"(?P<public_key>-----BEGIN PGP PUBLIC KEY BLOCK-----.*-----END PGP PUBLIC KEY BLOCK-----)"
matches
=
re
.
search
(
regex
,
body
,
re
.
DOTALL
)
public_key
=
matches
.
group
(
'public_key'
)
if
self
.
_compare_public_key
(
account
,
public_key
):
return
for
request
in
self
.
pgp_requests
[
account
]:
request
.
dialog
.
hide
()
self
.
pgp_requests
.
remove
(
request
)
import_dialog
=
ImportDialog
()
incoming_request
=
ImportPrivateKeyRequest
(
import_dialog
,
body
,
account
)
incoming_request
.
accepted
.
connect
(
self
.
_SH_ImportPGPKeys
)
incoming_request
.
finished
.
connect
(
self
.
_SH_PGPRequestFinished
)
bisect
.
insort_right
(
self
.
pgp_requests
,
incoming_request
)
incoming_request
.
dialog
.
show
()
if
content_type
.
lower
()
==
'text/pgp-public-key'
:
# print('-- Received public key')
...
...
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