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

@ -64,7 +64,7 @@ class LokiFileServerAPI {
// go through each user and find deviceMap annotations // go through each user and find deviceMap annotations
const notFoundUsers = []; const notFoundUsers = [];
users.forEach(user => { await Promise.all(users.map(async user => {
let found = false; let found = false;
if (!user.annotations || !user.annotations.length) { if (!user.annotations || !user.annotations.length) {
log.info( log.info(
@ -72,27 +72,12 @@ class LokiFileServerAPI {
); );
return; return;
} }
user.annotations.forEach(note => { const mappingNote = user.annotations.find(note => note.type === DEVICE_MAPPING_ANNOTATION_KEY);
if (note.type !== 'network.loki.messenger.devicemapping') { const { authorisations } = mappingNote.value;
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;
if (!Array.isArray(authorisations)) { if (!Array.isArray(authorisations)) {
return; return;
} }
authorisations.forEach(auth => { await Promise.all(authorisations.map(async auth => {
// log.info('devmap auth', auth);
// only skip, if in secondary search mode // only skip, if in secondary search mode
if (isRequest && auth.secondaryDevicePubKey !== user.username) { if (isRequest && auth.secondaryDevicePubKey !== user.username) {
// this is not the authorization we're looking for // this is not the authorization we're looking for
@ -101,38 +86,17 @@ class LokiFileServerAPI {
); );
return; return;
} }
// log.info('auth', auth); const valid = await libloki.crypto.validateAuthorisation(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
);
// log.info('auth is valid for', user.username) // log.info('auth is valid for', user.username)
if (iterator(user.username, auth)) { if (iterator(user.username, auth)) {
found = true; found = true;
} }
} catch (e) { })); // end map authorisations
log.warn(
`Invalid signature on pubkey ${user.username} authorization ${
auth.secondaryDevicePubKey
} isRequest ${isRequest}`
);
}
}); // end forEach authorisations
}); // end forEach annotations
if (!found) { if (!found) {
notFoundUsers.push(user.username); notFoundUsers.push(user.username);
} }
}); // end forEach users })); // end map users
// log.info('done with users', users.length); // log.info('done with users', users.length);
return notFoundUsers; return notFoundUsers;
} }

Loading…
Cancel
Save