glasslock
Server-side WebAuthn/FIDO2 credential verification for Gleam.
Types
A verified WebAuthn credential returned after successful registration or authentication.
Persist every field after registration. After authentication, replace the
stored sign_count with the value returned by authentication.verify.
Pass id and transports to registration.exclude_credential or
authentication.allow_credential when starting another ceremony.
pub type Credential {
Credential(
id: BitArray,
public_key: PublicKey,
sign_count: Int,
transports: List(Transport),
)
}
Constructors
-
Arguments
- id
-
Authenticator-generated identifier.
- public_key
-
COSE public key used to verify assertions.
- sign_count
-
Latest authenticator signature counter.
- transports
-
Browser transport hints reported at registration.
A reference to a stored credential, used in allow_credentials and
exclude_credentials lists. Carrying transports is optional but lets the
browser route the ceremony to the right authenticator faster.
pub type CredentialDescriptor {
CredentialDescriptor(id: BitArray, transports: List(Transport))
}
Constructors
-
CredentialDescriptor(id: BitArray, transports: List(Transport))
A COSE-encoded public key.
Round-trip through storage with parse_public_key
and encode_public_key.
pub opaque type PublicKey
Errors returned by parse_public_key when stored
bytes cannot be interpreted as a supported COSE public key.
pub type PublicKeyError {
InvalidPublicKey(reason: String)
UnsupportedPublicKey(reason: String)
}
Constructors
-
InvalidPublicKey(reason: String)The bytes are not a valid COSE-encoded public key.
-
UnsupportedPublicKey(reason: String)The key uses an algorithm or curve glasslock does not support.
Transport hints reported by an authenticator during registration.
Echoed back to the browser in allow_credentials/exclude_credentials so
it can route the request to the right authenticator. Optional for
correctness; helpful for UX, especially with hybrid (cross-device)
transports.
pub type Transport {
TransportUsb
TransportNfc
TransportBle
TransportSmartCard
TransportHybrid
TransportInternal
}
Constructors
-
TransportUsbRemovable USB authenticator.
-
TransportNfcNear-field communication authenticator.
-
TransportBleBluetooth Low Energy authenticator.
-
TransportSmartCardISO/IEC 7816 smart card with contacts.
-
TransportHybridCross-device authenticator (e.g. phone acting as a roaming key).
-
TransportInternalBuilt-in platform authenticator (Touch ID, Windows Hello, etc.).
User-verification policy for a ceremony.
pub type Verification {
VerificationRequired
VerificationPreferred
VerificationDiscouraged
}
Constructors
-
VerificationRequiredReject unless the authenticator verifies the user with a biometric or PIN.
-
VerificationPreferredRequest verification, but accept a response without it.
-
VerificationDiscouragedAsk the authenticator to skip verification when possible.
Identifies which field failed verification in a VerificationMismatch error.
pub type VerificationField {
TypeField
ChallengeField
OriginField
RelyingPartyIdField
CrossOriginField
TopOriginField
CredentialIdField
CredentialTypeField
UserHandleField
}
Constructors
-
TypeFieldThe
typefield in clientDataJSON (expected"webauthn.create"or"webauthn.get"). -
ChallengeFieldThe
challengefield in clientDataJSON did not match the expected challenge bytes. -
OriginFieldThe
originfield in clientDataJSON did not match the expected origin. -
RelyingPartyIdFieldThe SHA-256 hash of the Relying Party ID did not match authenticator data.
-
CrossOriginFieldThe
crossOriginfield wastruebut cross-origin requests are not allowed. -
TopOriginFieldThe
topOriginfield was either set withoutcrossOrigin: true, or did not match any allowed top-level origin. -
CredentialIdFieldThe
rawIdin the response did not match the credential ID in authenticator data. -
CredentialTypeFieldThe top-level credential
typefield was not"public-key". -
UserHandleFieldThe assertion
userHandlewas missing or did not match the account.
Values
pub fn encode_public_key(public_key: PublicKey) -> BitArray
Serialize a PublicKey to canonical public-only COSE bytes.
The returned bytes round-trip through parse_public_key. Use when
persisting a credential to storage.
pub fn parse_public_key(
bytes: BitArray,
) -> Result(PublicKey, PublicKeyError)
Parse stored COSE bytes into a PublicKey.
Validates the encoding, key type, curve, and signature algorithm. Use
when loading a credential from storage before passing to
authentication.verify.