diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/services/webauthn/register_service.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/services/webauthn/register_service.rb')
-rw-r--r-- | app/services/webauthn/register_service.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/services/webauthn/register_service.rb b/app/services/webauthn/register_service.rb new file mode 100644 index 00000000000..21be22027a8 --- /dev/null +++ b/app/services/webauthn/register_service.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Webauthn + class RegisterService < BaseService + def initialize(user, params, challenge) + @user = user + @params = params + @challenge = challenge + end + + def execute + registration = WebauthnRegistration.new + + begin + webauthn_credential = WebAuthn::Credential.from_create(Gitlab::Json.parse(@params[:device_response])) + webauthn_credential.verify(@challenge) + + registration.update( + credential_xid: Base64.strict_encode64(webauthn_credential.raw_id), + public_key: webauthn_credential.public_key, + counter: webauthn_credential.sign_count, + name: @params[:name], + user: @user + ) + rescue JSON::ParserError + registration.errors.add(:base, _('Your WebAuthn device did not send a valid JSON response.')) + rescue WebAuthn::Error => e + registration.errors.add(:base, e.message) + end + + registration + end + end +end |