Class: Mccloud::Util::SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/mccloud/util/sshkey.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key, options = {}) ⇒ SSHKey

Returns a new instance of SSHKey.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mccloud/util/sshkey.rb', line 19

def initialize(private_key, options = {})
  @key_object        = OpenSSL::PKey::RSA.new(private_key)

  @comment           = options[:comment] || ""
  @rsa_private_key   = @key_object.to_pem
  @rsa_public_key    = @key_object.public_key.to_pem
  raw_ssh_public_key = ssh_public_key_conversion

#    @ssh_public_key    = ["ssh-rsa", Base64.strict_encode64(raw_ssh_public_key), @comment].join(" ").strip

  @ssh_public_key    = ["ssh-rsa", [raw_ssh_public_key].pack("m0").gsub(/\n/,''), @comment].join(" ").strip
  @fingerprint       = Digest::MD5.hexdigest(raw_ssh_public_key).gsub(/(.{2})(?=.)/, '\1:\2')
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



17
18
19
# File 'lib/mccloud/util/sshkey.rb', line 17

def comment
  @comment
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



17
18
19
# File 'lib/mccloud/util/sshkey.rb', line 17

def fingerprint
  @fingerprint
end

#key_objectObject (readonly)

Returns the value of attribute key_object.



17
18
19
# File 'lib/mccloud/util/sshkey.rb', line 17

def key_object
  @key_object
end

#rsa_private_keyObject (readonly)

Returns the value of attribute rsa_private_key.



17
18
19
# File 'lib/mccloud/util/sshkey.rb', line 17

def rsa_private_key
  @rsa_private_key
end

#rsa_public_keyObject (readonly)

Returns the value of attribute rsa_public_key.



17
18
19
# File 'lib/mccloud/util/sshkey.rb', line 17

def rsa_public_key
  @rsa_public_key
end

#ssh_public_keyObject (readonly)

Returns the value of attribute ssh_public_key.



17
18
19
# File 'lib/mccloud/util/sshkey.rb', line 17

def ssh_public_key
  @ssh_public_key
end

Class Method Details

.generate(options = {}) ⇒ Object



13
14
15
# File 'lib/mccloud/util/sshkey.rb', line 13

def self.generate(options = {})
  SSHKey.new(OpenSSL::PKey::RSA.generate(2048).to_pem, options)
end