rodauth 2.49.0 → 2.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rodauth/features/audit_logging.rb +4 -2
- data/lib/rodauth/features/base.rb +2 -1
- data/lib/rodauth/features/internal_request.rb +6 -2
- data/lib/rodauth/features/json.rb +3 -3
- data/lib/rodauth/features/otp.rb +8 -6
- data/lib/rodauth/features/webauthn.rb +38 -5
- data/lib/rodauth/features/webauthn_verify_account.rb +1 -1
- data/lib/rodauth/version.rb +1 -1
- data/templates/webauthn-auth.str +1 -1
- data/templates/webauthn-autofill.str +1 -1
- data/templates/webauthn-setup.str +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0bc39bbb4274800781804df0552ab4110972187fa7d92b039c6987dfda8a27ac
|
|
4
|
+
data.tar.gz: 3b5d4e5ec1cd5a3fb732ec2103aff7d4a8849d13884ba74a038d7732ff93fa73
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb9dd09809e2267224d1f12ca2bb97aa3443d6ff91228fefab37efc31e4efe3b337ac1f93a8194ddcf364af0c2a78bd507befe4ae5452e01c851b8030002b87a
|
|
7
|
+
data.tar.gz: 5e8a30091172947bc3d4012515e4f2124d30321f19e0b6c98e5e99e8816b4eef39e001aa5ac73dda19dcd76305689c0b4fe30eaea1db0c1dd0754adf81f0c523
|
|
@@ -31,8 +31,10 @@ module Rodauth
|
|
|
31
31
|
def hook_action(hook_type, action)
|
|
32
32
|
super
|
|
33
33
|
|
|
34
|
-
#
|
|
35
|
-
|
|
34
|
+
# Audit after successful actions. Logout is audited on before_logout
|
|
35
|
+
# because logout/clear_session runs before after_logout and does not
|
|
36
|
+
# clear @account, which would otherwise duplicate the logout audit.
|
|
37
|
+
if hook_type == (action == :logout ? :before : :after) && (id = account_id_or_session_value)
|
|
36
38
|
add_audit_log(id, action)
|
|
37
39
|
end
|
|
38
40
|
end
|
|
@@ -75,6 +75,10 @@ module Rodauth
|
|
|
75
75
|
alias close_account_requires_password? modifications_require_password?
|
|
76
76
|
alias two_factor_modifications_require_password? modifications_require_password?
|
|
77
77
|
|
|
78
|
+
def webauthn_credential_challenge_hmac_match?(hmac)
|
|
79
|
+
true
|
|
80
|
+
end
|
|
81
|
+
|
|
78
82
|
def otp_setup_view
|
|
79
83
|
hash = {:otp_setup=>otp_user_key}
|
|
80
84
|
hash[:otp_setup_raw] = otp_key if hmac_secret
|
|
@@ -90,7 +94,7 @@ module Rodauth
|
|
|
90
94
|
_return_from_internal_request({
|
|
91
95
|
webauthn_setup: cred.as_json,
|
|
92
96
|
webauthn_setup_challenge: cred.challenge,
|
|
93
|
-
webauthn_setup_challenge_hmac:
|
|
97
|
+
webauthn_setup_challenge_hmac: webauthn_credential_challenge_hmac(cred.challenge)
|
|
94
98
|
})
|
|
95
99
|
end
|
|
96
100
|
|
|
@@ -99,7 +103,7 @@ module Rodauth
|
|
|
99
103
|
_return_from_internal_request({
|
|
100
104
|
webauthn_auth: cred.as_json,
|
|
101
105
|
webauthn_auth_challenge: cred.challenge,
|
|
102
|
-
webauthn_auth_challenge_hmac:
|
|
106
|
+
webauthn_auth_challenge_hmac: webauthn_credential_challenge_hmac(cred.challenge)
|
|
103
107
|
})
|
|
104
108
|
end
|
|
105
109
|
|
|
@@ -144,7 +144,7 @@ module Rodauth
|
|
|
144
144
|
cred = new_webauthn_credential
|
|
145
145
|
json_response[webauthn_setup_param] = cred.as_json
|
|
146
146
|
json_response[webauthn_setup_challenge_param] = cred.challenge
|
|
147
|
-
json_response[webauthn_setup_challenge_hmac_param] =
|
|
147
|
+
json_response[webauthn_setup_challenge_hmac_param] = webauthn_credential_challenge_hmac(cred.challenge)
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
150
|
|
|
@@ -154,7 +154,7 @@ module Rodauth
|
|
|
154
154
|
cred = webauthn_credential_options_for_get
|
|
155
155
|
json_response[webauthn_auth_param] = cred.as_json
|
|
156
156
|
json_response[webauthn_auth_challenge_param] = cred.challenge
|
|
157
|
-
json_response[webauthn_auth_challenge_hmac_param] =
|
|
157
|
+
json_response[webauthn_auth_challenge_hmac_param] = webauthn_credential_challenge_hmac(cred.challenge)
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
@@ -164,7 +164,7 @@ module Rodauth
|
|
|
164
164
|
cred = webauthn_credential_options_for_get
|
|
165
165
|
json_response[webauthn_auth_param] = cred.as_json
|
|
166
166
|
json_response[webauthn_auth_challenge_param] = cred.challenge
|
|
167
|
-
json_response[webauthn_auth_challenge_hmac_param] =
|
|
167
|
+
json_response[webauthn_auth_challenge_hmac_param] = webauthn_credential_challenge_hmac(cred.challenge)
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
|
data/lib/rodauth/features/otp.rb
CHANGED
|
@@ -100,7 +100,7 @@ module Rodauth
|
|
|
100
100
|
:otp_valid_code_for_old_secret
|
|
101
101
|
)
|
|
102
102
|
|
|
103
|
-
uses_instance_variables(:@otp, :@otp_key, :@otp_user_key, :@otp_tmp_key)
|
|
103
|
+
uses_instance_variables(:@otp, :@otp_key, :@otp_user_key, :@otp_tmp_key, :@otp_verify_time)
|
|
104
104
|
|
|
105
105
|
internal_request_method :otp_setup_params
|
|
106
106
|
internal_request_method :otp_setup
|
|
@@ -275,14 +275,14 @@ module Rodauth
|
|
|
275
275
|
otp.verify_with_drift(ot_pass, drift)
|
|
276
276
|
# simplecov:enable
|
|
277
277
|
else
|
|
278
|
-
otp.verify(ot_pass, :drift_behind=>drift, :drift_ahead=>drift, :after=>otp_last_use)
|
|
278
|
+
@otp_verify_time = otp.verify(ot_pass, :drift_behind=>drift, :drift_ahead=>drift, :after=>otp_last_use)
|
|
279
279
|
end
|
|
280
280
|
# simplecov:disable
|
|
281
281
|
elsif otp.respond_to?(:verify_with_drift)
|
|
282
282
|
otp.verify(ot_pass)
|
|
283
283
|
# simplecov:enable
|
|
284
284
|
else
|
|
285
|
-
otp.verify(ot_pass, :after=>otp_last_use)
|
|
285
|
+
@otp_verify_time = otp.verify(ot_pass, :after=>otp_last_use)
|
|
286
286
|
end
|
|
287
287
|
end
|
|
288
288
|
|
|
@@ -297,9 +297,10 @@ module Rodauth
|
|
|
297
297
|
end
|
|
298
298
|
|
|
299
299
|
def otp_update_last_use
|
|
300
|
+
verify_time = @otp_verify_time.is_a?(Integer) ? Time.at(@otp_verify_time) : Sequel::CURRENT_TIMESTAMP # simplecov:disable
|
|
300
301
|
otp_key_ds.
|
|
301
|
-
where(Sequel.date_add(otp_keys_last_use_column, :seconds=>_otp_interval)
|
|
302
|
-
update(otp_keys_last_use_column=>
|
|
302
|
+
where(Sequel.date_add(otp_keys_last_use_column, :seconds=>_otp_interval) <= verify_time).
|
|
303
|
+
update(otp_keys_last_use_column=>verify_time) == 1
|
|
303
304
|
end
|
|
304
305
|
|
|
305
306
|
def otp_last_use
|
|
@@ -440,9 +441,10 @@ module Rodauth
|
|
|
440
441
|
end
|
|
441
442
|
|
|
442
443
|
def _otp_add_key(secret)
|
|
444
|
+
verify_time = @otp_verify_time.is_a?(Integer) ? Time.at(@otp_verify_time) : Sequel::CURRENT_TIMESTAMP # simplecov:disable
|
|
443
445
|
# Uniqueness errors can't be handled here, as we can't be sure the secret provided
|
|
444
446
|
# is the same as the current secret.
|
|
445
|
-
otp_key_ds.insert(otp_keys_id_column=>session_value, otp_keys_column=>secret)
|
|
447
|
+
otp_key_ds.insert(otp_keys_id_column=>session_value, otp_keys_column=>secret, otp_keys_last_use_column=>verify_time)
|
|
446
448
|
end
|
|
447
449
|
|
|
448
450
|
def _otp_key
|
|
@@ -42,6 +42,8 @@ module Rodauth
|
|
|
42
42
|
error_flash "Error removing WebAuthn authenticator", 'webauthn_remove'
|
|
43
43
|
|
|
44
44
|
session_key :authenticated_webauthn_id_session_key, :webauthn_id
|
|
45
|
+
session_key :webauthn_hmac_session_key, :webauthn_hmac
|
|
46
|
+
session_key :webauthn_challenge_timestamp_session_key, :webauthn_challenge_timestamp
|
|
45
47
|
|
|
46
48
|
translatable_method :webauthn_auth_link_text, "Authenticate Using WebAuthn"
|
|
47
49
|
translatable_method :webauthn_setup_link_text, "Setup WebAuthn Authentication"
|
|
@@ -72,6 +74,7 @@ module Rodauth
|
|
|
72
74
|
|
|
73
75
|
auth_value_method :webauthn_setup_timeout, 120000
|
|
74
76
|
auth_value_method :webauthn_auth_timeout, 60000
|
|
77
|
+
auth_value_method :webauthn_authentication_seconds, 600
|
|
75
78
|
auth_value_method :webauthn_user_verification, 'discouraged'
|
|
76
79
|
auth_value_method :webauthn_attestation, 'none'
|
|
77
80
|
|
|
@@ -257,6 +260,8 @@ module Rodauth
|
|
|
257
260
|
end
|
|
258
261
|
|
|
259
262
|
def webauthn_update_session(webauthn_id)
|
|
263
|
+
remove_session_value(webauthn_challenge_timestamp_session_key)
|
|
264
|
+
remove_session_value(webauthn_hmac_session_key)
|
|
260
265
|
set_session_value(authenticated_webauthn_id_session_key, webauthn_id)
|
|
261
266
|
end
|
|
262
267
|
|
|
@@ -315,6 +320,7 @@ module Rodauth
|
|
|
315
320
|
_override_webauthn_credential_response_verify(webauthn_credential)
|
|
316
321
|
(challenge = param_or_nil(webauthn_setup_challenge_param)) &&
|
|
317
322
|
(hmac = param_or_nil(webauthn_setup_challenge_hmac_param)) &&
|
|
323
|
+
webauthn_credential_challenge_hmac_match?(hmac) &&
|
|
318
324
|
(timing_safe_eql?(compute_hmac(challenge), hmac) || (hmac_secret_rotation? && timing_safe_eql?(compute_old_hmac(challenge), hmac))) &&
|
|
319
325
|
webauthn_credential.verify(challenge)
|
|
320
326
|
end
|
|
@@ -359,19 +365,36 @@ module Rodauth
|
|
|
359
365
|
nil
|
|
360
366
|
end
|
|
361
367
|
|
|
368
|
+
def webauthn_credential_challenge_hmac(challenge)
|
|
369
|
+
session[webauthn_challenge_timestamp_session_key] = Time.now.to_i
|
|
370
|
+
session[webauthn_hmac_session_key] = compute_hmac(challenge)
|
|
371
|
+
end
|
|
372
|
+
|
|
362
373
|
def valid_webauthn_credential_auth?(webauthn_credential)
|
|
363
374
|
ds = webauthn_keys_ds.where(webauthn_keys_webauthn_id_column => webauthn_credential.id)
|
|
364
|
-
|
|
375
|
+
# simplecov:disable
|
|
376
|
+
last_use_column = if db.database_type == :sqlite
|
|
377
|
+
Sequel.cast(webauthn_keys_last_use_column, String).as(:__rodauth_last_use__)
|
|
378
|
+
# simplecov:enable
|
|
379
|
+
else
|
|
380
|
+
webauthn_keys_last_use_column
|
|
381
|
+
end
|
|
382
|
+
pub_key, sign_count, last_use = ds.get([webauthn_keys_public_key_column, webauthn_keys_sign_count_column, last_use_column])
|
|
365
383
|
|
|
366
384
|
_override_webauthn_credential_response_verify(webauthn_credential)
|
|
367
385
|
(challenge = param_or_nil(webauthn_auth_challenge_param)) &&
|
|
368
386
|
(hmac = param_or_nil(webauthn_auth_challenge_hmac_param)) &&
|
|
387
|
+
webauthn_credential_challenge_hmac_match?(hmac) &&
|
|
369
388
|
(timing_safe_eql?(compute_hmac(challenge), hmac) || (hmac_secret_rotation? && timing_safe_eql?(compute_old_hmac(challenge), hmac))) &&
|
|
370
389
|
webauthn_credential.verify(challenge, public_key: pub_key, sign_count: sign_count) &&
|
|
371
|
-
ds.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
390
|
+
ds.
|
|
391
|
+
where(
|
|
392
|
+
webauthn_keys_sign_count_column => sign_count,
|
|
393
|
+
webauthn_keys_last_use_column => last_use
|
|
394
|
+
).update(
|
|
395
|
+
webauthn_keys_sign_count_column => Integer(webauthn_credential.sign_count),
|
|
396
|
+
webauthn_keys_last_use_column => Sequel::CURRENT_TIMESTAMP
|
|
397
|
+
) == 1
|
|
375
398
|
end
|
|
376
399
|
|
|
377
400
|
def remove_webauthn_key(webauthn_id)
|
|
@@ -548,6 +571,16 @@ module Rodauth
|
|
|
548
571
|
end
|
|
549
572
|
end
|
|
550
573
|
|
|
574
|
+
def webauthn_credential_challenge_hmac_match?(hmac)
|
|
575
|
+
challenge_create_time = session[webauthn_challenge_timestamp_session_key]
|
|
576
|
+
session_hmac = session[webauthn_hmac_session_key]
|
|
577
|
+
|
|
578
|
+
challenge_create_time &&
|
|
579
|
+
session_hmac &&
|
|
580
|
+
(challenge_create_time + webauthn_authentication_seconds > Time.now.to_i) &&
|
|
581
|
+
timing_safe_eql?(hmac, session_hmac)
|
|
582
|
+
end
|
|
583
|
+
|
|
551
584
|
def webauthn_setup_credential_from_form_submission
|
|
552
585
|
unless two_factor_password_match?(param(password_param))
|
|
553
586
|
throw_error_reason(:invalid_password, invalid_password_error_status, password_param, invalid_password_message)
|
|
@@ -35,7 +35,7 @@ module Rodauth
|
|
|
35
35
|
cred = new_webauthn_credential
|
|
36
36
|
json_response[webauthn_setup_param] = cred.as_json
|
|
37
37
|
json_response[webauthn_setup_challenge_param] = cred.challenge
|
|
38
|
-
json_response[webauthn_setup_challenge_hmac_param] =
|
|
38
|
+
json_response[webauthn_setup_challenge_hmac_param] = webauthn_credential_challenge_hmac(cred.challenge)
|
|
39
39
|
end
|
|
40
40
|
@webauthn_credential = webauthn_setup_credential_from_form_submission
|
|
41
41
|
add_webauthn_credential(@webauthn_credential)
|
data/lib/rodauth/version.rb
CHANGED
data/templates/webauthn-auth.str
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#{rodauth.webauthn_auth_additional_form_tags}
|
|
3
3
|
#{rodauth.csrf_tag(rodauth.webauthn_auth_form_path)}
|
|
4
4
|
<input type="hidden" name="#{rodauth.webauthn_auth_challenge_param}" value="#{cred.challenge}" />
|
|
5
|
-
<input type="hidden" name="#{rodauth.webauthn_auth_challenge_hmac_param}" value="#{rodauth.
|
|
5
|
+
<input type="hidden" name="#{rodauth.webauthn_auth_challenge_hmac_param}" value="#{rodauth.webauthn_credential_challenge_hmac(cred.challenge)}" />
|
|
6
6
|
<input class="rodauth_hidden d-none" aria-hidden="true" type="text" name="#{rodauth.webauthn_auth_param}" id="webauthn-auth" value="" />
|
|
7
7
|
<div id="webauthn-auth-button">
|
|
8
8
|
#{rodauth.button(rodauth.webauthn_auth_button)}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#{rodauth.webauthn_auth_additional_form_tags}
|
|
3
3
|
#{rodauth.csrf_tag(rodauth.webauthn_login_path)}
|
|
4
4
|
<input type="hidden" name="#{rodauth.webauthn_auth_challenge_param}" value="#{cred.challenge}" />
|
|
5
|
-
<input type="hidden" name="#{rodauth.webauthn_auth_challenge_hmac_param}" value="#{rodauth.
|
|
5
|
+
<input type="hidden" name="#{rodauth.webauthn_auth_challenge_hmac_param}" value="#{rodauth.webauthn_credential_challenge_hmac(cred.challenge)}" />
|
|
6
6
|
<input class="rodauth_hidden d-none" aria-hidden="true" type="text" name="#{rodauth.webauthn_auth_param}" id="webauthn-auth" value="" />
|
|
7
7
|
#{rodauth.button(rodauth.webauthn_auth_button, class: "d-none")}
|
|
8
8
|
</form>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#{rodauth.webauthn_setup_additional_form_tags}
|
|
3
3
|
#{rodauth.csrf_tag}
|
|
4
4
|
<input type="hidden" name="#{rodauth.webauthn_setup_challenge_param}" value="#{cred.challenge}" />
|
|
5
|
-
<input type="hidden" name="#{rodauth.webauthn_setup_challenge_hmac_param}" value="#{rodauth.
|
|
5
|
+
<input type="hidden" name="#{rodauth.webauthn_setup_challenge_hmac_param}" value="#{rodauth.webauthn_credential_challenge_hmac(cred.challenge)}" />
|
|
6
6
|
<input class="rodauth_hidden d-none" aria-hidden="true" type="text" name="#{rodauth.webauthn_setup_param}" id="webauthn-setup" value="" />
|
|
7
7
|
#{rodauth.render('password-field') if rodauth.two_factor_modifications_require_password?}
|
|
8
8
|
<div id="webauthn-setup-button">
|