-
Notifications
You must be signed in to change notification settings - Fork 53
/
attestation_object.rb
47 lines (38 loc) · 1.35 KB
/
attestation_object.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
require "cbor"
require "forwardable"
require "openssl"
require "webauthn/attestation_statement"
require "webauthn/authenticator_data"
module WebAuthn
class AttestationObject
extend Forwardable
def self.deserialize(attestation_object, relying_party)
from_map(CBOR.decode(attestation_object), relying_party)
end
def self.from_map(map, relying_party)
new(
authenticator_data: WebAuthn::AuthenticatorData.deserialize(map["authData"]),
attestation_statement: WebAuthn::AttestationStatement.from(
map["fmt"],
map["attStmt"],
relying_party: relying_party
)
)
end
attr_reader :authenticator_data, :attestation_statement, :relying_party
def initialize(authenticator_data:, attestation_statement:)
@authenticator_data = authenticator_data
@attestation_statement = attestation_statement
end
def valid_attested_credential?
authenticator_data.attested_credential_data_included? &&
authenticator_data.attested_credential_data.valid?
end
def valid_attestation_statement?(client_data_hash)
attestation_statement.valid?(authenticator_data, client_data_hash)
end
def_delegators :authenticator_data, :credential, :aaguid
def_delegators :attestation_statement, :attestation_certificate_key_id
end
end