mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
bug #1919: Do not ask ssh password twice
Patch by Jean-Philippe Garcia Ballester Conflicts: src/authm_mad/remotes/ssh/ssh_auth.rb
This commit is contained in:
1 parent
138181ee3c
commit
c0adc81af6
1 file changed
+6
-8
@@ -44,18 +44,18 @@ class OpenNebula::SshAuth
|
||||
raise "Cannot read #{options[:private_key]}"
|
||||
end
|
||||
end
|
||||
@private_key_rsa = OpenSSL::PKey::RSA.new(@private_key) unless @private_key.nil?
|
||||
|
||||
if options[:public_key]
|
||||
@public_key = options[:public_key]
|
||||
elsif @private_key != nil
|
||||
# Init ssh keys using private key. public key is extracted in a
|
||||
# format compatible with openssl. The public key does not contain
|
||||
# "---- BEGIN/END RSA PUBLIC KEY ----" and is in a single line
|
||||
key = OpenSSL::PKey::RSA.new(@private_key)
|
||||
|
||||
@public_key = key.public_key.to_pem.split("\n")
|
||||
# "---- BEGIN/END PUBLIC KEY ----" and is in a single line
|
||||
@public_key = @private_key_rsa.public_key.to_pem.split("\n")
|
||||
@public_key = @public_key.reject {|l| l.match(/PUBLIC KEY/) }.join('')
|
||||
end
|
||||
@public_key_rsa = OpenSSL::PKey::RSA.new(Base64::decode64(@public_key)) unless @public_key.nil?
|
||||
|
||||
if @private_key.nil? && @public_key.nil?
|
||||
raise "You have to define at least one of the keys"
|
||||
@@ -127,13 +127,11 @@ class OpenNebula::SshAuth
|
||||
# Encrypts data with the private key of the user and returns
|
||||
# base 64 encoded output in a single line
|
||||
def encrypt(data)
|
||||
rsa=OpenSSL::PKey::RSA.new(@private_key)
|
||||
Base64::encode64(rsa.private_encrypt(data)).gsub!(/\n/, '').strip
|
||||
Base64::encode64(@private_key_rsa.private_encrypt(data)).gsub!(/\n/, '').strip
|
||||
end
|
||||
|
||||
# Decrypts base 64 encoded data with pub_key (public key)
|
||||
def decrypt(data)
|
||||
rsa=OpenSSL::PKey::RSA.new(Base64::decode64(@public_key))
|
||||
rsa.public_decrypt(Base64::decode64(data))
|
||||
@public_key_rsa.public_decrypt(Base64::decode64(data))
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user