fbe9252db1
- Use plain client data json everywhere - Expose AAGUID and backed_up on Credentials - Make attestation verifiers configurable - Auto-suggest names for passkeys and show icons
49 lines
1.6 KiB
Ruby
49 lines
1.6 KiB
Ruby
class ActionPack::WebAuthn::PublicKeyCredential
|
|
attr_reader :id, :public_key, :sign_count, :aaguid, :backed_up, :transports, :owner
|
|
|
|
class << self
|
|
def create(client_data_json:, attestation_object:, challenge:, origin:, transports: [], owner: nil)
|
|
response = ActionPack::WebAuthn::Authenticator::AttestationResponse.new(
|
|
client_data_json: client_data_json,
|
|
attestation_object: attestation_object
|
|
)
|
|
|
|
response.validate!(challenge: challenge, origin: origin)
|
|
|
|
new(
|
|
id: response.attestation.credential_id,
|
|
public_key: response.attestation.public_key,
|
|
sign_count: response.attestation.sign_count,
|
|
aaguid: response.attestation.aaguid,
|
|
backed_up: response.attestation.backed_up?,
|
|
transports: transports,
|
|
owner: owner
|
|
)
|
|
end
|
|
end
|
|
|
|
def initialize(id:, public_key:, sign_count:, aaguid: nil, backed_up: nil, transports: [], owner: nil)
|
|
@id = id
|
|
@public_key = public_key
|
|
@sign_count = sign_count
|
|
@aaguid = aaguid
|
|
@backed_up = backed_up
|
|
@transports = transports
|
|
@owner = owner
|
|
end
|
|
|
|
def authenticate(client_data_json:, authenticator_data:, signature:, challenge:, origin:)
|
|
response = ActionPack::WebAuthn::Authenticator::AssertionResponse.new(
|
|
client_data_json: client_data_json,
|
|
authenticator_data: authenticator_data,
|
|
signature: signature,
|
|
credential: self
|
|
)
|
|
|
|
response.validate!(challenge: challenge, origin: origin)
|
|
|
|
@sign_count = response.authenticator_data.sign_count
|
|
@backed_up = response.authenticator_data.backed_up?
|
|
end
|
|
end
|