Welcome to mirror list, hosted at ThFree Co, Russian Federation.

insecure_key_fingerprint.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b1cf5e7931fc022191cd05641e074f1759d8943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Gitlab
  #
  # Calculates the fingerprint of a given key without using
  # openssh key validations. For this reason, only use
  # for calculating the fingerprint to find the key with it.
  #
  # DO NOT use it for checking the validity of a ssh key.
  #
  class InsecureKeyFingerprint
    attr_accessor :key
    alias_attribute :fingerprint_md5, :fingerprint

    #
    # Gets the base64 encoded string representing a rsa or dsa key
    #
    def initialize(key_base64)
      @key = key_base64
    end

    def fingerprint
      OpenSSL::Digest::MD5.hexdigest(Base64.decode64(@key)).scan(/../).join(':')
    end

    def fingerprint_sha256
      Digest::SHA256.base64digest(Base64.decode64(@key)).scan(/../).join('').delete("=")
    end
  end
end