class WebAuthn::FakeAuthenticator::AuthenticatorData
Constants
- AAGUID
Attributes
credential[R]
extensions[R]
rp_id_hash[R]
sign_count[R]
user_present[R]
user_verified[R]
Public Class Methods
new( rp_id_hash:, credential: { id: SecureRandom.random_bytes(16), public_key: OpenSSL::PKey::EC.new("prime256v1").generate_key.public_key }, sign_count: 0, user_present: true, user_verified: !user_present, aaguid: AAGUID, extensions: { "fakeExtension" => "fakeExtensionValue" } )
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 14 def initialize( rp_id_hash:, credential: { id: SecureRandom.random_bytes(16), public_key: OpenSSL::PKey::EC.new("prime256v1").generate_key.public_key }, sign_count: 0, user_present: true, user_verified: !user_present, aaguid: AAGUID, extensions: { "fakeExtension" => "fakeExtensionValue" } ) @rp_id_hash = rp_id_hash @credential = credential @sign_count = sign_count @user_present = user_present @user_verified = user_verified @aaguid = aaguid @extensions = extensions end
Public Instance Methods
serialize()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 35 def serialize rp_id_hash + flags + serialized_sign_count + attested_credential_data + extension_data end
Private Instance Methods
attested_credential_data()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 62 def attested_credential_data @attested_credential_data ||= if credential @aaguid + [credential[:id].length].pack("n*") + credential[:id] + cose_credential_public_key else "" end end
attested_credential_data_included_bit()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 90 def attested_credential_data_included_bit if attested_credential_data.empty? "0" else "1" end end
bit(flag)
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 82 def bit(flag) if context[flag] "1" else "0" end end
context()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 110 def context { user_present: user_present, user_verified: user_verified } end
cose_credential_public_key()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 114 def cose_credential_public_key case credential[:public_key] when OpenSSL::PKey::RSA key = COSE::Key::RSA.from_pkey(credential[:public_key]) key.alg = -257 when OpenSSL::PKey::EC::Point alg = { COSE::Key::Curve.by_name("P-256").id => -7, COSE::Key::Curve.by_name("P-384").id => -35, COSE::Key::Curve.by_name("P-521").id => -36 } key = COSE::Key::EC2.from_pkey(credential[:public_key]) key.alg = alg[key.crv] end key.serialize end
extension_data()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 74 def extension_data if extensions CBOR.encode(extensions) else "" end end
extension_data_included_bit()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 98 def extension_data_included_bit if extension_data.empty? "0" else "1" end end
flags()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 43 def flags [ [ bit(:user_present), reserved_for_future_use_bit, bit(:user_verified), reserved_for_future_use_bit, reserved_for_future_use_bit, reserved_for_future_use_bit, attested_credential_data_included_bit, extension_data_included_bit ].join ].pack("b*") end
key_bytes(public_key)
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 134 def key_bytes(public_key) public_key.to_bn.to_s(2) end
reserved_for_future_use_bit()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 106 def reserved_for_future_use_bit "0" end
serialized_sign_count()
click to toggle source
# File lib/webauthn/fake_authenticator/authenticator_data.rb, line 58 def serialized_sign_count [sign_count].pack('L>') end