Skip to content

Commit d08573b

Browse files
committed
webext: Cache D-Bus connection between WebAuthn requests
1 parent 9db5b3d commit d08573b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

webext/app/credential_manager_shim.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from dbus_next import Variant
1818
from dbus_next.aio import MessageBus
19+
from dbus_next.proxy_object import BaseProxyInterface
1920
from dbus_next.constants import MessageType
2021
from dbus_next.message import Message
2122

@@ -25,6 +26,7 @@
2526

2627
APP_ID = "@APP_ID@"
2728
DBUS_DOC_FILE = "@DBUS_DOC_FILE@"
29+
INTERFACE: Optional[BaseProxyInterface] = None
2830

2931

3032
def getMessage():
@@ -409,8 +411,11 @@ async def get_passkey(interface, options, origin, top_origin):
409411
return response_json
410412

411413

412-
async def run(cmd, options, origin, top_origin):
413-
logging.debug("Executing command")
414+
async def get_interface():
415+
global INTERFACE
416+
if INTERFACE and INTERFACE.bus.connected:
417+
return INTERFACE
418+
414419
bus = await MessageBus().connect()
415420
logging.debug("Connected to bus")
416421
import os
@@ -438,11 +443,17 @@ async def run(cmd, options, origin, top_origin):
438443
"/org/freedesktop/portal/desktop",
439444
introspection,
440445
)
441-
442446
interface = proxy_object.get_interface(
443447
"org.freedesktop.portal.experimental.Credential"
444448
)
449+
INTERFACE = interface
445450
logging.debug(f"Connected to interface at {interface.path}")
451+
return INTERFACE
452+
453+
454+
async def run(cmd, options, origin, top_origin):
455+
logging.debug("Executing command")
456+
interface = await get_interface()
446457

447458
if cmd == "create":
448459
if "publicKey" in options:
@@ -477,6 +488,7 @@ async def run(cmd, options, origin, top_origin):
477488

478489
async def main():
479490
logging.info("starting credential_manager_shim")
491+
480492
while not quit.is_set():
481493
logging.debug("starting event loop message")
482494
receivedMessage = getMessage()

0 commit comments

Comments
 (0)