Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gajim-plugins
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
56
Issues
56
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gajim
gajim-plugins
Commits
37273d96
Commit
37273d96
authored
Nov 20, 2018
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[omemo] Publish bundle with id 'current'
Fixes #362
parent
6429cc9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
46 deletions
+33
-46
omemo/omemo_connection.py
omemo/omemo_connection.py
+10
-6
omemo/xmpp.py
omemo/xmpp.py
+23
-40
No files found.
omemo/omemo_connection.py
View file @
37273d96
...
...
@@ -16,8 +16,8 @@ from gajim.common.connection_handlers_events import MessageNotSentEvent
from
gajim.plugins.plugins_i18n
import
_
from
omemo.xmpp
import
(
NS_NOTIFY
,
NS_OMEMO
,
NS_EME
,
NS_HINTS
,
BundleInformationAnnouncement
,
BundleInformationQuery
,
DevicelistQuery
,
NS_NOTIFY
,
NS_OMEMO
,
NS_EME
,
NS_HINTS
,
NS_BUNDLES
,
BundleInformationQuery
,
DevicelistQuery
,
make_bundle
,
OmemoMessage
,
successful
,
unpack_device_bundle
,
unpack_device_list_update
,
unpack_encrypted
,
NS_DEVICE_LIST
)
from
omemo.omemo.state
import
OmemoState
...
...
@@ -811,12 +811,16 @@ class OMEMOConnection:
def
publish_bundle
(
self
):
""" Publish our bundle information to the PEP node """
bundle_announce
=
BundleInformationAnnouncement
(
self
.
omemo
.
bundle
,
self
.
omemo
.
own_device_id
)
bundle
=
make_bundle
(
self
.
omemo
.
bundle
)
node
=
'%s%s'
%
(
NS_BUNDLES
,
self
.
omemo
.
own_device_id
)
log
.
info
(
'%s => Publishing bundle ...'
,
self
.
account
)
self
.
send_with_callback
(
bundle_announce
,
self
.
handle_publish_result
)
def
handle_publish_result
(
self
,
stanza
):
con
=
app
.
connections
[
self
.
account
]
con
.
get_module
(
'PubSub'
).
send_pb_publish
(
''
,
node
,
bundle
,
'current'
,
cb
=
self
.
handle_publish_result
)
def
handle_publish_result
(
self
,
_con
,
stanza
):
""" Log if publishing our bundle was successful
Parameters
...
...
omemo/xmpp.py
View file @
37273d96
...
...
@@ -43,13 +43,6 @@ NS_HINTS = 'urn:xmpp:hints'
log
=
logging
.
getLogger
(
'gajim.plugin_system.omemo'
)
class
PublishNode
(
Node
):
def
__init__
(
self
,
node_str
,
data
):
assert
node_str
is
not
None
and
isinstance
(
data
,
Node
)
Node
.
__init__
(
self
,
tag
=
'publish'
,
attrs
=
{
'node'
:
node_str
})
self
.
addChild
(
'item'
).
addChild
(
node
=
data
)
class
PubsubNode
(
Node
):
def
__init__
(
self
,
data
):
assert
isinstance
(
data
,
Node
)
...
...
@@ -88,39 +81,6 @@ class BundleInformationQuery(Iq):
self
.
addChild
(
node
=
pubsub
)
class
BundleInformationAnnouncement
(
Iq
):
def
__init__
(
self
,
state_bundle
,
device_id
):
id_
=
app
.
get_an_id
()
attrs
=
{
'id'
:
id_
}
Iq
.
__init__
(
self
,
typ
=
'set'
,
attrs
=
attrs
)
bundle_node
=
self
.
make_bundle_node
(
state_bundle
)
publish
=
PublishNode
(
NS_BUNDLES
+
str
(
device_id
),
bundle_node
)
pubsub
=
PubsubNode
(
publish
)
self
.
addChild
(
node
=
pubsub
)
def
make_bundle_node
(
self
,
state_bundle
):
result
=
Node
(
'bundle'
,
attrs
=
{
'xmlns'
:
NS_OMEMO
})
prekey_pub_node
=
result
.
addChild
(
'signedPreKeyPublic'
,
attrs
=
{
'signedPreKeyId'
:
state_bundle
[
'signedPreKeyId'
]})
prekey_pub_node
.
addData
(
state_bundle
[
'signedPreKeyPublic'
]
.
decode
(
'utf-8'
))
prekey_sig_node
=
result
.
addChild
(
'signedPreKeySignature'
)
prekey_sig_node
.
addData
(
state_bundle
[
'signedPreKeySignature'
]
.
decode
(
'utf-8'
))
identity_key_node
=
result
.
addChild
(
'identityKey'
)
identity_key_node
.
addData
(
state_bundle
[
'identityKey'
].
decode
(
'utf-8'
))
prekeys
=
result
.
addChild
(
'prekeys'
)
for
key
in
state_bundle
[
'prekeys'
]:
prekeys
.
addChild
(
'preKeyPublic'
,
attrs
=
{
'preKeyId'
:
key
[
0
]})
\
.
addData
(
key
[
1
].
decode
(
'utf-8'
))
return
result
class
DevicelistQuery
(
Iq
):
def
__init__
(
self
,
contact_jid
):
id_
=
app
.
get_an_id
()
...
...
@@ -139,6 +99,29 @@ class DevicelistPEP(AbstractPEP):
return
({},
[])
def
make_bundle
(
state_bundle
):
result
=
Node
(
'bundle'
,
attrs
=
{
'xmlns'
:
NS_OMEMO
})
prekey_pub_node
=
result
.
addChild
(
'signedPreKeyPublic'
,
attrs
=
{
'signedPreKeyId'
:
state_bundle
[
'signedPreKeyId'
]})
prekey_pub_node
.
addData
(
state_bundle
[
'signedPreKeyPublic'
]
.
decode
(
'utf-8'
))
prekey_sig_node
=
result
.
addChild
(
'signedPreKeySignature'
)
prekey_sig_node
.
addData
(
state_bundle
[
'signedPreKeySignature'
]
.
decode
(
'utf-8'
))
identity_key_node
=
result
.
addChild
(
'identityKey'
)
identity_key_node
.
addData
(
state_bundle
[
'identityKey'
].
decode
(
'utf-8'
))
prekeys
=
result
.
addChild
(
'prekeys'
)
for
key
in
state_bundle
[
'prekeys'
]:
prekeys
.
addChild
(
'preKeyPublic'
,
attrs
=
{
'preKeyId'
:
key
[
0
]})
\
.
addData
(
key
[
1
].
decode
(
'utf-8'
))
return
result
@
log_calls
(
'OmemoPlugin'
)
def
unpack_device_bundle
(
bundle
,
device_id
):
pubsub
=
bundle
.
getTag
(
'pubsub'
,
namespace
=
NS_PUBSUB
)
...
...
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