Class: Gitlab::Auth::U2fWebauthnConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/auth/u2f_webauthn_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(u2f_registration) ⇒ U2fWebauthnConverter

Returns a new instance of U2fWebauthnConverter.


8
9
10
# File 'lib/gitlab/auth/u2f_webauthn_converter.rb', line 8

def initialize(u2f_registration)
  @u2f_registration = u2f_registration
end

Instance Method Details

#convertObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/auth/u2f_webauthn_converter.rb', line 12

def convert
  now = Time.current

  converted_credential = WebAuthn::U2fMigrator.new(
    app_id: Gitlab.config.gitlab.url,
    certificate: u2f_registration.certificate,
    key_handle: u2f_registration.key_handle,
    public_key: u2f_registration.public_key,
    counter: u2f_registration.counter
  ).credential

  {
    credential_xid: Base64.strict_encode64(converted_credential.id),
    public_key: Base64.strict_encode64(converted_credential.public_key),
    counter: u2f_registration.counter || 0,
    name: u2f_registration.name || '',
    user_id: u2f_registration.user_id,
    u2f_registration_id: u2f_registration.id,
    created_at: now,
    updated_at: now
  }
end