Browse Source

Refactor PKI mismatch logic

pull/780/head
philon- 11 months ago
parent
commit
b7a4fa4de0
  1. 19
      packages/web/src/core/subscriptions.ts

19
packages/web/src/core/subscriptions.ts

@ -74,20 +74,23 @@ export const subscribeAll = (
connection.events.onNodeInfoPacket.subscribe((nodeInfo) => { connection.events.onNodeInfoPacket.subscribe((nodeInfo) => {
const nodeWithUser = ensureDefaultUser(nodeInfo); const nodeWithUser = ensureDefaultUser(nodeInfo);
if ( if (nodeWithUser.num !== myNodeNum && nodeDB.getNode(nodeWithUser.num)) {
nodeWithUser.num !== myNodeNum && // Ignore my own node const oldPublicKey = fromByteArray(
nodeDB.getNode(nodeWithUser.num)?.user?.publicKey !== undefined && // Only flag if the old key is not undefined nodeDB.getNode(nodeWithUser.num)?.user?.publicKey ?? new Uint8Array(),
fromByteArray( );
nodeDB.getNode(nodeWithUser.num)?.user?.publicKey ?? new Uint8Array(), // ... and equal to the new key const newPublicKey = fromByteArray(
) !== fromByteArray(nodeWithUser.user?.publicKey ?? new Uint8Array()) nodeWithUser.user?.publicKey ?? new Uint8Array(),
) { );
if (oldPublicKey !== newPublicKey) {
console.warn( console.warn(
`Node ${nodeWithUser.num} has a different public key than expected`, `Node ${nodeWithUser.user?.longName} (${nodeWithUser.num}) has a different public key than expected: Expected ${oldPublicKey} but got ${newPublicKey}`,
); );
nodeDB.setNodeError(nodeWithUser.num, "MISMATCH_PKI"); nodeDB.setNodeError(nodeWithUser.num, "MISMATCH_PKI");
// TODO: Handle this error case properly (refactor PKI dialog?) // TODO: Handle this error case properly (refactor PKI dialog?)
} }
}
nodeDB.addNode(nodeWithUser); nodeDB.addNode(nodeWithUser);
}); });

Loading…
Cancel
Save