blob: 206511a4a063bcc955db8de6bb1e498f55a2e10a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
module.exports = (socket, data) => {
if (!data.username) {
socket.send(JSON.stringify({error:"MISSING_OPERAND", fatal: false}));
console.log("[" + socket.id + "] Missing 'username' value");
return;
}
if (!keys[data.username]) {
socket.send(JSON.stringify({error:"INVALID_USER", fatal: false}));
console.log("[" + socket.id + "] Invalid 'username' value");
return;
}
let validKeys = {};
let validDevices = userCredentials.filter((i) => {
return i.id === data.username;
})[0].devices.map((i) => { return i.id; });
for (let keyId of Object.keys(keys[data.username])) {
if (validDevices.includes(keyId)) validKeys[keyId] = keys[data.username][keyId];
}
socket.send(JSON.stringify({error:null, success:true, fatal: false, keys: validKeys}));
console.log("[" + socket.id + "] Gathered public keys for " + data.username);
}
|