diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-24 20:07:21 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-24 20:07:21 +0300 |
commit | 113d2ff525b6005e1cc7ff86a5a0189c4ab3d0e4 (patch) | |
tree | db812996f7002ddd527c713851f829820654ce61 /app | |
parent | 05a7e8b9c0b1ebdc01470a31f933b7526ca2cd08 (diff) | |
download | gitlab-ce-113d2ff525b6005e1cc7ff86a5a0189c4ab3d0e4.tar.gz |
store and display public key fingerprint
Diffstat (limited to 'app')
-rw-r--r-- | app/models/key.rb | 40 | ||||
-rw-r--r-- | app/views/profiles/keys/_key.html.haml | 4 | ||||
-rw-r--r-- | app/views/profiles/keys/show.html.haml | 3 |
3 files changed, 37 insertions, 10 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index a87ea4943e9..0f2fc45abc9 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -15,6 +15,8 @@ require 'digest/md5' class Key < ActiveRecord::Base + include Gitlab::Popen + belongs_to :user attr_accessible :key, :title @@ -34,16 +36,10 @@ class Key < ActiveRecord::Base def fingerprintable_key return true unless key # Don't test if there is no key. - 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 + unless generate_fingerpint + errors.add(:key, "can't be fingerprinted") + false end - errors.add(:key, "can't be fingerprinted") if $?.exitstatus != 0 end # projects that has this key @@ -54,4 +50,30 @@ class Key < ActiveRecord::Base def shell_id "key-#{id}" end + + private + + def generate_fingerpint + cmd_status = 0 + cmd_output = '' + file = Tempfile.new('gitlab_key_file') + + begin + file.puts key + file.rewind + cmd_output, cmd_status = popen("ssh-keygen -lf #{file.path}", '/tmp') + ensure + file.close + file.unlink # deletes the temp file + end + + if cmd_status.zero? + cmd_output.gsub /([\d\h]{2}:)+[\d\h]{2}/ do |match| + self.fingerprint = match + end + true + else + false + end + end end diff --git a/app/views/profiles/keys/_key.html.haml b/app/views/profiles/keys/_key.html.haml index cf4d80ad894..d0a3fe32c35 100644 --- a/app/views/profiles/keys/_key.html.haml +++ b/app/views/profiles/keys/_key.html.haml @@ -1,9 +1,11 @@ %li = link_to profile_key_path(key) do %strong= key.title + %span + (#{key.fingerprint}) %span.cgray added = time_ago_in_words(key.created_at) ago - = link_to 'Remove', profile_key_path(key), confirm: 'Are you sure?', method: :delete, class: "btn btn-small btn-remove delete-key pull-right" + = link_to 'Remove', profile_key_path(key), confirm: 'Are you sure?', method: :delete, class: "btn btn-small btn-remove delete-key pull-right" diff --git a/app/views/profiles/keys/show.html.haml b/app/views/profiles/keys/show.html.haml index fc292f23066..735e9d1f936 100644 --- a/app/views/profiles/keys/show.html.haml +++ b/app/views/profiles/keys/show.html.haml @@ -12,6 +12,9 @@ %strong= @key.created_at.stamp("Aug 21, 2011") .span8 + %p + %span.light Fingerprint: + %strong= @key.fingerprint %pre.well-pre = @key.key |