Merge pull request #52 from Mikunj/fix/pkb-type

Implemented new PKB type logic.
pull/55/head
sachaaaaa 6 years ago committed by GitHub
commit 96595a46d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -143,7 +143,7 @@
await Promise.all([signedKeyPromise, preKeyPromise]); await Promise.all([signedKeyPromise, preKeyPromise]);
} }
async function sendEmptyMessageWithPreKeys(pubKey) { async function sendFriendRequestAccepted(pubKey) {
// empty content message // empty content message
const content = new textsecure.protobuf.Content(); const content = new textsecure.protobuf.Content();
@ -155,6 +155,9 @@
log.info('empty message sent successfully'); log.info('empty message sent successfully');
} }
}; };
const options = {
preKeyBundleType: textsecure.protobuf.PreKeyBundleMessage.Type.FRIEND_REQUEST_ACCEPT,
};
// send an empty message. The logic in ougoing_message will attach the prekeys. // send an empty message. The logic in ougoing_message will attach the prekeys.
const outgoingMessage = new textsecure.OutgoingMessage( const outgoingMessage = new textsecure.OutgoingMessage(
null, // server null, // server
@ -162,7 +165,8 @@
[pubKey], // numbers [pubKey], // numbers
content, // message content, // message
true, // silent true, // silent
callback // callback callback, // callback
options
); );
await outgoingMessage.sendToNumber(pubKey); await outgoingMessage.sendToNumber(pubKey);
} }
@ -171,5 +175,5 @@
window.libloki.getPreKeyBundleForNumber = getPreKeyBundleForNumber; window.libloki.getPreKeyBundleForNumber = getPreKeyBundleForNumber;
window.libloki.FallBackDecryptionError = FallBackDecryptionError; window.libloki.FallBackDecryptionError = FallBackDecryptionError;
window.libloki.savePreKeyBundleForNumber = savePreKeyBundleForNumber; window.libloki.savePreKeyBundleForNumber = savePreKeyBundleForNumber;
window.libloki.sendEmptyMessageWithPreKeys = sendEmptyMessageWithPreKeys; window.libloki.sendFriendRequestAccepted = sendFriendRequestAccepted;
})(); })();

@ -1026,7 +1026,7 @@ MessageReceiver.prototype.extend({
} }
// Send a reply back // Send a reply back
libloki.sendEmptyMessageWithPreKeys(pubKey); libloki.sendFriendRequestAccepted(pubKey);
} }
window.log.info(`Friend request for ${pubKey} was ${message.friendStatus}`, message); window.log.info(`Friend request for ${pubKey} was ${message.friendStatus}`, message);
}, },
@ -1040,6 +1040,15 @@ MessageReceiver.prototype.extend({
window.log.info('Error getting conversation: ', envelope.source); window.log.info('Error getting conversation: ', envelope.source);
} }
// Check if the other user accepted our friend request
if (
envelope.preKeyBundleMessage &&
envelope.preKeyBundleMessage.type === textsecure.protobuf.PreKeyBundleMessage.Type.FRIEND_REQUEST_ACCEPT &&
conversation
) {
await conversation.onFriendRequestAccepted();
}
if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) {
return this.handleFriendRequestMessage(envelope, content.dataMessage); return this.handleFriendRequestMessage(envelope, content.dataMessage);
} else if ( } else if (
@ -1048,12 +1057,10 @@ MessageReceiver.prototype.extend({
// ref: libsignal-protocol.js:36120 // ref: libsignal-protocol.js:36120
envelope.type === textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE envelope.type === textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE
) { ) {
// We know for sure that keys are exchanged // If we get a cipher and we're already friends
if (conversation) { // then we set our key exchange to complete
if (conversation && conversation.isFriend()) {
await conversation.setKeyExchangeCompleted(true); await conversation.setKeyExchangeCompleted(true);
// TODO: We should probably set this based on the PKB type
await conversation.onFriendRequestAccepted();
} }
} }

@ -43,9 +43,10 @@ function OutgoingMessage(
this.failoverNumbers = []; this.failoverNumbers = [];
this.unidentifiedDeliveries = []; this.unidentifiedDeliveries = [];
const { numberInfo, senderCertificate } = options; const { numberInfo, senderCertificate, preKeyBundleType } = options;
this.numberInfo = numberInfo; this.numberInfo = numberInfo;
this.senderCertificate = senderCertificate; this.senderCertificate = senderCertificate;
this.preKeyBundleType = preKeyBundleType || textsecure.protobuf.PreKeyBundleMessage.Type.UNKOWN;
} }
OutgoingMessage.prototype = { OutgoingMessage.prototype = {
@ -290,6 +291,12 @@ OutgoingMessage.prototype = {
if (this.attachPrekeys) { if (this.attachPrekeys) {
// Encrypt them with the fallback // Encrypt them with the fallback
const preKeyBundleMessage = await libloki.getPreKeyBundleForNumber(number); const preKeyBundleMessage = await libloki.getPreKeyBundleForNumber(number);
preKeyBundleMessage.type = this.preKeyBundleType;
// If we have to use fallback encryption then this must be a friend request
if (this.fallBackEncryption)
preKeyBundleMessage.type = textsecure.protobuf.PreKeyBundleMessage.Type.FRIEND_REQUEST;
const textBundle = this.convertMessageToText(preKeyBundleMessage); const textBundle = this.convertMessageToText(preKeyBundleMessage);
const encryptedBundle = await fallBackEncryption.encrypt(textBundle); const encryptedBundle = await fallBackEncryption.encrypt(textBundle);
preKeys = { preKeyBundleMessage: encryptedBundle.body }; preKeys = { preKeyBundleMessage: encryptedBundle.body };

Loading…
Cancel
Save