Skip to content

Commit 2ca6f14

Browse files
committed
Restrict host key-writes to user ECC slots (block 117-132, keep backup)
Host OKSETPRIV requests may only target user slots (RSA 1-4, ECC 101-116). Reserved ECC slots 117-132 are rejected EXCEPT the designated backup key (slot 131 with the 0x80 backup-type flag), which the app sets via setBackupPassphrase. HMAC (129/130, YUBIAUTH/feature-report) and derivation (128/132, internal) use other paths that call set_private() directly and bypass this dispatch, so they remain unaffected.
1 parent 0de93a5 commit 2ca6f14

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

onlykey/okcore.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,23 @@ void recvmsg(int n)
441441
if (profilemode != NONENCRYPTEDPROFILE)
442442
{
443443
#ifdef STD_VERSION
444-
if (recv_buffer[0] != 0xBA)
444+
if (recv_buffer[0] != 0xBA) {
445+
// A host may only set keys in user slots: RSA 1-4 or ECC
446+
// 101-116. Reserved ECC slots 117-132 are off-limits to host
447+
// key writes, with ONE exception: the designated backup key
448+
// (slot 131 with the backup type flag 0x80), which the app
449+
// legitimately sets via setBackupPassphrase. HMAC (129/130,
450+
// set via the YUBIAUTH/feature-report handler) and derivation
451+
// (128/132, set internally) use other paths that call
452+
// set_private() directly and bypass this dispatch, so they
453+
// are unaffected either way.
454+
if (recv_buffer[5] >= 117 && recv_buffer[5] <= 132 &&
455+
!(recv_buffer[5] == RESERVED_KEY_DEFAULT_BACKUP && (recv_buffer[6] & 0x80))) {
456+
hidprint("Error cannot set key in reserved slot (117-132)");
457+
return;
458+
}
445459
set_private(recv_buffer);
460+
}
446461
#endif
447462
}
448463
}

0 commit comments

Comments
 (0)