fix(connect): throw away credentials unaccepted by device

This commit is contained in:
Marek Polak
2025-10-07 17:01:34 +02:00
committed by Marek Polák
parent 85b34688b2
commit 26ebf67f63
4 changed files with 18 additions and 2 deletions

View File

@@ -127,6 +127,17 @@ export const thpHandshake = async (device: Device, unlockPin = false) => {
encryptedPayload: handshakeCredentials.encryptedPayload,
});
if (!handshakeCompletion.message.state && handshakeCredentials.credentials) {
// Known credentials was used but not accepted by device -> throw them away
thpState.removePairingCredential(handshakeCredentials.credentials);
const { credential } = handshakeCredentials.credentials;
const index = settings?.knownCredentials?.findIndex(c => c.credential === credential) ?? -1;
if (index >= 0) {
settings?.knownCredentials?.splice(index, 1);
}
}
thpState.setIsPaired(!!handshakeCompletion.message.state);
thpState.setPhase('pairing');

View File

@@ -102,6 +102,11 @@ export class ThpState {
}
}
removePairingCredential({ credential }: ThpCredentials) {
const index = this._pairingCredentials.findIndex(c => c.credential === credential);
if (index >= 0) this._pairingCredentials.splice(index, 1);
}
setNfcSecret(secret: Buffer) {
this._nfcSecret = secret;
}

View File

@@ -118,7 +118,7 @@ export const handleHandshakeInit = ({
trezorEphemeralPubkey,
);
// and use first from the list (could be undefined)
const credentials: ThpCredentialResponse | undefined = allCredentials[0];
const credentials = allCredentials.length ? allCredentials[0] : undefined;
// 11.1 If found set (temp_host_static_privkey, temp_host_static_pubkey) = (host_static_privkey, host_static_pubkey).
// 11.2 If not found set (temp_host_static_privkey, temp_host_static_pubkey) = (X25519(0, B), 0).

View File

@@ -48,7 +48,7 @@ export type ThpHandshakeCompletionRequest = {
};
export type ThpHandshakeCompletionResponse = {
state: 0 | 1;
state: 0 | 1 | 2;
};
export type ThpMessageType = ThpProtobufMessageType & {