Class: RBus::Auth::DBusCookieSHA1
- Inherits:
-
Object
- Object
- RBus::Auth::DBusCookieSHA1
- Defined in:
- lib/rbus/auth/dbus_cookie_sha1.rb
Overview
Implements the AUTH DBUS_COOKIE_SHA1 mechanism.
Instance Method Summary collapse
Instance Method Details
#auth ⇒ Object
30 31 32 33 34 |
# File 'lib/rbus/auth/dbus_cookie_sha1.rb', line 30 def auth require 'etc' ['DBUS_COOKIE_SHA1', Etc.getlogin, :DATA] end |
#data(data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rbus/auth/dbus_cookie_sha1.rb', line 36 def data(data) require 'digest/sha1' # name of cookie file, id of cookie in file, servers random challenge context, id, s_challenge = data.split(' ') # Random client challenge c_challenge = Array.new(s_challenge.length/2).map{|obj|obj=rand(255).to_s}.join # Search cookie file for id path = File.join(ENV['HOME'], '.dbus-keyrings', context) File.foreach(path) do |line| if line.index(id) == 0 # Right line of file, read cookie = line.split(' ')[2].chomp # Concatenate and encrypt to_encrypt = [s_challenge, c_challenge, ].join(':') sha = Digest::SHA1.hexdigest(to_encrypt) # Return response return ["#{c_challenge} #{sha}", :OK] end end raise AuthException, 'Unable to locate cookie' end |