2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-01 12:53:01 -05:00
|
|
|
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
|
2022-02-28 13:14:03 -05:00
|
|
|
|
2016-03-01 12:53:01 -05:00
|
|
|
# Gets the base64 encoded string representing a rsa or dsa key
|
|
|
|
#
|
|
|
|
def initialize(key_base64)
|
|
|
|
@key = key_base64
|
|
|
|
end
|
|
|
|
|
2019-12-11 13:08:10 -05:00
|
|
|
def fingerprint_sha256
|
|
|
|
Digest::SHA256.base64digest(Base64.decode64(@key)).scan(/../).join('').delete("=")
|
|
|
|
end
|
2016-03-01 12:53:01 -05:00
|
|
|
end
|
|
|
|
end
|