Skip to content

Commit 2d472e7

Browse files
committed
save
1 parent aef73ef commit 2d472e7

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

src/internet_identity/src/anchor_management/registration/registration_flow_v2.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::anchor_management::registration::captcha::{
44
use crate::anchor_management::registration::rate_limit::process_rate_limit;
55
use crate::anchor_management::registration::Base64;
66
use crate::anchor_management::{
7-
activity_bookkeeping, add_openid_credential_skip_checks, check_openid_credential_is_unique,
8-
post_operation_bookkeeping, set_name,
7+
self, activity_bookkeeping, add_openid_credential_skip_checks,
8+
check_openid_credential_is_unique, post_operation_bookkeeping, set_name,
99
};
1010
use crate::state::flow_states::RegistrationFlowState;
1111
use crate::storage::anchor::{Anchor, Device};
@@ -17,10 +17,10 @@ use ic_cdk::caller;
1717
use ic_stable_structures::Memory;
1818
use internet_identity_interface::archive::types::{DeviceDataWithoutAlias, Operation};
1919
use internet_identity_interface::internet_identity::types::{
20-
AuthnMethod, AuthorizationKey, CaptchaTrigger, CheckCaptchaArg, CheckCaptchaError,
21-
CreateIdentityData, DeviceData, DeviceWithUsage, IdRegFinishArg, IdRegFinishError,
22-
IdRegFinishResult, IdRegNextStepResult, IdRegStartError, IdentityNumber, OpenIDRegFinishArg,
23-
RegistrationFlowNextStep, StaticCaptchaTrigger,
20+
AuthnMethod, AuthnMethodData, AuthorizationKey, CaptchaTrigger, CheckCaptchaArg,
21+
CheckCaptchaError, CreateIdentityData, DeviceData, DeviceWithUsage, IdRegFinishArg,
22+
IdRegFinishError, IdRegFinishResult, IdRegNextStepResult, IdRegStartError, IdentityNumber,
23+
OpenIDRegFinishArg, RegistrationFlowNextStep, StaticCaptchaTrigger,
2424
};
2525

2626
impl RegistrationFlowState {
@@ -236,18 +236,6 @@ fn validate_identity_data<M: Memory + Clone>(
236236
) -> Result<ValidatedCreateIdentityData, IdRegFinishError> {
237237
match &arg {
238238
CreateIdentityData::PubkeyAuthn(arg) => {
239-
// Enforce global uniqueness of passkey pubkeys across all anchors.
240-
if let AuthnMethod::WebAuthn(webauthn) = &arg.authn_method.authn_method {
241-
if storage
242-
.lookup_anchor_with_passkey_pubkey(&webauthn.pubkey)
243-
.is_some()
244-
{
245-
return Err(IdRegFinishError::InvalidAuthnMethod(
246-
"passkey with this public key is already used".to_string(),
247-
));
248-
}
249-
}
250-
251239
Ok(ValidatedCreateIdentityData::PubkeyAuthn(arg.clone()))
252240
}
253241
CreateIdentityData::OpenID(openid_registration_data) => {
@@ -323,6 +311,20 @@ fn apply_identity_data(
323311
}
324312

325313
fn create_identity(arg: &CreateIdentityData, now: u64) -> Result<IdentityNumber, IdRegFinishError> {
314+
// Enforce global uniqueness of passkey pubkeys across all anchors.
315+
if let CreateIdentityData::PubkeyAuthn(IdRegFinishArg {
316+
authn_method:
317+
AuthnMethodData {
318+
authn_method: AuthnMethod::WebAuthn(webauthn),
319+
..
320+
},
321+
..
322+
}) = &arg
323+
{
324+
anchor_management::check_passkey_pubkey_is_not_used(&webauthn.pubkey)
325+
.map_err(|err| IdRegFinishError::InvalidAuthnMethod(err))?;
326+
}
327+
326328
let (identity_number, operation) = state::storage_borrow_mut(|storage| {
327329
let arg = validate_identity_data(storage, arg)?;
328330

src/internet_identity/src/anchor_management/tentative_device_registration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::state::RegistrationState::{
44
SessionTentativelyConfirmed,
55
};
66
use crate::state::TentativeDeviceRegistration;
7-
use crate::{secs_to_nanos, state};
7+
use crate::{anchor_management, secs_to_nanos, state};
88
use candid::{CandidType, Principal};
99
use ic_cdk::api::time;
1010
use ic_cdk::{call, trap};
@@ -101,6 +101,9 @@ pub async fn add_tentative_device(
101101
state: DeviceRegistrationModeActive,
102102
..
103103
} => {
104+
anchor_management::check_passkey_pubkey_is_not_used(&tentative_device.pubkey)
105+
.map_err(|_| AuthnMethodRegisterError::PasskeyWithThisPublicKeyIsAlreadyUsed)?;
106+
104107
registration.state = DeviceTentativelyAdded {
105108
tentative_device,
106109
failed_attempts: 0,

src/internet_identity/src/main.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ async fn add_tentative_device(
144144
anchor_number: AnchorNumber,
145145
device_data: DeviceData,
146146
) -> AddTentativeDeviceResponse {
147-
if anchor_management::check_passkey_pubkey_is_not_used(&device_data.pubkey).is_err() {
148-
return AddTentativeDeviceResponse::PasskeyWithThisPublicKeyIsAlreadyUsed;
149-
};
150-
151147
let result =
152148
tentative_device_registration::add_tentative_device(anchor_number, device_data).await;
153149
match result {
@@ -238,11 +234,9 @@ fn register(
238234

239235
#[update]
240236
fn add(anchor_number: AnchorNumber, device_data: DeviceData) {
241-
if let Err(err) = anchor_management::check_passkey_pubkey_is_not_used(&device_data.pubkey) {
242-
trap(&err);
243-
};
244-
245237
anchor_operation_with_authz_check(anchor_number, |anchor| {
238+
anchor_management::check_passkey_pubkey_is_not_used(&device_data.pubkey)?;
239+
246240
Ok::<_, String>(((), anchor_management::add_device(anchor, device_data)))
247241
})
248242
.unwrap_or_else(|err| trap(err.as_str()))
@@ -1108,9 +1102,6 @@ mod v2_api {
11081102
let device = DeviceWithUsage::try_from(authn_method)
11091103
.map_err(|err| AuthnMethodRegisterError::InvalidMetadata(err.to_string()))?;
11101104

1111-
anchor_management::check_passkey_pubkey_is_not_used(&device.pubkey)
1112-
.map_err(|_| AuthnMethodRegisterError::PasskeyWithThisPublicKeyIsAlreadyUsed)?;
1113-
11141105
tentative_device_registration::add_tentative_device(
11151106
identity_number,
11161107
DeviceData::from(device),

src/internet_identity/tests/integration/activity_stats/authn_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::openid;
22
use crate::v2_api::authn_method_test_helpers::{
33
create_identity_with_authn_method, create_identity_with_openid_credential,
4-
sample_webauthn_authn_method, test_authn_method,
4+
sample_webauthn_authn_method,
55
};
66
use candid::Principal;
77
use canister_tests::api::internet_identity as api;

0 commit comments

Comments
 (0)