diff options
author | Sašo Stanovnik <sstanovnik@gmail.com> | 2015-03-24 02:11:41 +0300 |
---|---|---|
committer | Sašo Stanovnik <sstanovnik@gmail.com> | 2015-03-24 02:11:41 +0300 |
commit | 455a4fe91a32d0ab2de72d1e62a7a6edfcb40d31 (patch) | |
tree | 662be3ce67a0f37a7495650950f8b9eb24e744a9 /app/models | |
parent | c03374919fac691c3ecb7eb4f844dbbce5dc35fa (diff) |
Fixed generating SSH key fingerprints in OpenSSH 6.8.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/key.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index e2e59296eed..b74daf50fec 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -86,7 +86,24 @@ class Key < ActiveRecord::Base Tempfile.open('gitlab_key_file') do |file| file.puts key file.rewind - cmd_output, cmd_status = popen(%W(ssh-keygen -lf #{file.path}), '/tmp') + + # OpenSSH 6.8 introduces a new default output format for fingerprints. + # Check the version and decide which command to use. + version_output, version_status = popen(%W(ssh -V)) + explicit_fingerprint_algorithm = false + if version_status.zero? + out, _ = version_output.scan /.*?(\d)\.(\d).*?,/ + major, minor = out[0], out[1] + if major.to_i > 6 or (major.to_i == 6 and minor.to_i >= 8) + explicit_fingerprint_algorithm = true + end + end + + if explicit_fingerprint_algorithm + cmd_output, cmd_status = popen(%W(ssh-keygen -E md5 -lf #{file.path}), '/tmp') + else + cmd_output, cmd_status = popen(%W(ssh-keygen -lf #{file.path}), '/tmp') + end end if cmd_status.zero? |