Browse Source

Refactor PKI mismatch logic

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

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

@ -74,19 +74,22 @@ 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
) !== fromByteArray(nodeWithUser.user?.publicKey ?? new Uint8Array())
) {
console.warn(
`Node ${nodeWithUser.num} has a different public key than expected`,
); );
nodeDB.setNodeError(nodeWithUser.num, "MISMATCH_PKI"); const newPublicKey = fromByteArray(
nodeWithUser.user?.publicKey ?? new Uint8Array(),
);
if (oldPublicKey !== newPublicKey) {
console.warn(
`Node ${nodeWithUser.user?.longName} (${nodeWithUser.num}) has a different public key than expected: Expected ${oldPublicKey} but got ${newPublicKey}`,
);
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