Merge pull request #1 from BeaudanBrown/public-incoming

Prepare for public sync
pull/539/head
Ryan Tharp 6 years ago committed by GitHub
commit a7b1540fb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -836,7 +836,11 @@ class LokiPublicChannelAPI {
params,
});
if (!res.err && res.response) {
if (res.err || !res.response) {
return;
}
let receivedAt = new Date().getTime();
const pubKeys = [];
let pendingMessages = [];
@ -943,8 +947,9 @@ class LokiPublicChannelAPI {
);
this.conversation.setLastRetrievedMessage(this.lastGot);
if (pendingMessages.length) {
// console.log('premultiDeviceResults', pubKeys);
if (!pendingMessages.length) {
return;
}
if (pubKeys.length) {
// this will set slavePrimaryMap
const verifiedPrimaryPKs = await lokiFileServerAPI.verifyPrimaryPubKeys(
@ -984,7 +989,6 @@ class LokiPublicChannelAPI {
const verifiedDeviceResults = await this.serverAPI.getUsers(
verifiedPrimaryPKs
);
// console.log('verifiedDeviceResults', verifiedDeviceResults)
// go through verifiedDeviceResults
const newPrimaryUserProfileName = {};
@ -1020,8 +1024,6 @@ class LokiPublicChannelAPI {
});
} // end if there are pending pubkeys to look up
// console.log('pendingMessages len', pendingMessages.length);
// console.log('pendingMessages', pendingMessages);
// find messages for original slave key using slavePrimaryMap
if (pendingMessages.length) {
const { slavePrimaryMap } = this.serverAPI.chatAPI;
@ -1054,8 +1056,6 @@ class LokiPublicChannelAPI {
}
pendingMessages = [];
}
}
}
static getPreviewFromAnnotation(annotation) {
const preview = {

@ -64,7 +64,7 @@ class LokiFileServerAPI {
// go through each user and find deviceMap annotations
const notFoundUsers = [];
users.forEach(user => {
await Promise.all(users.map(async user => {
let found = false;
if (!user.annotations || !user.annotations.length) {
log.info(
@ -72,27 +72,12 @@ class LokiFileServerAPI {
);
return;
}
user.annotations.forEach(note => {
if (note.type !== 'network.loki.messenger.devicemapping') {
return;
}
// isn't desired type
// request is slave => primary type...
if (
(isRequest && note.value.isPrimary !== '0') ||
(!isRequest && note.value.isPrimary === '0')
) {
/* log.info(`verifyUserObjectDeviceMap found wrong type of` +
`relationship ${user.username}`); */
// console.log(`https://file.lokinet.org/users/@${user.username}?prettyPrint=1&include_annotations=1`);
return;
}
const { authorisations } = note.value;
const mappingNote = user.annotations.find(note => note.type === DEVICE_MAPPING_ANNOTATION_KEY);
const { authorisations } = mappingNote.value;
if (!Array.isArray(authorisations)) {
return;
}
authorisations.forEach(auth => {
// log.info('devmap auth', auth);
await Promise.all(authorisations.map(async auth => {
// only skip, if in secondary search mode
if (isRequest && auth.secondaryDevicePubKey !== user.username) {
// this is not the authorization we're looking for
@ -101,38 +86,17 @@ class LokiFileServerAPI {
);
return;
}
// log.info('auth', auth);
try {
// request (secondary wants to be paired with this primary)
// grant (primary approves this secondary)
window.libloki.crypto.verifyPairingSignature(
auth.primaryDevicePubKey,
auth.secondaryDevicePubKey,
dcodeIO.ByteBuffer.wrap(
isRequest ? auth.requestSignature : auth.grantSignature,
'base64'
).toArrayBuffer(),
isRequest
? textsecure.protobuf.PairingAuthorisationMessage.Type.REQUEST
: textsecure.protobuf.PairingAuthorisationMessage.Type.GRANT
);
const valid = await libloki.crypto.validateAuthorisation(auth);
// log.info('auth is valid for', user.username)
if (iterator(user.username, auth)) {
found = true;
}
} catch (e) {
log.warn(
`Invalid signature on pubkey ${user.username} authorization ${
auth.secondaryDevicePubKey
} isRequest ${isRequest}`
);
}
}); // end forEach authorisations
}); // end forEach annotations
})); // end map authorisations
if (!found) {
notFoundUsers.push(user.username);
}
}); // end forEach users
})); // end map users
// log.info('done with users', users.length);
return notFoundUsers;
}

Loading…
Cancel
Save