Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1f9dee79
Commit
1f9dee79
authored
Dec 02, 2021
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid falling back to U2F registrations when WebAuthn enabled
parent
733ba47f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
89 deletions
+109
-89
app/controllers/concerns/authenticates_with_two_factor.rb
app/controllers/concerns/authenticates_with_two_factor.rb
+1
-1
app/models/user.rb
app/models/user.rb
+2
-0
ee/spec/controllers/ee/admin/sessions_controller_spec.rb
ee/spec/controllers/ee/admin/sessions_controller_spec.rb
+1
-0
ee/spec/controllers/ee/sessions_controller_spec.rb
ee/spec/controllers/ee/sessions_controller_spec.rb
+1
-0
spec/features/webauthn_spec.rb
spec/features/webauthn_spec.rb
+58
-88
spec/models/user_spec.rb
spec/models/user_spec.rb
+46
-0
No files found.
app/controllers/concerns/authenticates_with_two_factor.rb
View file @
1f9dee79
...
@@ -25,7 +25,7 @@ module AuthenticatesWithTwoFactor
...
@@ -25,7 +25,7 @@ module AuthenticatesWithTwoFactor
session
[
:user_password_hash
]
=
Digest
::
SHA256
.
hexdigest
(
user
.
encrypted_password
)
session
[
:user_password_hash
]
=
Digest
::
SHA256
.
hexdigest
(
user
.
encrypted_password
)
push_frontend_feature_flag
(
:webauthn
)
push_frontend_feature_flag
(
:webauthn
)
if
user
.
two_factor_webauthn_enabled?
if
Feature
.
enabled?
(
:webauthn
)
setup_webauthn_authentication
(
user
)
setup_webauthn_authentication
(
user
)
else
else
setup_u2f_authentication
(
user
)
setup_u2f_authentication
(
user
)
...
...
app/models/user.rb
View file @
1f9dee79
...
@@ -917,6 +917,8 @@ class User < ApplicationRecord
...
@@ -917,6 +917,8 @@ class User < ApplicationRecord
end
end
def
two_factor_u2f_enabled?
def
two_factor_u2f_enabled?
return
false
if
Feature
.
enabled?
(
:webauthn
)
if
u2f_registrations
.
loaded?
if
u2f_registrations
.
loaded?
u2f_registrations
.
any?
u2f_registrations
.
any?
else
else
...
...
ee/spec/controllers/ee/admin/sessions_controller_spec.rb
View file @
1f9dee79
...
@@ -26,6 +26,7 @@ RSpec.describe Admin::SessionsController, :do_not_mock_admin_mode do
...
@@ -26,6 +26,7 @@ RSpec.describe Admin::SessionsController, :do_not_mock_admin_mode do
context
'when U2F authentication fails'
do
context
'when U2F authentication fails'
do
before
do
before
do
stub_feature_flags
(
webauthn:
false
)
allow
(
U2fRegistration
).
to
receive
(
:authenticate
).
and_return
(
false
)
allow
(
U2fRegistration
).
to
receive
(
:authenticate
).
and_return
(
false
)
end
end
...
...
ee/spec/controllers/ee/sessions_controller_spec.rb
View file @
1f9dee79
...
@@ -104,6 +104,7 @@ RSpec.describe SessionsController, :geo do
...
@@ -104,6 +104,7 @@ RSpec.describe SessionsController, :geo do
context
'when U2F authentication fails'
do
context
'when U2F authentication fails'
do
before
do
before
do
stub_feature_flags
(
webauthn:
false
)
allow
(
U2fRegistration
).
to
receive
(
:authenticate
).
and_return
(
false
)
allow
(
U2fRegistration
).
to
receive
(
:authenticate
).
and_return
(
false
)
end
end
...
...
spec/features/webauthn_spec.rb
View file @
1f9dee79
...
@@ -113,35 +113,6 @@ RSpec.describe 'Using WebAuthn Devices for Authentication', :js do
...
@@ -113,35 +113,6 @@ RSpec.describe 'Using WebAuthn Devices for Authentication', :js do
describe
'authentication'
do
describe
'authentication'
do
let
(
:otp_required_for_login
)
{
true
}
let
(
:otp_required_for_login
)
{
true
}
let
(
:user
)
{
create
(
:user
,
webauthn_xid:
WebAuthn
.
generate_user_id
,
otp_required_for_login:
otp_required_for_login
)
}
let
(
:user
)
{
create
(
:user
,
webauthn_xid:
WebAuthn
.
generate_user_id
,
otp_required_for_login:
otp_required_for_login
)
}
describe
'when there is only an U2F device'
do
let!
(
:u2f_device
)
do
fake_device
=
U2F
::
FakeU2F
.
new
(
app_id
)
# "Client"
u2f
=
U2F
::
U2F
.
new
(
app_id
)
# "Server"
challenges
=
u2f
.
registration_requests
.
map
(
&
:challenge
)
device_response
=
fake_device
.
register_response
(
challenges
[
0
])
device_registration_params
=
{
device_response:
device_response
,
name:
'My device'
}
U2fRegistration
.
register
(
user
,
app_id
,
device_registration_params
,
challenges
)
FakeU2fDevice
.
new
(
page
,
'My device'
,
fake_device
)
end
it
'falls back to U2F'
do
# WebAuthn registration is automatically created with the U2fRegistration because of the after_create callback
# so we need to delete it
WebauthnRegistration
.
delete_all
gitlab_sign_in
(
user
)
u2f_device
.
respond_to_u2f_authentication
expect
(
page
).
to
have_css
(
'.sign-out-link'
,
visible:
false
)
end
end
describe
'when there is a WebAuthn device'
do
let!
(
:webauthn_device
)
do
let!
(
:webauthn_device
)
do
add_webauthn_device
(
app_id
,
user
)
add_webauthn_device
(
app_id
,
user
)
end
end
...
@@ -234,5 +205,4 @@ RSpec.describe 'Using WebAuthn Devices for Authentication', :js do
...
@@ -234,5 +205,4 @@ RSpec.describe 'Using WebAuthn Devices for Authentication', :js do
end
end
end
end
end
end
end
end
end
spec/models/user_spec.rb
View file @
1f9dee79
...
@@ -1726,6 +1726,52 @@ RSpec.describe User do
...
@@ -1726,6 +1726,52 @@ RSpec.describe User do
end
end
end
end
context
'two_factor_u2f_enabled?'
do
let_it_be
(
:user
)
{
create
(
:user
,
:two_factor
)
}
context
'when webauthn feature flag is enabled'
do
context
'user has no U2F registration'
do
it
{
expect
(
user
.
two_factor_u2f_enabled?
).
to
eq
(
false
)
}
end
context
'user has existing U2F registration'
do
it
'returns false'
do
device
=
U2F
::
FakeU2F
.
new
(
FFaker
::
BaconIpsum
.
characters
(
5
))
create
(
:u2f_registration
,
name:
'my u2f device'
,
user:
user
,
certificate:
Base64
.
strict_encode64
(
device
.
cert_raw
),
key_handle:
U2F
.
urlsafe_encode64
(
device
.
key_handle_raw
),
public_key:
Base64
.
strict_encode64
(
device
.
origin_public_key_raw
))
expect
(
user
.
two_factor_u2f_enabled?
).
to
eq
(
false
)
end
end
end
context
'when webauthn feature flag is disabled'
do
before
do
stub_feature_flags
(
webauthn:
false
)
end
context
'user has no U2F registration'
do
it
{
expect
(
user
.
two_factor_u2f_enabled?
).
to
eq
(
false
)
}
end
context
'user has existing U2F registration'
do
it
'returns true'
do
device
=
U2F
::
FakeU2F
.
new
(
FFaker
::
BaconIpsum
.
characters
(
5
))
create
(
:u2f_registration
,
name:
'my u2f device'
,
user:
user
,
certificate:
Base64
.
strict_encode64
(
device
.
cert_raw
),
key_handle:
U2F
.
urlsafe_encode64
(
device
.
key_handle_raw
),
public_key:
Base64
.
strict_encode64
(
device
.
origin_public_key_raw
))
expect
(
user
.
two_factor_u2f_enabled?
).
to
eq
(
true
)
end
end
end
end
describe
'projects'
do
describe
'projects'
do
before
do
before
do
@user
=
create
(
:user
)
@user
=
create
(
:user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment