2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
2020-01-01 13:55:28 +05:30
|
|
|
alias_attribute :fingerprint_md5, :fingerprint
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
def fingerprint_sha256
|
|
|
|
Digest::SHA256.base64digest(Base64.decode64(@key)).scan(/../).join('').delete("=")
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|