简体   繁体   English

从临时 dbus 会话中解锁 gnome-keyring

[英]Unlock gnome-keyring from a temp dbus session

I'm trying to write a python application that can unlock gnome-keyring from a text-only system (headless machine) and retrieve the credentials.我正在尝试编写一个python应用程序,它可以从纯文本系统(无头机器)解锁gnome-keyring并检索凭据。 I have the gnome-keyring package installed in this machine.我在这台机器上安装了gnome-keyring包。

Basically, my application will:基本上,我的应用程序将:

  1. Start a new dbus session启动一个新的 dbus 会话
  2. Unlock the gnome-keyring in that dbus session在该 dbus 会话中解锁 gnome-keyring
  3. Extract the credentials from the keyring从密钥环中提取凭据
  4. Destroy the dbus session bus销毁dbus会话总线

I'm trying to follow this tutorial: https://pypi.org/project/keyring/#using-keyring-on-headless-linux-systems我正在尝试按照本教程进行操作: https : //pypi.org/project/keyring/#using-keyring-on-headless-linux-systems

I tried reading: Python DBUS SESSION_BUS - X11 dependency but, the OP uses dbus-launch instead of the dbus-run-session .我尝试阅读: Python DBUS SESSION_BUS - X11 dependency但是,OP 使用dbus-launch而不是dbus-run-session The original man page for dbus-launch says to use 'dbus-run-session` for text-only systems. dbus-launch的原始手册页说对纯文本系统使用“dbus-run-session”。

If I start a new dbus session using python's subprocess, how can I run the step #2 in the same dbus-session?如果我使用 python 的子进程启动一个新的 dbus 会话,我如何在同一个 dbus 会话中运行第 2 步?

You will either need to spawn a second program in your project beneath dbus-run-session , or you will need to use something other than dbus-run-session to run your own session bus.您要么需要在项目中的dbus-run-session下生成第二个程序,要么需要使用dbus-run-session以外的其他程序来运行您自己的会话总线。 dbus-run-session is designed to run a single program in its own bus; dbus-run-session旨在在其自己的总线上运行单个程序; once that program terminates, the bus is shut down.一旦该程序终止,总线就会关闭。 So either you need to provide a second program which does steps 2 and 3 from your plan, or you need to more explicitly set up and tear down your own dbus-daemon instance from your top-level program, replicating some of the behaviour of dbus-run-session .因此,要么您需要提供第二个程序来执行您计划中的第 2 步和第 3 步,要么您需要从顶级dbus-daemon更明确地设置和拆除您自己的dbus-daemon实例,复制dbus-run-session某些行为dbus-run-session

Typically this would involve:通常这将涉及:

  • Providing a dbus-daemon configuration file to use.提供要使用的dbus-daemon配置文件。
  • Running dbus-daemon --config-file=path/to/config --address=path/to/socket --nofork .运行dbus-daemon --config-file=path/to/config --address=path/to/socket --nofork
  • Setting DBUS_SESSION_BUS_ADDRESS=unix:path/to/socket in your program's environment before doing anything with the keyring.在对密钥环执行任何操作之前,在程序环境中设置DBUS_SESSION_BUS_ADDRESS=unix:path/to/socket
  • Doing whatever you need to with the keyring.用钥匙圈做任何你需要做的事情。
  • Terminating the dbus-daemon subprocess.终止dbus-daemondbus-daemon

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM