-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathagent.py
More file actions
executable file
·49 lines (41 loc) · 1.41 KB
/
agent.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.41 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
#http://wiki.bluez.org/wiki/PasskeyAgent
#A simple passkey agent, invoke with arbitrary MAC/PIN pairs, i.e like 00:01:02:03:04:05/1234
import dbus
import dbus.glib
import dbus.service
import gobject
import sys
class PasskeyAgent(dbus.service.Object):
def __init__(self, path, keystore):
dbus.service.Object.__init__(self, dbus.SystemBus(), path)
self.keystore = keystore
@dbus.service.method(dbus_interface='org.bluez.PasskeyAgent',
in_signature='ssb', out_signature='s')
def Request(self, path, address, numeric):
try:
pin = self.keystore[address]
print "Request",path,address,numeric,"OK"
return pin
except:
print "Request",path,address,numeric,"failed"
return ""
if __name__ == "__main__":
keystore = {}
addr = "00:1A:45:94:44:F2"
pin = "0000"
keystore[addr] = pin
print "Added ",addr," ",pin
for arg in sys.argv:
addr, pin = arg.split("/")
keystore[addr] = pin
print "Added ",addr," ",pin
PATH = '/my/PasskeyAgent'
bus = dbus.SystemBus();
handler = PasskeyAgent(PATH, keystore)
adapter = bus.get_object('org.bluez', '/org/bluez/hci0')
sec = dbus.Interface(adapter, 'org.bluez.Security')
ret = sec.RegisterDefaultPasskeyAgent(PATH)
print "Return",ret
main_loop = gobject.MainLoop()
main_loop.run()