Commit 7bb7f8f4 authored by JC Brand's avatar JC Brand

Can now successfully send an encrypted stanza

updates #497
parent c1123fd6
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
}, },
buildSessions (devices) { buildSessions (devices) {
return Promise.all(devices.map(device => this.buildSession(device))); return Promise.all(devices.map(device => this.buildSession(device))).then(() => devices);
}, },
encryptMessage (plaintext) { encryptMessage (plaintext) {
...@@ -330,14 +330,10 @@ ...@@ -330,14 +330,10 @@
encryptKey (plaintext, device) { encryptKey (plaintext, device) {
const { _converse } = this.__super__, const { _converse } = this.__super__,
address = new libsignal.SignalProtocolAddress(this.get('jid'), device.get('id')), address = new libsignal.SignalProtocolAddress(device.get('jid'), device.get('id')),
session_cipher = new window.libsignal.SessionCipher(_converse.omemo_store, address); session_cipher = new window.libsignal.SessionCipher(_converse.omemo_store, address);
return new Promise((resolve, reject) => { return session_cipher.encrypt(plaintext).then(payload => ({'payload': payload, 'device': device}));
session_cipher.encrypt(plaintext)
.then(payload => resolve({'payload': payload, 'device': device}))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}, },
addKeysToMessageStanza (stanza, dicts, iv) { addKeysToMessageStanza (stanza, dicts, iv) {
...@@ -380,7 +376,7 @@ ...@@ -380,7 +376,7 @@
.c('encrypted', {'xmlns': Strophe.NS.OMEMO}) .c('encrypted', {'xmlns': Strophe.NS.OMEMO})
.c('header', {'sid': _converse.omemo_store.get('device_id')}); .c('header', {'sid': _converse.omemo_store.get('device_id')});
return this.encryptMessage(message).then((obj) => { return this.encryptMessage(message).then(obj => {
// The 16 bytes key and the GCM authentication tag (The tag // The 16 bytes key and the GCM authentication tag (The tag
// SHOULD have at least 128 bit) are concatenated and for each // SHOULD have at least 128 bit) are concatenated and for each
// intended recipient device, i.e. both own devices as well as // intended recipient device, i.e. both own devices as well as
...@@ -394,7 +390,6 @@ ...@@ -394,7 +390,6 @@
return Promise.all(promises) return Promise.all(promises)
.then((dicts) => this.addKeysToMessageStanza(stanza, dicts, obj.iv)) .then((dicts) => this.addKeysToMessageStanza(stanza, dicts, obj.iv))
.then((stanza) => stanza.c('payload').t(obj.payload)) .then((stanza) => stanza.c('payload').t(obj.payload))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}); });
}, },
...@@ -406,12 +401,12 @@ ...@@ -406,12 +401,12 @@
this.getBundlesAndBuildSessions() this.getBundlesAndBuildSessions()
.then(devices => this.createOMEMOMessageStanza(message, devices)) .then(devices => this.createOMEMOMessageStanza(message, devices))
.then(stanza => this.sendMessageStanza(stanza)) .then(stanza => this.sendMessageStanza(stanza))
.catch((e) => { .catch(e => {
this.messages.create({ this.messages.create({
'message': __("Sorry, could not send the message due to an error.") + ` ${e.message}`, 'message': __("Sorry, could not send the message due to an error.") + ` ${e.message}`,
'type': 'error', 'type': 'error',
}); });
converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
}); });
} else { } else {
...@@ -527,7 +522,7 @@ ...@@ -527,7 +522,7 @@
}, },
getLocalRegistrationId () { getLocalRegistrationId () {
return Promise.resolve(this.get('device_id')); return Promise.resolve(parseInt(this.get('device_id'), 10));
}, },
isTrustedIdentity (identifier, identity_key, direction) { isTrustedIdentity (identifier, identity_key, direction) {
...@@ -863,10 +858,8 @@ ...@@ -863,10 +858,8 @@
.c('prekeys'); .c('prekeys');
_.forEach( _.forEach(
store.get('prekeys').slice(0, _converse.NUM_PREKEYS), store.get('prekeys').slice(0, _converse.NUM_PREKEYS),
(prekey) => { (prekey) => stanza.c('preKeyPublic', {'preKeyId': prekey.keyId}).t(prekey.keyPair.pubKey).up()
stanza.c('preKeyPublic', {'preKeyId': prekey.keyId}) );
.t(prekey.keyPair.pubKey).up();
});
return _converse.api.sendIQ(stanza); return _converse.api.sendIQ(stanza);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment