summaryrefslogtreecommitdiff
path: root/lib/gitlab/ssh_public_key.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2018-02-09 18:12:20 +0800
committerLin Jen-Shin <godfat@godfat.org>2018-02-09 18:12:20 +0800
commit09a3b8fb655ac673a5d706548d13c26cdb53aa9f (patch)
tree1de0f5552cf1235587cc36f59c1ddc92c1a50752 /lib/gitlab/ssh_public_key.rb
parent1264e2b6e8ce53f578255e9296875947845431bf (diff)
parent7534f7a892d6e8c50475720e387b8689c94582da (diff)
downloadgitlab-ce-09a3b8fb655ac673a5d706548d13c26cdb53aa9f.tar.gz
Merge remote-tracking branch 'upstream/master' into qa-clone-with-deploy-key
* upstream/master: (466 commits) Set initial password for instance in LDAP QA test Backport EE changes to some hashed storage documentation to CE Remove allow_n_plus_1 from Git::Repository#branches_filter Bumps Gitlab Shell version to 6.0.3 Make resetting column information overridable in EE Added 'clear' button to ci lint editor Issues and merge requests in subgroups docs Update docs labels CE Refactored merge_requests/show path in dispatcher.js wording don't check against a hardcoded user name 10.5 Update the dependencies license list 10.5 Update the .gitignore, .gitlab-ci.yml, and Dockerfile templates Create update guide for 10.5 Update 10.5 source install guide Add docs for MR link in commit page Add groups to OpenID Connect claims Replaced $.get with axois.get Memoize MergeRequest#rebase_in_progress? to prevent N+1 queries in Gitaly Update style_guide_scss.md ...
Diffstat (limited to 'lib/gitlab/ssh_public_key.rb')
-rw-r--r--lib/gitlab/ssh_public_key.rb28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/gitlab/ssh_public_key.rb b/lib/gitlab/ssh_public_key.rb
index 89ca1298120..545e7c74f7e 100644
--- a/lib/gitlab/ssh_public_key.rb
+++ b/lib/gitlab/ssh_public_key.rb
@@ -21,6 +21,22 @@ module Gitlab
technology(name)&.supported_sizes
end
+ def self.sanitize(key_content)
+ ssh_type, *parts = key_content.strip.split
+
+ return key_content if parts.empty?
+
+ parts.each_with_object("#{ssh_type} ").with_index do |(part, content), index|
+ content << part
+
+ if Gitlab::SSHPublicKey.new(content).valid?
+ break [content, parts[index + 1]].compact.join(' ') # Add the comment part if present
+ elsif parts.size == index + 1 # return original content if we've reached the last element
+ break key_content
+ end
+ end
+ end
+
attr_reader :key_text, :key
# Unqualified MD5 fingerprint for compatibility
@@ -37,23 +53,23 @@ module Gitlab
end
def valid?
- key.present?
+ key.present? && bits && technology.supported_sizes.include?(bits)
end
def type
- technology.name if valid?
+ technology.name if key.present?
end
def bits
- return unless valid?
+ return if key.blank?
case type
when :rsa
- key.n.num_bits
+ key.n&.num_bits
when :dsa
- key.p.num_bits
+ key.p&.num_bits
when :ecdsa
- key.group.order.num_bits
+ key.group.order&.num_bits
when :ed25519
256
else