-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-secret.rb
executable file
·37 lines (29 loc) · 981 Bytes
/
find-secret.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env ruby
# output passwords for search
# call: find-secret.rb server=example.org user=u33 protocol=smtp
require 'dbus'
require 'pp'
search = []
ARGV.each do |x|
key, value = x.split("=")
search << [key, value]
end
bus = DBus::SessionBus.instance
service = bus.service("org.freedesktop.secrets")
secret = service.object("/org/freedesktop/secrets")
secret.introspect
secret.default_iface = "org.freedesktop.Secret.Service"
unlocked, locked = secret.SearchItems(search)
puts "unlocked: #{unlocked.inspect}\nlocked: #{locked.inspect}" if $DEBUG
# TODO unlock locked
s = unlocked.first
item = service.object(s)
item.default_iface = "org.freedesktop.Secret.Item"
item.introspect
_empty_string, session_path = secret.OpenSession("plain", "")
session = service.object(session_path)
session.default_iface = "org.freedesktop.Secret.Session"
session.introspect
_session_path, _parameter, value = item.GetSecret(session_path).first
puts value.pack("c*")
session.Close()