Passkeys: sign in with a passkey (#334) #470
No files matched your search
@@ -99,6 +99,8 @@ pub enum Via {
|
||||
},
|
||||
/// The recovery administrator from the server's own configuration.
|
||||
Recovery,
|
||||
/// A passkey (passkeys spec, PK-11).
|
||||
Passkey,
|
||||
/// A migration's run, acting for the administrator who started it
|
||||
/// (migrations spec, MG-10).
|
||||
Migration {
|
||||
|
||||
@@ -66,6 +66,12 @@ impl ManagementApi for Server {
|
||||
let path = req.uri().path().split('/').skip(2).collect::<Vec<_>>();
|
||||
|
||||
match path.first().copied().unwrap_or_default() {
|
||||
// inbuxa: passkeys spec, PK-10: a sign-in challenge
|
||||
"auth" if is_post && path.get(1).copied() == Some("passkey") => {
|
||||
self.is_http_anonymous_request_allowed(session.remote_ip)
|
||||
.await?;
|
||||
crate::auth::passkey::challenge(self).await
|
||||
}
|
||||
"auth" if is_post => {
|
||||
self.is_http_anonymous_request_allowed(session.remote_ip)
|
||||
.await?;
|
||||
|
||||
@@ -100,7 +100,10 @@ pub trait OAuthApiHandler: Sync + Send {
|
||||
pub enum LoginRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
AuthCode {
|
||||
// inbuxa: empty when a passkey signs in
|
||||
#[serde(default)]
|
||||
account_name: String,
|
||||
#[serde(default)]
|
||||
account_secret: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
@@ -120,6 +123,9 @@ pub enum LoginRequest {
|
||||
state: Option<String>,
|
||||
#[serde(default)]
|
||||
resource: Vec<String>,
|
||||
// inbuxa: passkeys spec, PK-11: an assertion in place of the password
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
passkey: Option<crate::auth::passkey::PasskeyAssertion>,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
AuthDevice {
|
||||
@@ -191,6 +197,7 @@ impl OAuthApiHandler for Server {
|
||||
code_challenge,
|
||||
code_challenge_method,
|
||||
resource,
|
||||
passkey,
|
||||
..
|
||||
} => {
|
||||
// Validate clientId
|
||||
@@ -306,19 +313,25 @@ impl OAuthApiHandler for Server {
|
||||
}
|
||||
};
|
||||
|
||||
// Authenticate
|
||||
match self
|
||||
.authenticate(&AuthRequest {
|
||||
credentials: Credentials::Basic {
|
||||
username: account_name,
|
||||
secret: account_secret,
|
||||
mfa_token,
|
||||
},
|
||||
session_id: session.session_id,
|
||||
remote_ip: session.remote_ip,
|
||||
})
|
||||
.await
|
||||
{
|
||||
// Authenticate (inbuxa: or a passkey, PK-11)
|
||||
let authenticated = match &passkey {
|
||||
Some(assertion) => {
|
||||
crate::auth::passkey::sign_in(self, session, assertion).await
|
||||
}
|
||||
None => {
|
||||
self.authenticate(&AuthRequest {
|
||||
credentials: Credentials::Basic {
|
||||
username: account_name,
|
||||
secret: account_secret,
|
||||
mfa_token,
|
||||
},
|
||||
session_id: session.session_id,
|
||||
remote_ip: session.remote_ip,
|
||||
})
|
||||
.await
|
||||
}
|
||||
};
|
||||
match authenticated {
|
||||
Ok(access_token) => {
|
||||
// Registry-backed clients are validated once the account is known
|
||||
if stateless_client.is_none()
|
||||
|
||||
+285
-21
@@ -4,7 +4,10 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
//! inbuxa: passkey registration (passkeys spec, PK-6 to PK-8).
|
||||
//! inbuxa: passkeys (passkeys spec): registration (PK-6 to PK-8) and
|
||||
//! sign-in (PK-9 to PK-12).
|
||||
//!
|
||||
//! Registration:
|
||||
//!
|
||||
//! `inbuxa:Passkey/set` create hands back a URL to `/passkey/register` with
|
||||
//! a single-use ticket. That page posts here twice:
|
||||
@@ -18,6 +21,12 @@
|
||||
//!
|
||||
//! What `start` began waits in the in-memory store under the ticket, so any
|
||||
//! node can answer `finish`, and it's deleted as it's read: it's good once.
|
||||
//! Instead of the password, `start` takes one of the account's active
|
||||
//! passkeys.
|
||||
//!
|
||||
//! Sign-in: `POST /api/auth/passkey` hands out a challenge (PK-10), kept in
|
||||
//! the in-memory store for two minutes and good once; the login request then
|
||||
//! carries the browser's assertion in place of a name and password (PK-11).
|
||||
|
||||
use common::{
|
||||
KV_PASSKEY_CEREMONY, Server,
|
||||
@@ -25,22 +34,36 @@ use common::{
|
||||
};
|
||||
use directory::Credentials;
|
||||
use http_proto::{HttpResponse, HttpSessionData, JsonResponse, ToHttpResponse};
|
||||
use inbuxa_features::audit::Via;
|
||||
use inbuxa_features::passkey::{self, Activated, HANDLE_LEN, Passkey};
|
||||
use registry::schema::enums::Permission;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use store::{
|
||||
dispatch::lookup::KeyValue,
|
||||
rand::{RngExt, rng},
|
||||
rand::{RngExt, distr::Alphanumeric, rng},
|
||||
write::now,
|
||||
};
|
||||
use trc::AddContext;
|
||||
use webauthn_rs::prelude::{
|
||||
CreationChallengeResponse, Credential, CredentialID, PasskeyRegistration,
|
||||
RegisterPublicKeyCredential, Url, Uuid, Webauthn, WebauthnBuilder,
|
||||
CreationChallengeResponse, Credential, CredentialID, DiscoverableAuthentication,
|
||||
PasskeyRegistration, PublicKeyCredential, RegisterPublicKeyCredential,
|
||||
RequestChallengeResponse, Url, Uuid, Webauthn, WebauthnBuilder, WebauthnError,
|
||||
};
|
||||
use webauthn_rs_proto::ResidentKeyRequirement;
|
||||
|
||||
/// How long the browser has between `start` and `finish`.
|
||||
const CEREMONY_SECONDS: u64 = 300;
|
||||
/// How long a sign-in challenge lasts (PK-10).
|
||||
const CHALLENGE_SECONDS: u64 = 120;
|
||||
const CHALLENGE_ID_LEN: usize = 32;
|
||||
|
||||
/// What the browser answered a sign-in challenge with.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PasskeyAssertion {
|
||||
pub challenge_id: String,
|
||||
pub credential: Box<PublicKeyCredential>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(tag = "step", rename_all = "camelCase")]
|
||||
@@ -48,9 +71,13 @@ pub enum RegisterRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Start {
|
||||
ticket: String,
|
||||
#[serde(default)]
|
||||
password: String,
|
||||
#[serde(default)]
|
||||
mfa_token: Option<String>,
|
||||
/// One of the account's passkeys, in place of the password (PK-8).
|
||||
#[serde(default)]
|
||||
passkey: Option<PasskeyAssertion>,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Finish {
|
||||
@@ -117,7 +144,233 @@ pub fn relying_party(server: &Server) -> trc::Result<(Webauthn, String)> {
|
||||
}
|
||||
|
||||
fn ceremony_key(ticket: &str) -> Vec<u8> {
|
||||
KeyValue::<()>::build_key(KV_PASSKEY_CEREMONY, passkey::ticket_hash(ticket))
|
||||
let mut key = vec![b'r'];
|
||||
key.extend_from_slice(&passkey::ticket_hash(ticket));
|
||||
KeyValue::<()>::build_key(KV_PASSKEY_CEREMONY, key)
|
||||
}
|
||||
|
||||
fn challenge_key(id: &str) -> Vec<u8> {
|
||||
let mut key = vec![b'a'];
|
||||
key.extend_from_slice(id.as_bytes());
|
||||
KeyValue::<()>::build_key(KV_PASSKEY_CEREMONY, key)
|
||||
}
|
||||
|
||||
/// A sign-in challenge between the two requests.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct SignInCeremony {
|
||||
rp_id: String,
|
||||
state: DiscoverableAuthentication,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ChallengeResponse {
|
||||
challenge_id: String,
|
||||
options: Box<RequestChallengeResponse>,
|
||||
}
|
||||
|
||||
/// PK-10: a challenge for the login page or the registration page. The
|
||||
/// options name no credentials: the browser offers the passkeys it holds for
|
||||
/// this relying party.
|
||||
pub async fn challenge(server: &Server) -> trc::Result<HttpResponse> {
|
||||
let (webauthn, rp_id) = relying_party(server)?;
|
||||
let (options, state) = webauthn
|
||||
.start_discoverable_authentication()
|
||||
.map_err(|err| {
|
||||
trc::AuthEvent::Error
|
||||
.into_err()
|
||||
.details("Failed to start a passkey sign-in")
|
||||
.reason(err)
|
||||
})?;
|
||||
let challenge_id = rng()
|
||||
.sample_iter(Alphanumeric)
|
||||
.take(CHALLENGE_ID_LEN)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let ceremony = serde_json::to_string(&SignInCeremony { rp_id, state }).map_err(|err| {
|
||||
trc::StoreEvent::UnexpectedError
|
||||
.into_err()
|
||||
.details("Failed to serialize a passkey sign-in")
|
||||
.reason(err)
|
||||
})?;
|
||||
server
|
||||
.in_memory_store()
|
||||
.key_set(
|
||||
KeyValue::new(challenge_key(&challenge_id), ceremony.into_bytes())
|
||||
.expires(CHALLENGE_SECONDS),
|
||||
)
|
||||
.await?;
|
||||
Ok(JsonResponse::new(ChallengeResponse {
|
||||
challenge_id,
|
||||
options: Box::new(options),
|
||||
})
|
||||
.no_cache()
|
||||
.into_http_response())
|
||||
}
|
||||
|
||||
fn refused(reason: &'static str) -> trc::Error {
|
||||
trc::AuthEvent::Failed
|
||||
.into_err()
|
||||
.details("Passkey sign-in refused")
|
||||
.reason(reason)
|
||||
}
|
||||
|
||||
/// PK-11, PK-12: signs in with a passkey. Failures count toward the same
|
||||
/// limits and blocking as a wrong password, and a passkey needs no TOTP code.
|
||||
pub async fn sign_in(
|
||||
server: &Server,
|
||||
session: &HttpSessionData,
|
||||
assertion: &PasskeyAssertion,
|
||||
) -> trc::Result<AccessToken> {
|
||||
let result = check_assertion(server, session, assertion)
|
||||
.await
|
||||
.and_then(|token| {
|
||||
// AL-2: a locked account fails as a wrong passkey does
|
||||
if token.is_locked() {
|
||||
Err(refused("Account is locked").ctx(trc::Key::AccountId, token.account_id()))
|
||||
} else {
|
||||
token.assert_has_permission(Permission::Authenticate)
|
||||
}
|
||||
});
|
||||
let request = AuthRequest {
|
||||
credentials: Credentials::Bearer {
|
||||
username: None,
|
||||
token: String::new(),
|
||||
},
|
||||
session_id: session.session_id,
|
||||
remote_ip: session.remote_ip,
|
||||
};
|
||||
match result {
|
||||
Ok(token) => {
|
||||
trc::event!(
|
||||
Auth(trc::AuthEvent::Success),
|
||||
AccountId = token.account_id(),
|
||||
SpanId = session.session_id,
|
||||
Type = "passkey",
|
||||
);
|
||||
// AU-1.4, AU-1.5
|
||||
server.audit_sign_in(&request, &token).await;
|
||||
Ok(token)
|
||||
}
|
||||
Err(err) => {
|
||||
if matches!(err.as_ref(), trc::EventType::Auth(trc::AuthEvent::Failed))
|
||||
&& server.has_auth_fail2ban()
|
||||
&& server.is_auth_fail2banned(session.remote_ip, None).await?
|
||||
{
|
||||
Err(trc::SecurityEvent::AuthenticationBan
|
||||
.into_err()
|
||||
.ctx(trc::Key::RemoteIp, session.remote_ip))
|
||||
} else {
|
||||
Err(err.ctx(trc::Key::RemoteIp, session.remote_ip))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_assertion(
|
||||
server: &Server,
|
||||
session: &HttpSessionData,
|
||||
assertion: &PasskeyAssertion,
|
||||
) -> trc::Result<AccessToken> {
|
||||
// PK-10: good once
|
||||
if assertion.challenge_id.len() != CHALLENGE_ID_LEN {
|
||||
return Err(refused("Unknown passkey challenge"));
|
||||
}
|
||||
let key = challenge_key(&assertion.challenge_id);
|
||||
let Some(ceremony) = server
|
||||
.in_memory_store()
|
||||
.key_get::<String>(key.clone())
|
||||
.await?
|
||||
else {
|
||||
return Err(refused("Unknown, used or expired passkey challenge"));
|
||||
};
|
||||
server.in_memory_store().key_delete(key).await?;
|
||||
let ceremony = serde_json::from_str::<SignInCeremony>(&ceremony).map_err(|err| {
|
||||
trc::StoreEvent::DataCorruption
|
||||
.into_err()
|
||||
.details("Invalid passkey sign-in")
|
||||
.reason(err)
|
||||
})?;
|
||||
let (webauthn, rp_id) = relying_party(server)?;
|
||||
if rp_id != ceremony.rp_id {
|
||||
return Err(refused("The relying-party id changed during sign-in"));
|
||||
}
|
||||
|
||||
// The account by user handle, the passkey by credential id: both must agree
|
||||
let credential = &assertion.credential;
|
||||
let (handle, credential_id) = webauthn
|
||||
.identify_discoverable_authentication(credential)
|
||||
.map_err(|_| refused("No user handle in the passkey's answer"))?;
|
||||
let Some(mut record) = passkey::by_credential(server.store(), credential_id)
|
||||
.await?
|
||||
.filter(|p| p.state == passkey::State::Active)
|
||||
else {
|
||||
return Err(refused("Unknown passkey"));
|
||||
};
|
||||
if passkey::account_of_handle(server.store(), handle.as_bytes()).await?
|
||||
!= Some(record.account_id)
|
||||
{
|
||||
return Err(refused("The passkey belongs to another account")
|
||||
.ctx(trc::Key::AccountId, record.account_id));
|
||||
}
|
||||
// PK-4: a passkey works only for the relying-party id it was made for
|
||||
if record.rp_id != rp_id {
|
||||
return Err(
|
||||
refused("The passkey was registered for another relying-party id")
|
||||
.ctx(trc::Key::AccountId, record.account_id),
|
||||
);
|
||||
}
|
||||
let mut stored = serde_json::from_slice::<webauthn_rs::prelude::Passkey>(&record.public_key)
|
||||
.map_err(|err| {
|
||||
trc::StoreEvent::DataCorruption
|
||||
.into_err()
|
||||
.details("Invalid stored passkey")
|
||||
.reason(err)
|
||||
})?;
|
||||
|
||||
// The signature, the origin (PK-2), user verification and the counter
|
||||
let result = match webauthn.finish_discoverable_authentication_v2(
|
||||
credential,
|
||||
ceremony.state,
|
||||
Credential::from(stored.clone()),
|
||||
) {
|
||||
Ok(result) => result,
|
||||
Err(WebauthnError::CredentialPossibleCompromise) => {
|
||||
trc::event!(
|
||||
Auth(trc::AuthEvent::Failed),
|
||||
AccountId = record.account_id,
|
||||
Id = passkey::passkey_id(record.account_id, record.number),
|
||||
SpanId = session.session_id,
|
||||
Details = "Passkey counter went backwards: the passkey may be cloned",
|
||||
);
|
||||
return Err(refused("Passkey counter went backwards")
|
||||
.ctx(trc::Key::AccountId, record.account_id));
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(refused("The passkey's answer didn't check out")
|
||||
.ctx(trc::Key::AccountId, record.account_id)
|
||||
.details(err.to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
// Keep the new counter and flags, and when it was last used
|
||||
stored.update_credential(&result);
|
||||
record.sign_count = result.counter();
|
||||
record.backed_up = result.backup_state();
|
||||
record.last_used_at = Some(now());
|
||||
record.public_key = serde_json::to_vec(&stored).map_err(|err| {
|
||||
trc::StoreEvent::UnexpectedError
|
||||
.into_err()
|
||||
.details("Failed to serialize a passkey")
|
||||
.reason(err)
|
||||
})?;
|
||||
passkey::save(server.store(), &record).await?;
|
||||
|
||||
server
|
||||
.access_token(record.account_id)
|
||||
.await
|
||||
.and_then(|token| AccessToken::new(token, session.remote_ip))
|
||||
.map(|token| token.with_origin(Via::Passkey))
|
||||
}
|
||||
|
||||
pub trait PasskeyRegistrationHandler: Sync + Send {
|
||||
@@ -142,7 +395,8 @@ impl PasskeyRegistrationHandler for Server {
|
||||
ticket,
|
||||
password,
|
||||
mfa_token,
|
||||
} => start(self, session, &ticket, password, mfa_token).await?,
|
||||
passkey,
|
||||
} => start(self, session, &ticket, password, mfa_token, passkey).await?,
|
||||
RegisterRequest::Finish { ticket, credential } => {
|
||||
finish(self, &ticket, &credential).await?
|
||||
}
|
||||
@@ -157,6 +411,7 @@ async fn start(
|
||||
ticket: &str,
|
||||
password: String,
|
||||
mfa_token: Option<String>,
|
||||
assertion: Option<PasskeyAssertion>,
|
||||
) -> trc::Result<RegisterResponse> {
|
||||
let Some(pending) = passkey::by_ticket(server.store(), ticket, now()).await? else {
|
||||
return Ok(RegisterResponse::Expired);
|
||||
@@ -166,20 +421,26 @@ async fn start(
|
||||
.await
|
||||
.caused_by(trc::location!())?;
|
||||
|
||||
// PK-8: the password (and code) first. The sign-in limits and the
|
||||
// failure counting are the ones every sign-in goes through.
|
||||
let access_token: AccessToken = match server
|
||||
.authenticate(&AuthRequest {
|
||||
credentials: Credentials::Basic {
|
||||
username: account.name.to_string(),
|
||||
secret: password,
|
||||
mfa_token,
|
||||
},
|
||||
session_id: session.session_id,
|
||||
remote_ip: session.remote_ip,
|
||||
})
|
||||
.await
|
||||
{
|
||||
// PK-8: the password (and code), or an active passkey, first. The
|
||||
// sign-in limits and the failure counting are the ones every sign-in
|
||||
// goes through.
|
||||
let signed_in = match &assertion {
|
||||
Some(assertion) => sign_in(server, session, assertion).await,
|
||||
None => {
|
||||
server
|
||||
.authenticate(&AuthRequest {
|
||||
credentials: Credentials::Basic {
|
||||
username: account.name.to_string(),
|
||||
secret: password,
|
||||
mfa_token,
|
||||
},
|
||||
session_id: session.session_id,
|
||||
remote_ip: session.remote_ip,
|
||||
})
|
||||
.await
|
||||
}
|
||||
};
|
||||
let access_token: AccessToken = match signed_in {
|
||||
Ok(access_token) => access_token,
|
||||
Err(err) => {
|
||||
return match *err.as_ref() {
|
||||
@@ -195,7 +456,10 @@ async fn start(
|
||||
};
|
||||
}
|
||||
};
|
||||
if access_token.account_id() != pending.account_id {
|
||||
// An app password is for one app, not for adding ways to sign in
|
||||
if access_token.account_id() != pending.account_id
|
||||
|| matches!(access_token.origin(), Some(Via::AppPassword { .. }))
|
||||
{
|
||||
return Ok(RegisterResponse::Failure);
|
||||
}
|
||||
|
||||
|
||||
@@ -268,10 +268,15 @@ Building, one PR each:
|
||||
`POST /api/passkey/register` with a `start` step (ticket and password,
|
||||
plus the TOTP code when the account has one; anonymous, limited like the
|
||||
other sign-in requests) and a `finish` step. What `start` began waits in
|
||||
the in-memory store for up to 5 minutes and is good once. Until sign-in
|
||||
with a passkey exists (step 3), the page asks for the password only; the
|
||||
"or an active passkey" of PK-8 comes with it.
|
||||
3. Sign-in in the authorization-code flow, with autofill.
|
||||
the in-memory store for up to 5 minutes and is good once.
|
||||
3. Sign-in in the authorization-code flow: `POST /api/auth/passkey` for a
|
||||
challenge, the login request's `passkey` field (`challengeId` and the
|
||||
browser's assertion) in place of the name and password, autofill on the
|
||||
username field and a "Sign in with a passkey" button. The registration
|
||||
page takes an active passkey instead of the password (PK-8), and an app
|
||||
password no longer opens it. Sign-ins by passkey are recorded with
|
||||
`via: passkey`, and raise `auth.success` with type `passkey`; a counter
|
||||
that didn't go up fails and is logged as a possible clone.
|
||||
4. The device flow, the settings and policy, and the sign-in events.
|
||||
|
||||
Then the webmail and console pages.
|
||||
@@ -283,6 +283,13 @@
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* INBUXA (#334): the passkey button, under the main one */
|
||||
.btn.secondary {
|
||||
background: transparent;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
@@ -313,7 +320,7 @@
|
||||
<form class="fields" id="login-form" novalidate>
|
||||
<div class="field" id="field-username">
|
||||
<label for="username">Username</label>
|
||||
<input id="username" name="username" type="text" placeholder="[email protected]" autocomplete="username"
|
||||
<input id="username" name="username" type="text" placeholder="[email protected]" autocomplete="username webauthn"
|
||||
autocapitalize="none" autocorrect="off" spellcheck="false" required>
|
||||
</div>
|
||||
<div class="field" id="field-password">
|
||||
@@ -332,6 +339,7 @@
|
||||
pattern="\d{6}" autocomplete="one-time-code">
|
||||
</div>
|
||||
<button type="submit" class="btn" id="submit-btn">Sign in</button>
|
||||
<button type="button" class="btn secondary" id="passkey-btn" hidden>Sign in with a passkey</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -538,7 +546,13 @@
|
||||
? 'Sign in to approve this device.'
|
||||
: 'Enter your credentials to continue');
|
||||
}
|
||||
showError('Invalid username or password. Please try again.');
|
||||
if (usedPasskey) {
|
||||
usedPasskey = false;
|
||||
showError('That passkey didn\'t sign you in. Try again, or use your password.');
|
||||
startAutofill();
|
||||
} else {
|
||||
showError('Invalid username or password. Please try again.');
|
||||
}
|
||||
return;
|
||||
default:
|
||||
console.log('Unknown login response type:', resp);
|
||||
@@ -549,6 +563,7 @@
|
||||
function submitLogin(e) {
|
||||
if (e) e.preventDefault();
|
||||
clearAlert();
|
||||
usedPasskey = false;
|
||||
|
||||
var creds;
|
||||
if (inMfa) {
|
||||
@@ -622,6 +637,108 @@
|
||||
|
||||
$('login-form').addEventListener('submit', submitLogin);
|
||||
|
||||
// INBUXA (#334): passkeys (passkeys spec PK-9 to PK-11). The
|
||||
// browser's autofill offers them on the username field, and the
|
||||
// button asks for one directly. Each try fetches a challenge that
|
||||
// is good once, for two minutes.
|
||||
var usedPasskey = false;
|
||||
var autofill = null;
|
||||
var canPasskey = !isDevice && window.PublicKeyCredential && navigator.credentials &&
|
||||
typeof navigator.credentials.get === 'function' && window.AbortController;
|
||||
|
||||
function fromB64(s) {
|
||||
s = s.replace(/-/g, '+').replace(/_/g, '/');
|
||||
while (s.length % 4) s += '=';
|
||||
var bin = atob(s), out = new Uint8Array(bin.length);
|
||||
for (var i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
||||
return out.buffer;
|
||||
}
|
||||
function toB64(buf) {
|
||||
var bytes = new Uint8Array(buf), bin = '';
|
||||
for (var i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
|
||||
return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
||||
}
|
||||
|
||||
function getPasskey(mediation, signal) {
|
||||
return fetch('/api/auth/passkey', {
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
cache: 'no-store',
|
||||
headers: { 'Accept': 'application/json' }
|
||||
}).then(function (res) {
|
||||
if (res.status !== 200) throw new Error('http ' + res.status);
|
||||
return res.json();
|
||||
}).then(function (c) {
|
||||
var pk = c.options.publicKey;
|
||||
pk.challenge = fromB64(pk.challenge);
|
||||
(pk.allowCredentials || []).forEach(function (a) { a.id = fromB64(a.id); });
|
||||
var opts = { publicKey: pk };
|
||||
if (mediation) opts.mediation = mediation;
|
||||
if (signal) opts.signal = signal;
|
||||
return navigator.credentials.get(opts).then(function (cred) {
|
||||
var r = cred.response;
|
||||
return {
|
||||
challengeId: c.challengeId,
|
||||
credential: {
|
||||
id: cred.id,
|
||||
rawId: toB64(cred.rawId),
|
||||
type: cred.type,
|
||||
response: {
|
||||
authenticatorData: toB64(r.authenticatorData),
|
||||
clientDataJSON: toB64(r.clientDataJSON),
|
||||
signature: toB64(r.signature),
|
||||
userHandle: r.userHandle ? toB64(r.userHandle) : null
|
||||
},
|
||||
extensions: cred.getClientExtensionResults ? cred.getClientExtensionResults() : {}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function signInWithPasskey(assertion) {
|
||||
clearAlert();
|
||||
usedPasskey = true;
|
||||
var body = buildRequest({ account_name: '', account_secret: '' }, null);
|
||||
delete body.accountName;
|
||||
delete body.accountSecret;
|
||||
body.passkey = assertion;
|
||||
postLogin(body);
|
||||
}
|
||||
|
||||
function startAutofill() {
|
||||
if (!canPasskey || !PublicKeyCredential.isConditionalMediationAvailable) return;
|
||||
PublicKeyCredential.isConditionalMediationAvailable().then(function (ok) {
|
||||
if (!ok) return;
|
||||
if (autofill) autofill.abort();
|
||||
var mine = new AbortController();
|
||||
autofill = mine;
|
||||
// A challenge lasts two minutes: ask for a new one before then
|
||||
var renew = setTimeout(function () { if (autofill === mine) startAutofill(); }, 110000);
|
||||
getPasskey('conditional', mine.signal).then(function (assertion) {
|
||||
clearTimeout(renew);
|
||||
autofill = null;
|
||||
signInWithPasskey(assertion);
|
||||
}, function () { clearTimeout(renew); });
|
||||
}, function () {});
|
||||
}
|
||||
|
||||
if (canPasskey) {
|
||||
show($('passkey-btn'));
|
||||
$('passkey-btn').addEventListener('click', function () {
|
||||
if (autofill) { autofill.abort(); autofill = null; }
|
||||
clearAlert();
|
||||
getPasskey(null, null).then(signInWithPasskey, function (err) {
|
||||
console.log('Passkey sign-in did not finish:', err);
|
||||
if (!err || (err.name !== 'NotAllowedError' && err.name !== 'AbortError')) {
|
||||
showError('Passkeys aren\'t available right now. Use your password.');
|
||||
}
|
||||
startAutofill();
|
||||
});
|
||||
});
|
||||
startAutofill();
|
||||
}
|
||||
|
||||
// Digit-only filter on OTP and auto-submit on 6 digits.
|
||||
$('otp').addEventListener('input', function () {
|
||||
this.value = this.value.replace(/\D/g, '');
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="referrer" content="no-referrer"> <script>!function(){var e=new URLSearchParams(window.location.search).get("theme");"light"!==e&&"dark"!==e||document.documentElement.setAttribute("data-theme",e)}()</script> <title>Sign in · inbuxa</title> <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAR4ElEQVRo3u1aeXSV1bXf+5xvuHNyczOQGCAhCQQSEQEBEX3ocqJWUVwq8Vmxdnhaq3ZZO9hnW95qV63Vqu/J66CV95xaZBAFRHEqYAUEBFFAQsIQyUBC5tzc77v3O+fs98d37+UifXAjWavteu+srKzcm+87Z//23mcPv3OQiOAfebC/tQD/D+BvLcDfAgARKaWGcfOcyYQ41NeUUowlYUulECD98QsMpRQB8IwJ+RBnG9rTShFjzLasg4cPRwcGOGOMMSm/iPKISErJGOOM9fX2Nhw4KByHM6bU0KYaggVc9Wz5cNcdCx9v6ooWhkOXTKm+q25u7fhxACCl4vy4Ok6eFhEzFe/a7eDhpidfWLnm/Y86+gbGl0Ye+e4dF06fnGnkYQNARIiYiMdn3PStjvbWWyb5P+2S7zTaXDfvnHfpg3fdFggEhJQMURExxliGuKkZQKrkAxrnAPDvz7zws8WvxCzrskpzTC5butvyB3M+WPLbcDjHXS4bwbQsgSqlOOdvvrdpZ2Pzf80L3jYlRjG2s8t8fJv+8Auvvbt913O/+EF1VWXaKUXC7u0fUEQAYOq63+fTDNOVmwF0d3ff+W+PLn37w2tqAz+dZUyKxJmXzi32LXi5542Nm+rmznGXG04Arpk+2NMQMuDCEiF7yBJyciE8/2VxzVj/PWvbL/nGA0sf/kF+XnjV+k3bdzfua2o91hslICQydD0U8I0uDM84Z9y8yy7kiDd//xefHO741VWh7022AGgwgeYAXTzSyffAlt0NdXPnAGSl/iEAcA3a0tGT48VcDyhHQUvPYH6A5fhuGGeNzzX+eZWc852HGGDCGqyKsOoCfmEl82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ACafoyll5syYdfXPzri17r3xehULeATLKLigOnz8pNLFK2vEkX/X5V9NunCp6GJNWPHjOuNrvL+j64OPe+sPXr4yBcLqi8cIJI0dcOj189rjWHz7mcvGn2wLZAUAiApSWZRTljb71mqLZU5tXbzi2c1+opKD46ot9laVWRzfjLE0wEJzEzFFK/pRh5GAsWFPhH11iP/li95H2wJjSSbdfFJxYTRoTAzFIlqqnH9lZwO3RGVcJQY5tlhZVfrsuvHFH0/J1u366qOzGKwsvP1/EE+AI4IwydZZBraS+SwZuIzfU93HDgWdWxLv7Sq+eXXzVLOYxxaAFyDgiEYFSwwYgvTQwhpxLOwEI+bOn+itHNr2w5sCzrw40tY6aP0cLeMWghYylo8/JDkBSMtNgmtLine truncated
|
||||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="referrer" content="no-referrer"> <script>!function(){var e=new URLSearchParams(window.location.search).get("theme");"light"!==e&&"dark"!==e||document.documentElement.setAttribute("data-theme",e)}()</script> <title>Sign in · inbuxa</title> <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAR4ElEQVRo3u1aeXSV1bXf+5xvuHNyczOQGCAhCQQSEQEBEX3ocqJWUVwq8Vmxdnhaq3ZZO9hnW95qV63Vqu/J66CV95xaZBAFRHEqYAUEBFFAQsIQyUBC5tzc77v3O+fs98d37+UifXAjWavteu+srKzcm+87Z//23mcPv3OQiOAfebC/tQD/D+BvLcDfAgARKaWGcfOcyYQ41NeUUowlYUulECD98QsMpRQB8IwJ+RBnG9rTShFjzLasg4cPRwcGOGOMMSm/iPKISErJGOOM9fX2Nhw4KByHM6bU0KYaggVc9Wz5cNcdCx9v6ooWhkOXTKm+q25u7fhxACCl4vy4Ok6eFhEzFe/a7eDhpidfWLnm/Y86+gbGl0Ye+e4dF06fnGnkYQNARIiYiMdn3PStjvbWWyb5P+2S7zTaXDfvnHfpg3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EBDRITi2rf6+cxNV+aq/Dz0pIkJIgAQyIEJMOOJEK34hAIqII27f09De2bELPINOLOhXIoFCAQD5DASdioJgKFFy8dTwzEliMAbIUqsmf2OmBESocRazmnc0locBNAh6KSGACBmQTyMw4fVDZl8s9u7WnWPHlJ9RP5BmB7bv3e8krPpj7O43jXvPo2K/U+hVwOCdQ5puwBsHmKWUFgrYPX2UEJ9rjpN/ZLAsBKBx7sv1/umjwQtGm+sa1DcmOh5UcYlHEvrKPWzJR07IQx/s2X9HFhRdVrSKEgJ1vfzSKas37lz+iTOlzPv4pc4on3hyG3urQfgNUXntReaoYmnHkfMUc5KWPCNJEAACKgKPUTlv9o7fLJv524THY8ws5Wf51c+2eJbvEo4UJdNrWusP2Jadgn7GAAhACafoyll5syYdfXPzri17r3xehULeATLKLigOnz8pNLFK2vEkX/X5V9NunCp6GJNWPHjOuNrvL+j64OPe+sPXr4yBcLqi8cIJI0dcOj189rjWHz7mcvGn2wLZAUAiApSWZRTljb71mqLZU5tXbzi2c1+opKD46ot9laVWRzfjLE0wEJzEzFFK/pRh5GAsWFPhH11iP/li95H2wJjSSbdfFJxYTRoTAzFIlqqnH9lZwO3RGVcJQY5tlhZVfrsuvHFH0/J1u366qOzGKwsvP1/EE+AI4IwydZZBraS+SwZuIzfU93HDgWdWxLv7Sq+eXXzVLOYxxaAFyDgiEYFSwwYgvTQwhpxLOwEI+bOn+itHNr2w5sCzrw40tY6aP0cLeMWghYylo8/JDkBSMtNgmtLine truncated
|
||||
Binary file not shown.
@@ -283,6 +283,12 @@
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.btn.secondary {
|
||||
background: transparent;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
@@ -326,6 +332,7 @@
|
||||
pattern="\d{6}" autocomplete="one-time-code">
|
||||
</div>
|
||||
<button type="submit" class="btn" id="submit-btn">Continue</button>
|
||||
<button type="button" class="btn secondary" id="passkey-btn" hidden>Use a passkey you already have</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -467,20 +474,45 @@
|
||||
});
|
||||
}
|
||||
|
||||
function submit(e) {
|
||||
if (e) e.preventDefault();
|
||||
clearAlert();
|
||||
var password = $('password').value;
|
||||
if (!password) { showError('Enter your password.'); return; }
|
||||
var otp = $('otp').value.trim();
|
||||
var body = { step: 'start', ticket: ticket, password: password };
|
||||
if (!$('field-otp').hidden) {
|
||||
if (!/^\d{6}$/.test(otp)) { showError('Enter the 6-digit code.'); return; }
|
||||
body.mfaToken = otp;
|
||||
}
|
||||
function getPasskey() {
|
||||
return fetch('/api/auth/passkey', {
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
cache: 'no-store',
|
||||
headers: { 'Accept': 'application/json' }
|
||||
}).then(function (res) {
|
||||
if (res.status !== 200) throw new Error('http ' + res.status);
|
||||
return res.json();
|
||||
}).then(function (c) {
|
||||
var pk = c.options.publicKey;
|
||||
pk.challenge = fromB64(pk.challenge);
|
||||
(pk.allowCredentials || []).forEach(function (a) { a.id = fromB64(a.id); });
|
||||
return navigator.credentials.get({ publicKey: pk }).then(function (cred) {
|
||||
var r = cred.response;
|
||||
return {
|
||||
challengeId: c.challengeId,
|
||||
credential: {
|
||||
id: cred.id,
|
||||
rawId: toB64(cred.rawId),
|
||||
type: cred.type,
|
||||
response: {
|
||||
authenticatorData: toB64(r.authenticatorData),
|
||||
clientDataJSON: toB64(r.clientDataJSON),
|
||||
signature: toB64(r.signature),
|
||||
userHandle: r.userHandle ? toB64(r.userHandle) : null
|
||||
},
|
||||
extensions: cred.getClientExtensionResults ? cred.getClientExtensionResults() : {}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function begin(body, viaPasskey) {
|
||||
var btn = $('submit-btn');
|
||||
btn.disabled = true;
|
||||
post(body).then(function (json) {
|
||||
$('passkey-btn').disabled = true;
|
||||
return post(body).then(function (json) {
|
||||
switch (json.type) {
|
||||
case 'options':
|
||||
$('account').value = json.accountName;
|
||||
@@ -504,7 +536,11 @@
|
||||
expired();
|
||||
return;
|
||||
default:
|
||||
showError(!$('field-otp').hidden ? 'The password or code is wrong.' : 'The password is wrong.');
|
||||
if (viaPasskey) {
|
||||
showError('That passkey isn\'t one of this account\'s. Use your password.');
|
||||
} else {
|
||||
showError(!$('field-otp').hidden ? 'The password or code is wrong.' : 'The password is wrong.');
|
||||
}
|
||||
$('otp').value = '';
|
||||
}
|
||||
}).catch(function (err) {
|
||||
@@ -518,7 +554,40 @@
|
||||
}
|
||||
console.log('Passkey registration failed:', err);
|
||||
showError('Temporary server failure. If the problem persists, contact your administrator.');
|
||||
}).then(function () { btn.disabled = false; });
|
||||
}).then(function () {
|
||||
btn.disabled = false;
|
||||
$('passkey-btn').disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
function submit(e) {
|
||||
if (e) e.preventDefault();
|
||||
clearAlert();
|
||||
var password = $('password').value;
|
||||
if (!password) { showError('Enter your password.'); return; }
|
||||
var otp = $('otp').value.trim();
|
||||
var body = { step: 'start', ticket: ticket, password: password };
|
||||
if (!$('field-otp').hidden) {
|
||||
if (!/^\d{6}$/.test(otp)) { showError('Enter the 6-digit code.'); return; }
|
||||
body.mfaToken = otp;
|
||||
}
|
||||
begin(body, false);
|
||||
}
|
||||
|
||||
// PK-8: an active passkey of the account instead of the password
|
||||
if (navigator.credentials.get) {
|
||||
show($('passkey-btn'));
|
||||
$('passkey-btn').addEventListener('click', function () {
|
||||
clearAlert();
|
||||
getPasskey().then(function (assertion) {
|
||||
begin({ step: 'start', ticket: ticket, passkey: assertion }, true);
|
||||
}, function (err) {
|
||||
console.log('Passkey sign-in did not finish:', err);
|
||||
if (!err || (err.name !== 'NotAllowedError' && err.name !== 'AbortError')) {
|
||||
showError('Passkeys aren\'t available right now. Use your password.');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$('passkey-form').addEventListener('submit', submit);
|
||||
|
||||
@@ -1,481 +1 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<script>
|
||||
// INBUXA (#375): the app that opened this page can pass theme=light or
|
||||
// theme=dark so the page matches it; anything else follows the OS.
|
||||
(function () {
|
||||
var t = new URLSearchParams(window.location.search).get('theme');
|
||||
if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t);
|
||||
})();
|
||||
</script>
|
||||
<title>Add a passkey · inbuxa</title>
|
||||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAR4ElEQVRo3u1aeXSV1bXf+5xvuHNyczOQGCAhCQQSEQEBEX3ocqJWUVwq8Vmxdnhaq3ZZO9hnW95qV63Vqu/J66CV95xaZBAFRHEqYAUEBFFAQsIQyUBC5tzc77v3O+fs98d37+UifXAjWavteu+srKzcm+87Z//23mcPv3OQiOAfebC/tQD/D+BvLcDfAgARKaWGcfOcyYQ41NeUUowlYUulECD98QsMpRQB8IwJ+RBnG9rTShFjzLasg4cPRwcGOGOMMSm/iPKISErJGOOM9fX2Nhw4KByHM6bU0KYaggVc9Wz5cNcdCx9v6ooWhkOXTKm+q25u7fhxACCl4vy4Ok6eFhEzFe/a7eDhpidfWLnm/Y86+gbGl0Ye+e4dF06fnGnkYQNARIiYiMdn3PStjvbWWyb5P+2S7zTaXDfvnHfpg3fdFggEhJQMURExxliGuKkZQKrkAxrnAPDvz7zws8WvxCzrskpzTC5butvyB3M+WPLbcDjHXS4bwbQsgSqlOOdvvrdpZ2Pzf80L3jYlRjG2s8t8fJv+8Auvvbt913O/+EF1VWXaKUXC7u0fUEQAYOq63+fTDNOVmwF0d3ff+W+PLn37w2tqAz+dZUyKxJmXzi32LXi5542Nm+rmznGXG04Arpk+2NMQMuDCEiF7yBJyciE8/2Vxz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Gm+sa1DcmOh5UcYlHEvrKPWzJR07IQx/s2X9HFhRdVrSKEgJ1vfzSKas37lz+iTOlzPv4pc4on3hyG3urQfgNUXntReaoYmnHkfMUc5KWPCNJEAACKgKPUTlv9o7fLJv524THY8ws5Wf51c+2eJbvEo4UJdNrWusP2Jadgn7GAAhACafoyll5syYdfXPzri17r3xehULeATLKLigOnz8pNLFK2vEkX/X5V9NunCp6GJNWPHjOuNrvL+j64OPe+sPXr4yBcLqi8cIJI0dcOj189rjWHz7mcvGn2wLZAUAiApSWZRTljb71mqLZU5tXbzi2c1+opKD46ot9laVWRzfjLE0wEJzEzFFK/pRh5GAsWFPhH11iP/li95H2wJjSSbdfFJxYTRoTAzFIlqqnH9lZwO3RGVcJQY5tlhZVfrsuvHFH0/J1u366qOzGKwsvP1/EE+AI4IwydZZBraS+SwZuIzfU93HDgWdWxLv7Sq+eXXzVLOYxxaAFyDgiEYFSwwYgvTQwhpxLOwEI+bOn+itHNr2w5sCzrw40tY6aP0cLeMWghYylo8/JDkBSMtNgmtb2+l+aXnrdCOdUf+fWnEljRTQmohYwBIYgKeV5ZxxGU8vS8USaOn1w+qNmUd7Y+25tW/veZy+/HT1wpPzWq3NqK51BCxTBSYdkRASKtKA/cayn6YU1x7Z+UnDBuWU3f0kLhxJ9UcYYcnacxsianMsOADIAlhlcABA5l7YDDEquvcRfXvrZ8rf2P7mk+IrzR8yZxQwurThkpFBSinHO/Wbv9r2Hl7xOjhh7502RmeeQIhm1WIq5ydR2llV+lsycWxKklZo6tuAMFMmYFZ5akzuhQknx2Yq36x99Nt58zAgF3bqHFJBUms+DipqeW12/6I+Jrh7/yOL86WcToLQTqB0/zMNksZesODLXOjMARJnGTa9GUnKvCULt//WzzaveLLine truncated
|
||||
<style>
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0
|
||||
}
|
||||
:root {
|
||||
--bg: #f6f8fa;
|
||||
--card: #ffffff;
|
||||
--border: #e3e7ec;
|
||||
--text: #111827;
|
||||
--muted: #5b6472;
|
||||
--accent: #0f766e;
|
||||
--accent-fg: #ffffff;
|
||||
--info: #0e7490;
|
||||
--success: #15803d;
|
||||
--radius: 10px;
|
||||
--input-bg: #ffffff;
|
||||
--brand-ink: #1C4053;
|
||||
--danger: #b91c1c;
|
||||
}
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
:root[data-theme="light"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
@media(prefers-color-scheme:dark) {
|
||||
:root:not([data-theme="light"]) {
|
||||
--bg: #0b1220;
|
||||
--card: #111a2b;
|
||||
--border: #1f2a3d;
|
||||
--text: #e5e9f0;
|
||||
--muted: #9aa5b8;
|
||||
--accent: #2dd4bf;
|
||||
--accent-fg: #052e2b;
|
||||
--info: #67e8f9;
|
||||
--success: #4ade80;
|
||||
--input-bg: #0d1524;
|
||||
--brand-ink: #e5e9f0;
|
||||
--danger: #f87171;
|
||||
}
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
color-scheme: dark;
|
||||
--bg: #0b1220;
|
||||
--card: #111a2b;
|
||||
--border: #1f2a3d;
|
||||
--text: #e5e9f0;
|
||||
--muted: #9aa5b8;
|
||||
--accent: #2dd4bf;
|
||||
--accent-fg: #052e2b;
|
||||
--info: #67e8f9;
|
||||
--success: #4ade80;
|
||||
--input-bg: #0d1524;
|
||||
--brand-ink: #e5e9f0;
|
||||
--danger: #f87171;
|
||||
}
|
||||
body {
|
||||
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 0.5rem 2.25rem 2rem;
|
||||
width: 100%;
|
||||
max-width: 384px;
|
||||
}
|
||||
.logo-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-height: 72px;
|
||||
margin: 0.25rem auto 0.5rem;
|
||||
}
|
||||
.logo-wrap svg.default-logo {
|
||||
display: block;
|
||||
width: calc(100% + 1rem);
|
||||
height: auto;
|
||||
margin: -0.25rem auto 0.1rem;
|
||||
max-width: 320px;
|
||||
}
|
||||
.logo-wrap[data-loading] .default-logo {
|
||||
visibility: hidden;
|
||||
}
|
||||
.logo-wrap img.custom-logo {
|
||||
display: block;
|
||||
max-width: 220px;
|
||||
max-height: 96px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
}
|
||||
.default-logo .wordmark {
|
||||
fill: var(--brand-ink)
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: -.015em;
|
||||
margin-bottom: .25rem
|
||||
}
|
||||
.sub {
|
||||
font-size: .8125rem;
|
||||
color: var(--muted);
|
||||
margin-bottom: 1.75rem
|
||||
}
|
||||
.alert {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: .625rem;
|
||||
padding: .625rem .75rem;
|
||||
background: color-mix(in srgb, var(--danger, #dc2626) 10%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--danger, #dc2626) 30%, transparent);
|
||||
border-radius: 8px;
|
||||
font-size: .8125rem;
|
||||
color: var(--danger, #b91c1c);
|
||||
margin-bottom: .875rem;
|
||||
}
|
||||
.alert.success {
|
||||
background: color-mix(in srgb, #0f7a3c 10%, transparent);
|
||||
border-color: color-mix(in srgb, #0f7a3c 30%, transparent);
|
||||
color: #0f7a3c;
|
||||
}
|
||||
@media(prefers-color-scheme:dark) {
|
||||
:root:not([data-theme="light"]) .alert {
|
||||
color: #f4839a
|
||||
}
|
||||
:root:not([data-theme="light"]) .alert.success {
|
||||
color: #58c98a;
|
||||
}
|
||||
}
|
||||
:root[data-theme="dark"] .alert {
|
||||
color: #f4839a
|
||||
}
|
||||
:root[data-theme="dark"] .alert.success {
|
||||
color: #58c98a;
|
||||
}
|
||||
.alert svg {
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px
|
||||
}
|
||||
.fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: .875rem
|
||||
}
|
||||
.field label {
|
||||
font-size: .75rem;
|
||||
font-weight: 500;
|
||||
color: var(--muted);
|
||||
letter-spacing: .03em;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: .3125rem;
|
||||
}
|
||||
input[type=text],
|
||||
input[type=password],
|
||||
input[type=email] {
|
||||
width: 100%;
|
||||
padding: .5625rem .75rem;
|
||||
font-size: .9375rem;
|
||||
font-family: inherit;
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text);
|
||||
outline: none;
|
||||
transition: border-color .15s;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
input[type=text]:focus,
|
||||
input[type=password]:focus,
|
||||
input[type=email]:focus {
|
||||
border-color: color-mix(in srgb, var(--info) 60%, transparent);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--info) 12%, transparent);
|
||||
}
|
||||
input[type=text]::placeholder,
|
||||
input[type=password]::placeholder,
|
||||
input[type=email]::placeholder {
|
||||
color: var(--muted);
|
||||
opacity: .7
|
||||
}
|
||||
#otp {
|
||||
letter-spacing: .2em;
|
||||
font-size: 1.0625rem;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums
|
||||
}
|
||||
#device-code {
|
||||
letter-spacing: .15em;
|
||||
font-size: 1.0625rem;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.btn {
|
||||
width: 100%;
|
||||
margin-top: .375rem;
|
||||
padding: .625rem 0;
|
||||
font-size: .9375rem;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background: var(--accent);
|
||||
color: var(--accent-fg);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
letter-spacing: -.01em;
|
||||
transition: opacity .15s;
|
||||
}
|
||||
.btn:hover {
|
||||
opacity: .88
|
||||
}
|
||||
.btn:active {
|
||||
opacity: .75;
|
||||
transform: scale(.99)
|
||||
}
|
||||
.btn[disabled] {
|
||||
opacity: .55;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="logo-wrap" id="logo-wrap" data-loading>
|
||||
<svg class="default-logo" xmlns="http://www.w3.org/2000/svg" viewBox="165 35 616 130" role="img" aria-label="inbuxa">
|
||||
<g class="symbol" transform="translate(156.02,30.31) scale(1.0082)"><g stroke="#1C4053" stroke-linecap="round" stroke-linejoin="round"><g transform="translate(0 -12)"><path d="M18 58 L32 60 M19 67 L32 65 M110 58 L96 60 M109 67 L96 65" stroke-width="3" fill="none"/><g transform="translate(64 62) scale(0.9) translate(-64 -60)"><path d="M31 64 C30 50 31 38 34 27 Q36 20 42 23 L55 32 Q64 29.5 73 32 L86 23 Q92 20 94 27 C97 38 98 50 97 64 C96 83 82 92 64 92 C46 92 32 83 31 64 Z" fill="#F9A34C" stroke-width="5"/><path d="M38 30 L50 37.5 L40 45.5 Z M90 30 L78 37.5 L88 45.5 Z" fill="#F47F35" stroke="none"/><path d="M44 60 Q49.5 53 55 60 M73 60 Q78.5 53 84 60" stroke-width="4.2" fill="none"/><path d="M60.8 65.5 h6.4 l-3.2 3.6 z" fill="#1C4053" stroke-width="2"/><path d="M56 71.5 Q60 76.5 64 71.5 Q68 76.5 72 71.5" stroke-width="3.5" fill="none"/></g></g><rect x="12" y="73" width="104" height="51" rx="9" fill="#46CAC3" stroke-width="4.5"/><rect x="21" y="89" width="86" height="10" rx="2.5" fill="#1C4053" stroke="none"/><rect x="27" y="85.5" width="26" height="14" rx="2" fill="#FFFFFF" stroke-width="2.8"/><path d="M28.5 87 L40 93.5 L51.5 87" stroke-width="2.3" fill="none"/><circle cx="99" cy="94" r="2.5" fill="#9FF0E9" stroke="none"/><rect x="21" y="103" width="86" height="9" rx="2.5" fill="#1C4053" stroke="none"/><path d="M28 104.8 L31.8 107.5 L28 110.2 M34.8 110.2 H41" stroke="#9FF0E9" stroke-width="1.9" fill="none"/><circle cx="99" cy="107.5" r="2.5" fill="#9FF0E9" stroke="none"/><rect x="21" y="115.5" width="86" height="4.5" rx="2" fill="#2B8A86" stroke="none"/><circle cx="28" cy="117.75" r="1.6" fill="#F9A34C" stroke="none"/><circle cx="34" cy="117.75" r="1.6" fill="#9FF0E9" stroke="none"/><circle cx="40" cy="117.75" r="1.6" fill="#9FF0E9" stroke="none"/><g transform="translate(0 -12)"><path d="M36.5 90 C36 81 40 76.5 46 76.5 C52 76.5 56 81 55.5 90 C55.5 94 51 96 46 96 C41 96 36.5 94 36.5 90 Z" fill="#F9A34C" stroke-width="4"/><path d="M91.5 90 C92 81 88 76.5 82 76.5 C76 76.5 72 81 72.5 90 C72.5 94 77 96 82 96 C87 96 91.5 94 91.5 90 Z" fill="#F9A34C" stroke-width="4"/><path d="M43 88.5 V93 M49 88.5 V93 M79 88.5 V93 M85 88.5 V93" stroke-width="2.4" fill="none"/></g></g></g>
|
||||
<g class="wordmark"><path d="M70 0V496H196V0ZM133 554Q99 554 75.5 576.0Q52 598 52 634Q52 670 75.5 692.0Q99 714 133 714Q168 714 191.0 692.0Q214 670 214 634Q214 598 191.0 576.0Q168 554 133 554Z" transform="translate(303.25,151.90) scale(0.150000,-0.150000)"/><path d="M70 0V496H194V431H212Q224 457 257.0 480.5Q290 504 357 504Q415 504 458.5 477.5Q502 451 526.0 404.5Q550 358 550 296V0H424V286Q424 342 396.5 370.0Q369 398 318 398Q260 398 228.0 359.5Q196 321 196 252V0Z" transform="translate(340.15,151.90) scale(0.150000,-0.150000)"/><path d="M368 -14Q301 -14 265.0 9.0Q229 32 212 60H194V0H70V700H196V439H214Q225 457 243.5 473.0Q262 489 292.5 499.5Q323 510 368 510Q428 510 479.0 480.5Q530 451 561.0 394.0Q592 337 592 256V240Q592 159 561.0 102.0Q530 45 479.0 15.5Q428 -14 368 -14ZM330 96Q388 96 427.0 133.5Q466 171 466 243V253Q466 325 427.5 362.5Q389 400 330 400Q272 400 233.0 362.5Q194 325 194 253V243Q194 171 233.0 133.5Q272 96 330 96Z" transform="translate(429.55,151.90) scale(0.150000,-0.150000)"/><path d="M259 -8Q201 -8 157.5 18.5Q114 45 90.0 92.0Q66 139 66 200V496H192V210Q192 154 219.5 126.0Q247 98 298 98Q356 98 388.0 136.5Q420 175 420 244V496H546V0H422V65H404Q392 40 359.0 16.0Q326 -8 259 -8Z" transform="translate(522.25,151.90) scale(0.150000,-0.150000)"/><path d="M26 0 206 250 28 496H174L287 331H305L418 496H564L386 250L566 0H418L305 167H287L174 0Z" transform="translate(611.65,151.90) scale(0.150000,-0.150000)"/><path d="M224 -14Q171 -14 129.0 4.5Q87 23 62.5 58.5Q38 94 38 145Q38 196 62.5 230.5Q87 265 130.5 282.5Q174 300 230 300H366V328Q366 363 344.0 385.5Q322 408 274 408Q227 408 204.0 386.5Q181 365 174 331L58 370Q70 408 96.5 439.5Q123 471 167.5 490.5Q212 510 276 510Q374 510 431.0 461.0Q488 412 488 319V134Q488 104 516 104H556V0H472Q435 0 411.0 18.0Q387 36 387 66V67H368Q364 55 350.0 35.5Q336 16 306.0 1.0Q276 -14 224 -14ZM246 88Q299 88 332.5 117.5Q366 147 366 196V206H239Q204 206 184.0 191.0Q164 176 164 149Q164 122 185.0 105.0Q206 88 246 88Z" transform="translate(697.45,151.90) scale(0.150000,-0.150000)"/></g>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 id="title">Add a passkey</h1>
|
||||
<p class="sub" id="subtitle">Confirm it's you, then create the passkey on this device.</p>
|
||||
<div class="alert" id="alert" hidden aria-live="polite">
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<line x1="12" y1="8" x2="12" y2="12" />
|
||||
<line x1="12" y1="16" x2="12.01" y2="16" />
|
||||
</svg>
|
||||
<span id="alert-msg"></span>
|
||||
</div>
|
||||
<form class="fields" id="passkey-form" novalidate>
|
||||
<div class="field" id="field-account" hidden>
|
||||
<label for="account">Account</label>
|
||||
<input id="account" name="username" type="text" autocomplete="username" readonly>
|
||||
</div>
|
||||
<div class="field" id="field-password">
|
||||
<label for="password">Password</label>
|
||||
<input id="password" name="password" type="password" placeholder="••••••••"
|
||||
autocomplete="current-password" required>
|
||||
</div>
|
||||
<div class="field" id="field-otp" hidden>
|
||||
<label for="otp">One-time code</label>
|
||||
<input id="otp" name="otp" type="text" placeholder="000000" maxlength="6" inputmode="numeric"
|
||||
pattern="\d{6}" autocomplete="one-time-code">
|
||||
</div>
|
||||
<button type="submit" class="btn" id="submit-btn">Continue</button>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
// INBUXA (#334): registers a passkey for the ticket in this page's URL
|
||||
// (passkeys spec PK-6 to PK-8). The password (and code) comes first;
|
||||
// then the browser's own dialog makes the passkey.
|
||||
(function () {
|
||||
'use strict';
|
||||
var $ = function (id) { return document.getElementById(id); };
|
||||
function setText(el, text) { el.textContent = text == null ? '' : String(text); }
|
||||
function show(el) { if (el) el.hidden = false; }
|
||||
function hide(el) { if (el) el.hidden = true; }
|
||||
function showError(msg) {
|
||||
var a = $('alert');
|
||||
a.classList.remove('success');
|
||||
setText($('alert-msg'), msg);
|
||||
show(a);
|
||||
}
|
||||
function showSuccess(msg) {
|
||||
var a = $('alert');
|
||||
a.classList.add('success');
|
||||
setText($('alert-msg'), msg);
|
||||
show(a);
|
||||
}
|
||||
function clearAlert() { hide($('alert')); }
|
||||
var params = new URL(window.location.href).searchParams;
|
||||
var ticket = params.get('ticket') || '';
|
||||
var loginHint = null;
|
||||
(function loadCustomLogo() {
|
||||
var wrap = $('logo-wrap');
|
||||
function showDefault() { wrap.removeAttribute('data-loading'); }
|
||||
var params = [];
|
||||
if (loginHint) {
|
||||
var at = loginHint.lastIndexOf('@');
|
||||
if (at !== -1 && at < loginHint.length - 1) {
|
||||
params.push('domain=' + encodeURIComponent(loginHint.slice(at + 1).toLowerCase()));
|
||||
}
|
||||
}
|
||||
// The dark-mode logo when this page shows dark (branding BT-27)
|
||||
var theme = document.documentElement.getAttribute('data-theme');
|
||||
if (theme === 'dark' || (theme !== 'light' && window.matchMedia &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||
params.push('theme=dark');
|
||||
}
|
||||
var target = '/logo' + (params.length ? '?' + params.join('&') : '');
|
||||
// An image element, not fetch: it can follow /logo's redirect to
|
||||
// a URL logo on another origin (branding BT-26)
|
||||
var img = new Image();
|
||||
img.className = 'custom-logo';
|
||||
img.alt = 'Logo';
|
||||
img.onload = function () {
|
||||
while (wrap.firstChild) wrap.removeChild(wrap.firstChild);
|
||||
wrap.appendChild(img);
|
||||
wrap.removeAttribute('data-loading');
|
||||
};
|
||||
img.onerror = showDefault;
|
||||
img.src = target;
|
||||
})();
|
||||
function finished(title, subtitle) {
|
||||
hide($('passkey-form'));
|
||||
setText($('title'), title);
|
||||
setText($('subtitle'), subtitle);
|
||||
}
|
||||
if (!ticket) {
|
||||
finished('Add a passkey', 'This page is opened by your mail app when you add a passkey.');
|
||||
showError('Start adding the passkey from your mail app\'s settings.');
|
||||
return;
|
||||
}
|
||||
if (!window.PublicKeyCredential || !navigator.credentials || !navigator.credentials.create) {
|
||||
finished('Add a passkey', 'This browser can\'t make passkeys.');
|
||||
showError('Open this page in a browser that supports passkeys, or use another device.');
|
||||
return;
|
||||
}
|
||||
// WebAuthn's binary fields travel as base64url text
|
||||
function fromB64(s) {
|
||||
s = s.replace(/-/g, '+').replace(/_/g, '/');
|
||||
while (s.length % 4) s += '=';
|
||||
var bin = atob(s), out = new Uint8Array(bin.length);
|
||||
for (var i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
||||
return out.buffer;
|
||||
}
|
||||
function toB64(buf) {
|
||||
var bytes = new Uint8Array(buf), bin = '';
|
||||
for (var i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
|
||||
return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
||||
}
|
||||
function post(body) {
|
||||
return fetch('/api/passkey/register', {
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
cache: 'no-store',
|
||||
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
}).then(function (res) {
|
||||
if (res.status !== 200) throw new Error('http ' + res.status);
|
||||
return res.json();
|
||||
});
|
||||
}
|
||||
function expired() {
|
||||
finished('Add a passkey', 'This link has run out or was already used.');
|
||||
showError('Start again from your mail app\'s settings.');
|
||||
}
|
||||
function create(json) {
|
||||
var pk = json.options.publicKey;
|
||||
pk.challenge = fromB64(pk.challenge);
|
||||
pk.user.id = fromB64(pk.user.id);
|
||||
(pk.excludeCredentials || []).forEach(function (c) { c.id = fromB64(c.id); });
|
||||
setText($('subtitle'), 'Follow your browser\'s steps to create the passkey "' + json.name + '".');
|
||||
return navigator.credentials.create({ publicKey: pk }).then(function (cred) {
|
||||
var response = {
|
||||
attestationObject: toB64(cred.response.attestationObject),
|
||||
clientDataJSON: toB64(cred.response.clientDataJSON)
|
||||
};
|
||||
if (cred.response.getTransports) response.transports = cred.response.getTransports();
|
||||
return post({
|
||||
step: 'finish',
|
||||
ticket: ticket,
|
||||
credential: {
|
||||
id: cred.id,
|
||||
rawId: toB64(cred.rawId),
|
||||
type: cred.type,
|
||||
response: response,
|
||||
extensions: cred.getClientExtensionResults ? cred.getClientExtensionResults() : {}
|
||||
}
|
||||
});
|
||||
}, function (err) {
|
||||
console.log('navigator.credentials.create failed:', err);
|
||||
throw { cancelled: true, name: err && err.name };
|
||||
});
|
||||
}
|
||||
function submit(e) {
|
||||
if (e) e.preventDefault();
|
||||
clearAlert();
|
||||
var password = $('password').value;
|
||||
if (!password) { showError('Enter your password.'); return; }
|
||||
var otp = $('otp').value.trim();
|
||||
var body = { step: 'start', ticket: ticket, password: password };
|
||||
if (!$('field-otp').hidden) {
|
||||
if (!/^\d{6}$/.test(otp)) { showError('Enter the 6-digit code.'); return; }
|
||||
body.mfaToken = otp;
|
||||
}
|
||||
var btn = $('submit-btn');
|
||||
btn.disabled = true;
|
||||
post(body).then(function (json) {
|
||||
switch (json.type) {
|
||||
case 'options':
|
||||
$('account').value = json.accountName;
|
||||
return create(json).then(function (done) {
|
||||
if (done.type === 'registered') {
|
||||
finished('Passkey added', 'You can close this window.');
|
||||
showSuccess('"' + done.name + '" is ready. Use it the next time you sign in.');
|
||||
} else if (done.type === 'expired') {
|
||||
expired();
|
||||
} else {
|
||||
finished('Add a passkey', 'The passkey wasn\'t added.');
|
||||
showError(done.reason || 'Start again from your mail app\'s settings.');
|
||||
}
|
||||
});
|
||||
case 'mfaRequired':
|
||||
show($('field-otp'));
|
||||
setText($('subtitle'), 'Enter the 6-digit code from your authenticator app.');
|
||||
setTimeout(function () { $('otp').focus(); }, 0);
|
||||
return;
|
||||
case 'expired':
|
||||
expired();
|
||||
return;
|
||||
default:
|
||||
showError(!$('field-otp').hidden ? 'The password or code is wrong.' : 'The password is wrong.');
|
||||
$('otp').value = '';
|
||||
}
|
||||
}).catch(function (err) {
|
||||
if (err && err.cancelled) {
|
||||
// Nothing was used up: Continue asks again
|
||||
setText($('subtitle'), 'The passkey wasn\'t created.');
|
||||
showError(err.name === 'InvalidStateError'
|
||||
? 'This device already has a passkey for your account.'
|
||||
: 'Choose Continue to try again.');
|
||||
return;
|
||||
}
|
||||
console.log('Passkey registration failed:', err);
|
||||
showError('Temporary server failure. If the problem persists, contact your administrator.');
|
||||
}).then(function () { btn.disabled = false; });
|
||||
}
|
||||
$('passkey-form').addEventListener('submit', submit);
|
||||
$('otp').addEventListener('input', function () { this.value = this.value.replace(/\D/g, ''); });
|
||||
setTimeout(function () { $('password').focus(); }, 0);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="referrer" content="no-referrer"> <script>!function(){var e=new URLSearchParams(window.location.search).get("theme");"light"!==e&&"dark"!==e||document.documentElement.setAttribute("data-theme",e)}()</script> <title>Add a passkey · inbuxa</title> <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAR4ElEQVRo3u1aeXSV1bXf+5xvuHNyczOQGCAhCQQSEQEBEX3ocqJWUVwq8Vmxdnhaq3ZZO9hnW95qV63Vqu/J66CV95xaZBAFRHEqYAUEBFFAQsIQyUBC5tzc77v3O+fs98d37+UifXAjWavteu+srKzcm+87Z//23mcPv3OQiOAfebC/tQD/D+BvLcDfAgARKaWGcfOcyYQ41NeUUowlYUulECD98QsMpRQB8IwJ+RBnG9rTShFjzLasg4cPRwcGOGOMMSm/iPKISErJGOOM9fX2Nhw4KByHM6bU0KYaggVc9Wz5cNcdCx9v6ooWhkOXTKm+q25u7fhxACCl4vy4Ok6eFhEzFe/a7eDhpidfWLnm/Y86+gbGl0Ye+e4dF06fnGnkYQNARIiYiMdn3PStjvbWWyb5P+2S7zTaXDfvnHfpg3fdFggEhJQMURExxliGuKkZQKrkAxrnAPDvz7zws8WvxCzrskpzTC5butvyB3M+WPLbcDjHXS4bwbQsgSqlOOdvvrdpZ2Pzf80L3jYlRjG2s8t8fJv+8Auvvbt913O/+EF1VWXaKUXC7u0fUEQAYOq63+fTDNOVmwF0d3ff+W+PLn37w2tqAz+dZUyKxJmXzi32LXi5542Nm+rmznGXG04Arpk+2NMQMuDCEiF7yB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7sv1/umjwQtGm+sa1DcmOh5UcYlHEvrKPWzJR07IQx/s2X9HFhRdVrSKEgJ1vfzSKas37lz+iTOlzPv4pc4on3hyG3urQfgNUXntReaoYmnHkfMUc5KWPCNJEAACKgKPUTlv9o7fLJv524THY8ws5Wf51c+2eJbvEo4UJdNrWusP2Jadgn7GAAhACafoyll5syYdfXPzri17r3xehULeATLKLigOnz8pNLFK2vEkX/X5V9NunCp6GJNWPHjOuNrvL+j64OPe+sPXr4yBcLqi8cIJI0dcOj189rjWHz7mcvGn2wLZAUAiApSWZRTljb71mqLZU5tXbzi2c1+opKD46ot9laVWRzfjLE0wEJzEzFFK/pRh5GAsWFPhH11iP/li95H2wJjSSbdfFJxYTRoTAzFIlqqnH9lZwO3RGVcJQY5tlhZVfrsuvHFH0/J1u366qOzGKwsvP1/EE+AI4IwydZZBraS+SwZuIzfU93HDgWdWxLv7Sq+eXXzVLOYxxaAFyDgiEYFSwwYgvTQwhpxLOwEI+bOn+itHNr2w5sCzrw40tY6aP0cLeMWghYylo8/JDkBSLine truncated
|
||||
Binary file not shown.
@@ -352,6 +352,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
code_challenge_method: Some("S256".to_string()),
|
||||
state: None,
|
||||
resource: vec![],
|
||||
passkey: None,
|
||||
})
|
||||
.await;
|
||||
assert_ne!(
|
||||
@@ -372,6 +373,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
code_challenge_method: Some("S256".to_string()),
|
||||
state: None,
|
||||
resource: vec!["https://evil.example.com/jmap".to_string()],
|
||||
passkey: None,
|
||||
})
|
||||
.await;
|
||||
assert_ne!(
|
||||
@@ -394,6 +396,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
code_challenge_method: method.map(str::to_string),
|
||||
state: None,
|
||||
resource: vec![],
|
||||
passkey: None,
|
||||
})
|
||||
.await;
|
||||
assert_ne!(status, 200, "PKCE method {method:?} must not be authorized");
|
||||
@@ -432,6 +435,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
code_challenge_method: challenge.map(|_| "S256".to_string()),
|
||||
state: None,
|
||||
resource: vec![],
|
||||
passkey: None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(
|
||||
@@ -459,6 +463,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
code_challenge_method: Some("S256".to_string()),
|
||||
state: None,
|
||||
resource: vec!["https://mail.example.org/jmap/session".to_string()],
|
||||
passkey: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -627,6 +632,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
code_challenge_method: Some("S256".to_string()),
|
||||
state: None,
|
||||
resource: vec![],
|
||||
passkey: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -1356,6 +1362,7 @@ async fn obtain_auth_code(http: &HttpRequest, client_id: &str, redirect_uri: &st
|
||||
code_challenge_method: None,
|
||||
state: None,
|
||||
resource: vec![],
|
||||
passkey: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//! Passkeys (passkeys spec): `inbuxa:Passkey` management (PK-5, PK-14 to
|
||||
//! PK-17): starting a registration, the limit per account, renaming,
|
||||
//! removing, who reaches whose passkeys, and the audit log. Registration on
|
||||
//! the server's page (PK-6 to PK-8), with a software authenticator.
|
||||
//! the server's page (PK-6 to PK-8) and sign-in (PK-9 to PK-12), with a
|
||||
//! software authenticator.
|
||||
|
||||
use crate::utils::{
|
||||
account::Account,
|
||||
@@ -251,6 +252,8 @@ pub async fn test(test: &mut TestServer) {
|
||||
pub struct SoftKey {
|
||||
pub key: EcdsaKeyPair,
|
||||
pub credential_id: Vec<u8>,
|
||||
/// The account's user handle, as registration gave it (base64url).
|
||||
pub user_handle: std::sync::Mutex<String>,
|
||||
}
|
||||
|
||||
impl SoftKey {
|
||||
@@ -261,11 +264,50 @@ impl SoftKey {
|
||||
key: EcdsaKeyPair::from_pkcs8(&ECDSA_P256_SHA256_ASN1_SIGNING, pkcs8.as_ref(), &rng)
|
||||
.unwrap(),
|
||||
credential_id: credential_id.to_vec(),
|
||||
user_handle: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// What `navigator.credentials.get` hands the page for a sign-in
|
||||
/// challenge, with the given counter and origin.
|
||||
pub fn get(&self, challenge: &Value, counter: u32, origin: &str) -> Value {
|
||||
let client_data = json!({
|
||||
"type": "webauthn.get",
|
||||
"challenge": challenge["options"]["publicKey"]["challenge"],
|
||||
"origin": origin,
|
||||
"crossOrigin": false
|
||||
})
|
||||
.to_string();
|
||||
let mut auth_data = Sha256::digest(RP_ID.as_bytes()).to_vec();
|
||||
// UP, UV, backup eligible, backed up
|
||||
auth_data.push(0x01 | 0x04 | 0x08 | 0x10);
|
||||
auth_data.extend_from_slice(&counter.to_be_bytes());
|
||||
let mut signed = auth_data.clone();
|
||||
signed.extend_from_slice(&Sha256::digest(client_data.as_bytes()));
|
||||
let signature = self.key.sign(&SystemRandom::new(), &signed).unwrap();
|
||||
let id = URL_SAFE_NO_PAD.encode(&self.credential_id);
|
||||
json!({
|
||||
"challengeId": challenge["challengeId"],
|
||||
"credential": {
|
||||
"id": id,
|
||||
"rawId": id,
|
||||
"type": "public-key",
|
||||
"response": {
|
||||
"authenticatorData": URL_SAFE_NO_PAD.encode(&auth_data),
|
||||
"clientDataJSON": URL_SAFE_NO_PAD.encode(client_data.as_bytes()),
|
||||
"signature": URL_SAFE_NO_PAD.encode(signature.as_ref()),
|
||||
"userHandle": self.user_handle.lock().unwrap().clone()
|
||||
},
|
||||
"extensions": {}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// What `navigator.credentials.create` hands the page, for `options`.
|
||||
pub fn create(&self, options: &Value) -> Value {
|
||||
if let Some(handle) = options["publicKey"]["user"]["id"].as_str() {
|
||||
*self.user_handle.lock().unwrap() = handle.to_string();
|
||||
}
|
||||
let challenge = options["publicKey"]["challenge"].as_str().unwrap();
|
||||
let client_data = json!({
|
||||
"type": "webauthn.create",
|
||||
@@ -499,6 +541,131 @@ async fn registration(user: &Account) {
|
||||
}))
|
||||
.await;
|
||||
assert_eq!(response["type"], "refused", "{response}");
|
||||
|
||||
sign_in(user, &key).await;
|
||||
}
|
||||
|
||||
async fn new_challenge() -> Value {
|
||||
let challenge = register_at("/api/auth/passkey", json!({})).await;
|
||||
assert_eq!(
|
||||
challenge["options"]["publicKey"]["rpId"], RP_ID,
|
||||
"{challenge}"
|
||||
);
|
||||
assert_eq!(
|
||||
challenge["options"]["publicKey"]["userVerification"], "required",
|
||||
"{challenge}"
|
||||
);
|
||||
challenge
|
||||
}
|
||||
|
||||
async fn register_at(path: &str, body: Value) -> Value {
|
||||
HttpRequest::new()
|
||||
.post::<Value>(path, &body)
|
||||
.await
|
||||
.unwrap_or_else(|err| panic!("{path} {body}: {err}"))
|
||||
}
|
||||
|
||||
const PKCE_VERIFIER: &str = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk";
|
||||
const PKCE_CHALLENGE: &str = "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM";
|
||||
const REDIRECT: &str = "com.example.app:/cb";
|
||||
|
||||
async fn login(client_id: &str, assertion: Value) -> Value {
|
||||
register_at(
|
||||
"/api/auth",
|
||||
json!({
|
||||
"type": "authCode",
|
||||
"clientId": client_id,
|
||||
"redirectUri": REDIRECT,
|
||||
"codeChallenge": PKCE_CHALLENGE,
|
||||
"codeChallengeMethod": "S256",
|
||||
"passkey": assertion
|
||||
}),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// PK-9 to PK-12: sign-in in the authorization-code flow.
|
||||
async fn sign_in(user: &Account, key: &SoftKey) {
|
||||
let client = HttpRequest::with_credentials(
|
||||
8899,
|
||||
"[email protected]",
|
||||
"these_pretzels_are_making_me_thirsty",
|
||||
)
|
||||
.post::<Value>("/auth/register", &json!({"redirect_uris": [REDIRECT]}))
|
||||
.await
|
||||
.unwrap();
|
||||
let client_id = client["client_id"]
|
||||
.as_str()
|
||||
.unwrap_or_else(|| panic!("{client}"))
|
||||
.to_string();
|
||||
|
||||
// A passkey signs in on its own and the code works
|
||||
let challenge = new_challenge().await;
|
||||
let assertion = key.get(&challenge, 5, ORIGIN);
|
||||
let response = login(&client_id, assertion.clone()).await;
|
||||
assert_eq!(response["type"], "authenticated", "{response}");
|
||||
let code = response["client_code"].as_str().unwrap().to_string();
|
||||
let token = reqwest::Client::builder()
|
||||
.danger_accept_invalid_certs(true)
|
||||
.build()
|
||||
.unwrap()
|
||||
.post("https://127.0.0.1:8899/auth/token")
|
||||
.form(&[
|
||||
("grant_type", "authorization_code"),
|
||||
("code", code.as_str()),
|
||||
("client_id", client_id.as_str()),
|
||||
("redirect_uri", REDIRECT),
|
||||
("code_verifier", PKCE_VERIFIER),
|
||||
])
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json::<Value>()
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(token["access_token"].is_string(), "{token}");
|
||||
let laptop = list(user, user)
|
||||
.await
|
||||
.into_iter()
|
||||
.find(|p| p["name"] == "Laptop")
|
||||
.unwrap();
|
||||
assert!(laptop["lastUsedAt"].is_string(), "{laptop}");
|
||||
|
||||
// PK-10: a challenge is good once
|
||||
let response = login(&client_id, assertion).await;
|
||||
assert_eq!(response["type"], "failure", "{response}");
|
||||
|
||||
// PK-11: a counter that didn't go up fails
|
||||
let challenge = new_challenge().await;
|
||||
let response = login(&client_id, key.get(&challenge, 5, ORIGIN)).await;
|
||||
assert_eq!(response["type"], "failure", "{response}");
|
||||
|
||||
// PK-2: another origin fails
|
||||
let challenge = new_challenge().await;
|
||||
let response = login(&client_id, key.get(&challenge, 9, "https://evil.example")).await;
|
||||
assert_eq!(response["type"], "failure", "{response}");
|
||||
|
||||
// An unknown passkey fails
|
||||
let stranger = SoftKey::new(b"soft-key-stranger-01");
|
||||
*stranger.user_handle.lock().unwrap() = key.user_handle.lock().unwrap().clone();
|
||||
let challenge = new_challenge().await;
|
||||
let response = login(&client_id, stranger.get(&challenge, 1, ORIGIN)).await;
|
||||
assert_eq!(response["type"], "failure", "{response}");
|
||||
|
||||
// Still signs in with a higher counter
|
||||
let challenge = new_challenge().await;
|
||||
let response = login(&client_id, key.get(&challenge, 6, ORIGIN)).await;
|
||||
assert_eq!(response["type"], "authenticated", "{response}");
|
||||
|
||||
// PK-8: the registration page takes the account's passkey instead of
|
||||
// the password, and not someone else's
|
||||
let (_, ticket) = start_registration(user, "Second").await;
|
||||
let challenge = new_challenge().await;
|
||||
let response = register(json!({
|
||||
"step": "start", "ticket": ticket, "passkey": key.get(&challenge, 7, ORIGIN)
|
||||
}))
|
||||
.await;
|
||||
assert_eq!(response["type"], "options", "{response}");
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
|
||||
Reference in new issue
Block a user