OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Build RelyingParty on the fly to support our hosted environment
Klaus Zanders7d92d20a921a
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rbindex 7a33d80c34b..d5d82c6266c 100644--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb@@ -58,7 +58,7 @@ module ::TwoFactorAuthenticationdef webauthn_challengedevice = otp_service(@authenticated_user).device- webauthn_options = device.options_for_get+ webauthn_options = device.options_for_get(webauthn_relying_party)session[:webauthn_challenge] = webauthn_options.challengerender json: webauthn_options@@ -154,7 +154,11 @@ module ::TwoFactorAuthenticationservice = otp_service_for_verification(user)result = if service.device.class.device_type == :webauthn- service.verify(webauthn_credential, webauthn_challenge: session[:webauthn_challenge])+ service.verify(+ JSON.parse(webauthn_credential),+ webauthn_challenge: session[:webauthn_challenge],+ webauthn_relying_party:+ )elseservice.verify(otp_token)end@@ -217,5 +221,12 @@ module ::TwoFactorAuthenticationdef failure_stage_redirectredirect_to authentication_stage_failure_path :two_factor_authenticationend++ def webauthn_relying_party+ @webauthn_relying_party ||= WebAuthn::RelyingParty.new(+ origin: "#{Setting.protocol}://#{Setting.host_name}",+ name: Setting.app_title+ )+ endendenddiff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rbindex 7fc5effda9d..20f973229db 100644--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb@@ -75,7 +75,7 @@ module ::TwoFactorAuthenticationensure_user_has_webauthn_id!- webauthn_options = device.options_for_create+ webauthn_options = device.options_for_create(webauthn_relying_party)session[:webauthn_challenge] = webauthn_options.challengerender json: webauthn_options@@ -177,18 +177,31 @@ module ::TwoFactorAuthenticationenddef webauthn_credential- @webauthn_credential ||= WebAuthn::Credential.from_create(JSON.parse(params[:device][:webauthn_credential]))+ @webauthn_credential ||= webauthn_relying_party.verify_registration(+ JSON.parse(params[:device][:webauthn_credential]),+ session[:webauthn_challenge]+ )enddef verify_webauthn_credential- webauthn_credential.verify(session[:webauthn_challenge])- session.delete(:webauthn_challenge)- true+ if webauthn_credential+ session.delete(:webauthn_challenge)+ true+ else+ false+ endrescue WebAuthn::Error => eRails.logger.error "Failed to verify WebAuthn credential for registration. #{e}"falseend+ def webauthn_relying_party+ @webauthn_relying_party ||= WebAuthn::RelyingParty.new(+ origin: "#{Setting.protocol}://#{Setting.host_name}",+ name: Setting.app_title+ )+ end+def logout_other_sessionsif current_user == target_userRails.logger.info { "First 2FA device registered for #{target_user}, terminating other logged in sessions." }diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rbindex 1b011621a48..c1b7dbe88f6 100644--- a/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb+++ b/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb@@ -18,15 +18,15 @@ module TwoFactorAuthenticationendvalidates_inclusion_of :channel, in: supported_channels- def options_for_create- @options_for_create ||= WebAuthn::Credential.options_for_create(+ def options_for_create(relying_party)+ @options_for_create ||= relying_party.options_for_registration(user: { id: user.webauthn_id, name: user.name },exclude: TwoFactorAuthentication::Device::Webauthn.where(user:).pluck(:webauthn_external_id))end- def options_for_get- @options_for_get ||= WebAuthn::Credential.options_for_get(+ def options_for_get(relying_party)+ @options_for_get ||= relying_party.options_for_authentication(allow: webauthn_external_id # TODO: Maybe also allow all other tokens? Let's see)enddiff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rbindex b6c4b31763a..6b7a9cfc16b 100644--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb@@ -61,12 +61,6 @@ module OpenProject::TwoFactorAuthentication}) dotwo_factor_authentication_request_pathend-- WebAuthn.configure do |config|- # TODO: Real settings here- config.origin = "http://localhost:3000"- config.rp_name = "Example Inc."- endendendenddiff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rbindex 69acd0731ed..3c035a22130 100644--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb@@ -3,14 +3,13 @@ require 'webauthn'module OpenProject::TwoFactorAuthenticationmodule TokenStrategyclass Webauthn < Base- def verify(webauthn_credential, webauthn_challenge:)- credential = WebAuthn::Credential.from_get(JSON.parse(webauthn_credential))-+ def verify(webauthn_credential, webauthn_challenge:, webauthn_relying_party:)# This will raise WebAuthn::Error- credential.verify(+ credential = webauthn_relying_party.verify_authentication(+ webauthn_credential,webauthn_challenge,- public_key: device.webauthn_public_key,- sign_count: device.webauthn_sign_count+ sign_count: device.webauthn_sign_count,+ public_key: device.webauthn_public_key)device.update!(webauthn_sign_count: credential.sign_count)