Class: Smartdc::Auth
- Inherits:
-
Object
- Object
- Smartdc::Auth
- Defined in:
- lib/smartdc/auth.rb
Instance Attribute Summary collapse
-
#rsa_path ⇒ Object
readonly
Returns the value of attribute rsa_path.
-
#use_key ⇒ Object
readonly
Returns the value of attribute use_key.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #find_key_file ⇒ Object
- #fingerprint(path) ⇒ Object
-
#initialize(options = {}) ⇒ Auth
constructor
A new instance of Auth.
- #read_key_file(path) ⇒ Object
- #signature(data) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Auth
Returns a new instance of Auth.
7 8 9 10 11 |
# File 'lib/smartdc/auth.rb', line 7 def initialize(={}) @username = [:username] @rsa_path = [:rsa_path] @use_key = [:use_key] end |
Instance Attribute Details
#rsa_path ⇒ Object (readonly)
Returns the value of attribute rsa_path.
5 6 7 |
# File 'lib/smartdc/auth.rb', line 5 def rsa_path @rsa_path end |
#use_key ⇒ Object (readonly)
Returns the value of attribute use_key.
5 6 7 |
# File 'lib/smartdc/auth.rb', line 5 def use_key @use_key end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/smartdc/auth.rb', line 5 def username @username end |
Instance Method Details
#find_key_file ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smartdc/auth.rb', line 13 def find_key_file path = File.(self.rsa_path) if File.directory?(path) Dir[File.join(path, '*')].each do |path| return path if File.file?(path) and self.use_key == self.fingerprint(path) end return '' else return path end end |
#fingerprint(path) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/smartdc/auth.rb', line 38 def fingerprint(path) rsa = read_key_file(path) str = [7].pack('N') + 'ssh-rsa' + rsa.public_key.e.to_s(0) + rsa.public_key.n.to_s(0) OpenSSL::Digest::MD5.hexdigest(str).scan(/../).join(':') rescue '' end |
#read_key_file(path) ⇒ Object
25 26 27 |
# File 'lib/smartdc/auth.rb', line 25 def read_key_file(path) OpenSSL::PKey::RSA.new(File.read(File.(path)), '') end |
#signature(data) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/smartdc/auth.rb', line 29 def signature(data) rsa = read_key_file(self.find_key_file) sha256 = OpenSSL::Digest::SHA256.new str = [rsa.sign(sha256, data)].pack('m').delete("\r\n") "Signature keyId=\"/#{self.username}/keys/#{self.use_key}\",algorithm=\"rsa-sha256\" #{str}" rescue '' end |