[英]Using Secrets API with dbus-send
I'm trying to figure out how to get a password from the keyring using dbus-send
, but I'm struggling to understand what the session parameter is.我试图弄清楚如何使用
dbus-send
从密钥环获取密码,但我很难理解 session 参数是什么。
Here's where I've got to:这是我必须要做的:
#!/bin/bash
# Find key path
KEY_PATH=$(dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.SearchItems dict:string:string:"mount-point","/home/s/.mozilla/firefox" | grep -Eo '/\S+')
# Unlock keyring
RESULT=$(dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.Unlock array:objpath:$KEY_PATH | grep -Eo '/\S+')
# If unlocked...
if [ "$RESULT" = "$KEY_PATH" ]; then
# Get password
PASSWORD=$(dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.GetSecrets array:objpath:$KEY_PATH objpath:<WHAT IS SESSION?>)
# Mount ecryptfs firefox directory
echo $PASSWORD | ecryptfs-simple -o key=passphrase,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_passthrough=no,ecryptfs_enable_filename_crypto=yes,no_sig_cache=yes /home/s/.mozilla/.firefox-ecryptfs /home/s/.mozilla/firefox
firefox $@
fi
I'm lost as to how to get a session to fetch the password.我不知道如何获取 session 来获取密码。
The session needs to be created using: session 需要使用以下命令创建:
org.freedesktop.Secret.Service.OpenSession (
IN String algorithm,
IN Variant input,
OUT Variant output,
OUT ObjectPath result);
https://specifications.freedesktop.org/secret-service/latest/re01.html https://specifications.freedesktop.org/secret-service/latest/re01.html
Here is an example of creating a non-encrypted session.下面是创建非加密session 的示例。 Be aware the password returned by
GetSecret
will be a plain text as it uses a non-encrypted session:请注意,
GetSecret
返回的密码将是纯文本,因为它使用未加密的 session:
dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.OpenSession string:plain variant:string:''
The output is the objpath to the created session: output 是创建的 session 的 objpath:
variant /org/freedesktop/secrets/session/s31
Then, theoretically, you can pass the session to GetSecrets
.然后,理论上,您可以将 session 传递给
GetSecrets
。 For example:例如:
dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.GetSecrets array:objpath:/org/freedesktop/secrets/collection/login/6 objpath:/org/freedesktop/secrets/session/s31
Note: /org/freedesktop/secrets/collection/login/6
is the object path returned by SearchItems
.注意:
/org/freedesktop/secrets/collection/login/6
是 SearchItems 返回的SearchItems
路径。
However, this does not work with dbus-send.但是,这不适用于 dbus-send。 I think this is because the session is likely closed as soon as dbus-send returns.
我认为这是因为 session 可能会在 dbus-send 返回后立即关闭。
If you use d-feet, the session is retained until the d-feet window is closed.如果您使用 d-feet,则 session 将保留,直到 d-feet window 关闭。 So, you will be able to get the password using d-feet though.
因此,您将能够使用 d-feet 获取密码。 But, I understood that you want to automate it.
但是,我知道你想自动化它。
I suggest you use python3's keyring which offers to get a password using an encrypted session.我建议您使用 python3 的密钥环,它提供使用加密的 session 获取密码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.