def data(hexdata)
require 'digest/sha1'
data = hex_decode(hexdata)
context, id, s_challenge = data.split(' ')
c_challenge = Array.new(s_challenge.bytesize/2).map{|obj|obj=rand(255).to_s}.join
path = File.join(ENV['HOME'], '.dbus-keyrings', context)
puts "DEBUG: path: #{path.inspect}" if $debug
File.foreach(path) do |line|
if line.index(id) == 0
cookie = line.split(' ')[2].chomp
puts "DEBUG: cookie: #{cookie.inspect}" if $debug
to_encrypt = [s_challenge, c_challenge, cookie].join(':')
sha = Digest::SHA1.hexdigest(to_encrypt)
hex_response = hex_encode("#{c_challenge} #{sha}")
response = [:AuthOk, hex_response]
return response
end
end
unless @retries <= 0
puts "ERROR: Could not auth, will now exit."
puts "ERROR: Unable to locate cookie, retry in 1 second."
@retries -= 1
sleep 1
data(hexdata)
end
end