diff options
author | Valeriy Sizov <vsv2711@gmail.com> | 2012-10-03 03:18:08 -0700 |
---|---|---|
committer | Valeriy Sizov <vsv2711@gmail.com> | 2012-10-03 03:18:08 -0700 |
commit | b5f9d29f55e1fbf302bd824e2d08c0885caa15d7 (patch) | |
tree | abeb98c3a421d4b6674f5b6892bddf63e1bc4097 /app/models/key.rb | |
parent | 4cbfe9427ba84a05a444373809a6b7aa7906db34 (diff) | |
parent | 7284c58c5fb54965b078a2ba9e3634479700416d (diff) | |
download | gitlab-ce-b5f9d29f55e1fbf302bd824e2d08c0885caa15d7.tar.gz |
Merge pull request #1617 from dosire/reject-ssh-keys-that-break-gitolite
Reject ssh keys that break gitolite
Diffstat (limited to 'app/models/key.rb')
-rw-r--r-- | app/models/key.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index 3ef21811c2d..dc1f3cdb9f9 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -14,7 +14,7 @@ class Key < ActiveRecord::Base before_save :set_identifier before_validation :strip_white_space delegate :name, :email, to: :user, prefix: true - validate :unique_key + validate :unique_key, :fingerprintable_key def strip_white_space self.key = self.key.strip unless self.key.blank? @@ -28,6 +28,21 @@ class Key < ActiveRecord::Base end end + def fingerprintable_key + return true unless key # Don't test if there is no key. + # `ssh-keygen -lf /dev/stdin <<< "#{key}"` errors with: redirection unexpected + file = Tempfile.new('key_file') + begin + file.puts key + file.rewind + fingerprint_output = `ssh-keygen -lf #{file.path} 2>&1` # Catch stderr. + ensure + file.close + file.unlink # deletes the temp file + end + errors.add(:key, "can't be fingerprinted") if fingerprint_output.match("failed") + end + def set_identifier if is_deploy_key self.identifier = "deploy_#{Digest::MD5.hexdigest(key)}" |