Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
114e46df
Commit
114e46df
authored
Jul 22, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix broken test and refactor slightly. updates #497
parent
b80a77a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
58 deletions
+57
-58
dist/converse.js
dist/converse.js
+28
-30
spec/omemo.js
spec/omemo.js
+2
-2
src/converse-omemo.js
src/converse-omemo.js
+27
-26
No files found.
dist/converse.js
View file @
114e46df
...
...
@@ -73204,31 +73204,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
const TRUSTED = 1;
const UNTRUSTED = -1;
function getDevicesForContact(_converse, jid) {
return new Promise((resolve, reject) => {
_converse.api.waitUntil('OMEMOInitialized').then(() => {
let devicelist = _converse.devicelists.get(jid);
if (_.isNil(devicelist)) {
devicelist = _converse.devicelists.create({
'jid': jid
});
}
devicelist.fetchDevices().then(() => resolve(devicelist.devices));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function contactHasOMEMOSupport(_converse, jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
getDevicesForContact(_converse, jid).then(devices => {
resolve(devices.length > 0);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function parseBundle(bundle_el) {
/* Given an XML element representing a user's OMEMO bundle, parse it
* and return a map.
...
...
@@ -73266,9 +73241,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
getBundlesAndBuildSessions() {
const _converse = this.__super__._converse;
return new Promise((resolve, reject) => {
getDevicesForContact(this.get('jid')).then(devices => {
const promises = _.map(devices, device => device.getBundle());
_converse.getDevicesForContact(this.get('jid')).then(devices => {
const promises = devices.map(device => device.getBundle());
Promise.all(promises).then(() => {
this.buildSessions(devices).then(() => resolve(devices)).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
...
...
@@ -73361,7 +73335,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
renderOMEMOToolbarButton() {
const _converse = this.__super__._converse,
__ = _converse.__;
contactHasOMEMOSupport(_converse, this.model.get('jid')).then(support => {
_converse.contactHasOMEMOSupport(this.model.get('jid')).then(support => {
if (support) {
const icon = this.el.querySelector('.toggle-omemo'),
html = tpl_toolbar_omemo(_.extend(this.model.toJSON(), {
...
...
@@ -73398,6 +73373,29 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_converse.NUM_PREKEYS = 100; // Set here so that tests can override
_converse.getDevicesForContact = function (jid) {
return new Promise((resolve, reject) => {
_converse.api.waitUntil('OMEMOInitialized').then(() => {
let devicelist = _converse.devicelists.get(jid);
if (_.isNil(devicelist)) {
devicelist = _converse.devicelists.create({
'jid': jid
});
}
devicelist.fetchDevices().then(() => resolve(devicelist.devices));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
};
_converse.contactHasOMEMOSupport = function (jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
_converse.getDevicesForContact(jid).then(devices => resolve(devices.length > 0)).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
};
function generateDeviceID() {
/* Generates a device ID, making sure that it's unique */
const existing_ids = _converse.devicelists.get(_converse.bare_jid).devices.pluck('id');
...
...
@@ -73741,7 +73739,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'signedPreKeyId': signed_prekey.keyId
}).t(u.arrayBufferToBase64(signed_prekey.keyPair.pubKey)).up().c('signedPreKeySignature').t(u.arrayBufferToBase64(signed_prekey.signature)).up().c('identityKey').t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up().c('prekeys');
_.forEach(store.get('prekeys'), prekey => {
_.forEach(store.get('prekeys')
.slice(0, _converse.NUM_PREKEYS)
, prekey => {
stanza.c('preKeyPublic', {
'preKeyId': prekey.keyId
}).t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up();
spec/omemo.js
View file @
114e46df
...
...
@@ -326,6 +326,8 @@
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
_converse
.
NUM_PREKEYS
=
2
;
// Restrict to 2, otherwise the resulting stanza is too large to easily test
let
iq_stanza
;
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
...
...
@@ -339,8 +341,6 @@
return
node
;
}).
length
;
}).
then
(
function
()
{
_converse
.
NUM_PREKEYS
=
2
;
// Restrict to 2, otherwise the resulting stanza is too large to easily test
const
stanza
=
$iq
({
'
from
'
:
contact_jid
,
'
id
'
:
iq_stanza
.
getAttribute
(
'
id
'
),
...
...
src/converse-omemo.js
View file @
114e46df
...
...
@@ -27,28 +27,6 @@
const
UNTRUSTED
=
-
1
;
function
getDevicesForContact
(
_converse
,
jid
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
_converse
.
api
.
waitUntil
(
'
OMEMOInitialized
'
).
then
(()
=>
{
let
devicelist
=
_converse
.
devicelists
.
get
(
jid
);
if
(
_
.
isNil
(
devicelist
))
{
devicelist
=
_converse
.
devicelists
.
create
({
'
jid
'
:
jid
});
}
devicelist
.
fetchDevices
().
then
(()
=>
resolve
(
devicelist
.
devices
));
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
ERROR
));
});
}
function
contactHasOMEMOSupport
(
_converse
,
jid
)
{
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return
new
Promise
((
resolve
,
reject
)
=>
{
getDevicesForContact
(
_converse
,
jid
).
then
((
devices
)
=>
{
resolve
(
devices
.
length
>
0
)
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
ERROR
));
});
}
function
parseBundle
(
bundle_el
)
{
/* Given an XML element representing a user's OMEMO bundle, parse it
* and return a map.
...
...
@@ -92,9 +70,9 @@
getBundlesAndBuildSessions
()
{
const
{
_converse
}
=
this
.
__super__
;
return
new
Promise
((
resolve
,
reject
)
=>
{
getDevicesForContact
(
this
.
get
(
'
jid
'
))
_converse
.
getDevicesForContact
(
this
.
get
(
'
jid
'
))
.
then
((
devices
)
=>
{
const
promises
=
_
.
map
(
devices
,
(
device
)
=>
device
.
getBundle
());
const
promises
=
devices
.
map
(
(
device
)
=>
device
.
getBundle
());
Promise
.
all
(
promises
).
then
(()
=>
{
this
.
buildSessions
(
devices
)
.
then
(()
=>
resolve
(
devices
))
...
...
@@ -185,7 +163,7 @@
renderOMEMOToolbarButton
()
{
const
{
_converse
}
=
this
.
__super__
,
{
__
}
=
_converse
;
contactHasOMEMOSupport
(
_converse
,
this
.
model
.
get
(
'
jid
'
)).
then
((
support
)
=>
{
_converse
.
contactHasOMEMOSupport
(
this
.
model
.
get
(
'
jid
'
)).
then
((
support
)
=>
{
if
(
support
)
{
const
icon
=
this
.
el
.
querySelector
(
'
.toggle-omemo
'
),
html
=
tpl_toolbar_omemo
(
_
.
extend
(
this
.
model
.
toJSON
(),
{
'
__
'
:
__
}));
...
...
@@ -217,6 +195,29 @@
_converse
.
NUM_PREKEYS
=
100
;
// Set here so that tests can override
_converse
.
getDevicesForContact
=
function
(
jid
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
_converse
.
api
.
waitUntil
(
'
OMEMOInitialized
'
).
then
(()
=>
{
let
devicelist
=
_converse
.
devicelists
.
get
(
jid
);
if
(
_
.
isNil
(
devicelist
))
{
devicelist
=
_converse
.
devicelists
.
create
({
'
jid
'
:
jid
});
}
devicelist
.
fetchDevices
().
then
(()
=>
resolve
(
devicelist
.
devices
));
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
ERROR
));
});
}
_converse
.
contactHasOMEMOSupport
=
function
(
jid
)
{
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return
new
Promise
((
resolve
,
reject
)
=>
{
_converse
.
getDevicesForContact
(
jid
)
.
then
((
devices
)
=>
resolve
(
devices
.
length
>
0
))
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
ERROR
));
});
}
function
generateDeviceID
()
{
/* Generates a device ID, making sure that it's unique */
const
existing_ids
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
).
devices
.
pluck
(
'
id
'
);
...
...
@@ -535,7 +536,7 @@
.
t
(
u
.
arrayBufferToBase64
(
store
.
get
(
'
identity_keypair
'
).
pubKey
)).
up
()
.
c
(
'
prekeys
'
);
_
.
forEach
(
store
.
get
(
'
prekeys
'
),
store
.
get
(
'
prekeys
'
)
.
slice
(
0
,
_converse
.
NUM_PREKEYS
)
,
(
prekey
)
=>
{
stanza
.
c
(
'
preKeyPublic
'
,
{
'
preKeyId
'
:
prekey
.
keyId
})
.
t
(
u
.
arrayBufferToBase64
(
prekey
.
keyPair
.
pubKey
)).
up
();
...
...
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