Class: Booth::Webauth::AuthenticationVerification

Inherits:
Object
  • Object
show all
Includes:
Logging, MethodObject
Defined in:
lib/booth/webauth/authentication_verification.rb

Instance Method Summary collapse

Methods included from MethodObject

included

Instance Method Details

#callObject



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
# File 'lib/booth/webauth/authentication_verification.rb', line 11

def call
  raise 'this authenticator doesnt match the credential' if credential_id != authenticator.credential_id

  debug do
    "Verifying using challenge #{challenge.inspect} and public key #{authenticator.public_key.inspect} and sign count #{authenticator.sign_count.inspect}"
  end
  webauth.verify(
    challenge,
    public_key: authenticator.public_key,
    sign_count: authenticator.sign_count
  )
  debug { 'Response successfully verified' }

  authenticator.update!(sign_count: webauth.sign_count)
  sudo.webauth!

  Tron.success :webauth_authentication_verification_successful,
               credential: authenticator.credential,
               public_json: {},
               http_status: :created
rescue WebAuthn::SignCountVerificationError => e
  # TODO
  raise 'implement me, counter differed, not too bad?'
rescue WebAuthn::Error => e
  debug { "Response verification failed: #{e.message}" }
  # TODO: Audit but don't throttle?
  Tron.failure :webauth_failed, public_json: {},
                                public_message: "Verification failed: #{e.message}",
                                http_status: :unprocessable_entity
rescue RuntimeError => e
  # This happens e.g. if the param[:id] does not match the param[:rawId]
  raise
ensure
  sudo.webauthn_challenge = nil
end