Skip to content

Commit 2ad09d3

Browse files
authored
Merge pull request #157 from linux-credentials/webext-portal
Finish migrating web extension to portal
2 parents 9db5b3d + bb81a93 commit 2ad09d3

1 file changed

Lines changed: 54 additions & 11 deletions

File tree

webext/app/credential_manager_shim.py

Lines changed: 54 additions & 11 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():
@@ -397,20 +399,31 @@ async def get_passkey(interface, options, origin, top_origin):
397399
}
398400

399401
logging.debug("Sending request to D-Bus API")
400-
rsp = await interface.call_get_credential(["", req])
401-
if rsp["type"].value != "public-key":
402+
request_event = create_portal_request_message_handler(interface.bus)
403+
req = {
404+
"handle_token": Variant("s", request_event.token),
405+
"public_key": Variant("s", req_json),
406+
}
407+
if top_origin != origin:
408+
req["top_origin"] = Variant("s", top_origin)
409+
_rsp = await interface.call_get_credential("", origin, req)
410+
result = await request_event.wait()
411+
if result["type"].value != "public-key":
402412
raise Exception(
403-
f"Invalid credential type received: expected 'public-key', received {rsp['type'].value}"
413+
f"Invalid credential type received: expected 'public-key', received {result['type'].value}"
404414
)
405415

406416
response_json = json.loads(
407-
rsp["public_key"].value["authentication_response_json"].value
417+
result["public_key"].value["authentication_response_json"].value
408418
)
409419
return response_json
410420

411421

412-
async def run(cmd, options, origin, top_origin):
413-
logging.debug("Executing command")
422+
async def get_interface():
423+
global INTERFACE
424+
if INTERFACE and INTERFACE.bus.connected:
425+
return INTERFACE
426+
414427
bus = await MessageBus().connect()
415428
logging.debug("Connected to bus")
416429
import os
@@ -438,11 +451,17 @@ async def run(cmd, options, origin, top_origin):
438451
"/org/freedesktop/portal/desktop",
439452
introspection,
440453
)
441-
442454
interface = proxy_object.get_interface(
443455
"org.freedesktop.portal.experimental.Credential"
444456
)
457+
INTERFACE = interface
445458
logging.debug(f"Connected to interface at {interface.path}")
459+
return INTERFACE
460+
461+
462+
async def run(cmd, options, origin, top_origin):
463+
logging.debug("Executing command")
464+
interface = await get_interface()
446465

447466
if cmd == "create":
448467
if "publicKey" in options:
@@ -463,10 +482,33 @@ async def run(cmd, options, origin, top_origin):
463482
f"Could not get unknown credential type: {options.keys()[0]}"
464483
)
465484
elif cmd == "getClientCapabilities":
466-
rsp = await interface.call_get_client_capabilities()
467-
response = {}
468-
for name, val in rsp.items():
469-
response[name] = val.value
485+
conditional_create = await interface.get_conditional_create()
486+
conditional_get = await interface.get_conditional_get()
487+
hybrid_transport = await interface.get_hybrid_transport()
488+
passkey_platform_authenticator = (
489+
await interface.get_passkey_platform_authenticator()
490+
)
491+
user_verifying_platform_authenticator = (
492+
await interface.get_user_verifying_platform_authenticator()
493+
)
494+
related_origins = await interface.get_related_origins()
495+
signal_all_accepted_credentials = (
496+
await interface.get_signal_all_accepted_credentials()
497+
)
498+
signal_current_user_details = await interface.get_signal_current_user_details()
499+
signal_unknown_credential = await interface.get_signal_unknown_credential()
500+
501+
response = {
502+
"conditional_create": conditional_create,
503+
"conditional_get": conditional_get,
504+
"hybrid_transport": hybrid_transport,
505+
"passkey_platform_authenticator": passkey_platform_authenticator,
506+
"user_verifying_platform_authenticator": user_verifying_platform_authenticator,
507+
"related_origins": related_origins,
508+
"signal_all_accepted_credentials": signal_all_accepted_credentials,
509+
"signal_current_user_details": signal_current_user_details,
510+
"signal_unknown_credential": signal_unknown_credential,
511+
}
470512
return response
471513
else:
472514
raise Exception(f"unknown cmd: {cmd}")
@@ -477,6 +519,7 @@ async def run(cmd, options, origin, top_origin):
477519

478520
async def main():
479521
logging.info("starting credential_manager_shim")
522+
480523
while not quit.is_set():
481524
logging.debug("starting event loop message")
482525
receivedMessage = getMessage()

0 commit comments

Comments
 (0)