This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyubikey-totp-search-provider.py
executable file
·93 lines (67 loc) · 2.95 KB
/
yubikey-totp-search-provider.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2020 Håvard Moen <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""
This file is part of gnome-search-yubikey-totp.
gnome-search-yubikey-totp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
gnome-search-yubikey-totp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <https://www.gnu.org/licenses/>.
"""
import subprocess
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import dbus.service
from gi.repository import GLib
DBusGMainLoop(set_as_default=True)
# Convenience shorthand for declaring dbus interface methods.
# s.b.n. -> search_bus_name
search_bus_name = "org.gnome.Shell.SearchProvider2"
sbn = dict(dbus_interface=search_bus_name)
def reap_child(pid, status, child):
child.wait(0)
class SearchPassService(dbus.service.Object):
"""The search daemon.
This service is started through DBus activation by calling the
:meth:`Enable` method, and stopped with :meth:`Disable`.
"""
bus_name = "name.haavard.Yubikey.SearchProvider"
_object_path = "/" + bus_name.replace(".", "/")
def __init__(self):
self.session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName(self.bus_name, bus=self.session_bus)
dbus.service.Object.__init__(self, bus_name, self._object_path)
@dbus.service.method(in_signature="sasu", **sbn)
def ActivateResult(self, id, terms, timestamp):
child = subprocess.Popen(["yubikey-totp-copy-code.py", "".join(terms[1:])])
GLib.child_watch_add(child.pid, reap_child, child)
@dbus.service.method(in_signature="as", out_signature="as", **sbn)
def GetInitialResultSet(self, terms):
return self.get_result_set(terms)
@dbus.service.method(in_signature="as", out_signature="aa{sv}", **sbn)
def GetResultMetas(self, ids):
return [dict(id=id, name=id, gicon="com.yubico.yubioath") for id in ids]
@dbus.service.method(in_signature="asas", out_signature="as", **sbn)
def GetSubsearchResultSet(self, previous_results, new_terms):
return self.get_result_set(new_terms)
@dbus.service.method(in_signature="asu", terms="as", timestamp="u", **sbn)
def LaunchSearch(self, terms, timestamp):
pass
def get_result_set(self, terms):
if len(terms) > 1 and terms[0] in ("code", "mfa", "totp"):
name = "".join(terms[1:])
return [f"Get oauth code for {name}"]
else:
return []
def main():
SearchPassService()
GLib.MainLoop().run()
if __name__ == "__main__":
main()