Skip to content

Commit d282bc5

Browse files
atergagithub-actions[bot]sea-snake
authored
feat: Ensure passkeys cannot have duplicate pubkeys (#3626)
<!-- Make sure you talk to us before submitting changes. See CONTRIBUTING.md. --> # Motivation This PR enforces that public keys are unique for all (newly added) passkeys. The enforcement happens by maintaining a new stable index `passkey_public_key -> anchor_number` (for consistency w.r.t. the previously added `recovery_key_principal -> anchor_number` index). While registering a new passkey, this PR adds a precondition that enforces that it's not already present in that index, and then the index is extended with the public key of a passkey that is successfully registered. For existing passkeys, the index will be populated for all passkeys of all anchors in an arbitrary order. This means there might already be duplicate passkey public keys in II, and those will be kept, but new duplicates will not be allowed. This is reasonable, as existing duplicates are out of scope of the current threat model. # Changes * Added new stable index `lookup_anchor_with_passkey_pubkey_hash_memory` to track passkey public keys * Added validation checks in all device registration flows to prevent (new) duplicate passkey public keys * Introduced new error variants across API layers to handle duplicate public key scenarios # Tests Added tests to cover all passkey-based device creation flows: 1. `should_enforce_unique_passkey_pubkeys_and_free_them_on_change_and_remove` 2. `should_enforce_unique_passkey_pubkeys_in_registration_mode_flows` 3. `should_enforce_unique_passkey_pubkeys_in_legacy_flows` --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: sea-snake <104725312+sea-snake@users.noreply.github.com> Co-authored-by: sea-snake <sea-snake@outlook.com>
1 parent 6477b90 commit d282bc5

File tree

29 files changed

+1209
-197
lines changed

29 files changed

+1209
-197
lines changed

package-lock.json

Lines changed: 7 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frontend/src/lib/generated/internet_identity_idl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export const idlFactory = ({ IDL }) => {
114114
const AddTentativeDeviceResponse = IDL.Variant({
115115
'device_registration_mode_off' : IDL.Null,
116116
'another_device_tentatively_added' : IDL.Null,
117+
'passkey_with_this_public_key_is_already_used' : IDL.Null,
117118
'added_tentatively' : IDL.Record({
118119
'verification_code' : IDL.Text,
119120
'device_registration_timeout' : Timestamp,
@@ -177,6 +178,7 @@ export const idlFactory = ({ IDL }) => {
177178
'expiration' : Timestamp,
178179
});
179180
const AuthnMethodRegisterError = IDL.Variant({
181+
'PasskeyWithThisPublicKeyIsAlreadyUsed' : IDL.Null,
180182
'RegistrationModeOff' : IDL.Null,
181183
'RegistrationAlreadyInProgress' : IDL.Null,
182184
'NotSelfAuthenticating' : IDL.Principal,
@@ -190,12 +192,14 @@ export const idlFactory = ({ IDL }) => {
190192
'Unauthorized' : IDL.Principal,
191193
});
192194
const AuthnMethodRegistrationModeExitError = IDL.Variant({
195+
'PasskeyWithThisPublicKeyIsAlreadyUsed' : IDL.Null,
193196
'InternalCanisterError' : IDL.Text,
194197
'RegistrationModeOff' : IDL.Null,
195198
'Unauthorized' : IDL.Principal,
196199
'InvalidMetadata' : IDL.Text,
197200
});
198201
const AuthnMethodReplaceError = IDL.Variant({
202+
'PasskeyWithThisPublicKeyIsAlreadyUsed' : IDL.Null,
199203
'AuthnMethodNotFound' : IDL.Null,
200204
'InvalidMetadata' : IDL.Text,
201205
});

0 commit comments

Comments
 (0)