Skip to content

Commit 20f6974

Browse files
authored
Merge branch 'main' into sso-auth
2 parents f2e893e + ce852fd commit 20f6974

File tree

2 files changed

+49
-19
lines changed

2 files changed

+49
-19
lines changed

bin/rbw-pinentry-keyring

+48-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function help() {
99
Use this script as pinentry to store master password for rbw into your keyring
1010
1111
Usage
12-
- run "rbw-pinentry-keyring setup" once to save master password to keyring
12+
- run "rbw-pinentry-keyring clear" to clear the master password from your keyring
1313
- add "rbw-pinentry-keyring" as "pinentry" in rbw config (${XDG_CONFIG_HOME}/rbw/config.json)
1414
- use rbw as normal
1515
Notes
@@ -21,32 +21,62 @@ Notes
2121
EOHELP
2222
}
2323

24-
function setup() {
25-
cmd="SETTITLE rbw\n"
26-
cmd+="SETPROMPT Master Password\n"
27-
cmd+="SETDESC Please enter the master password for '$rbw_profile'\n"
28-
cmd+="GETPIN\n"
29-
password="$(printf "$cmd" | pinentry | grep -E "^D " | cut -d' ' -f2)"
30-
if [ -n "$password" ]; then
31-
echo -n "$password" | secret-tool store --label="$rbw_profile master password" application rbw profile "$rbw_profile" type master_password
32-
fi
24+
function clear() {
25+
secret-tool clear application rbw profile "$rbw_profile" type master_password
3326
}
3427

3528
function getpin() {
3629
echo 'OK'
3730

31+
title=""
32+
prompt=""
33+
desc=""
34+
3835
while IFS=' ' read -r command args ; do
3936
case "$command" in
40-
SETPROMPT|SETTITLE| SETDESC)
37+
SETTITLE)
38+
title="$args"
39+
echo 'OK'
40+
;;
41+
SETDESC)
42+
desc="$args"
43+
echo 'OK'
44+
;;
45+
SETPROMPT)
46+
prompt="$args"
4147
echo 'OK'
4248
;;
4349
GETPIN)
44-
secret_value="$(secret-tool lookup application rbw profile "$rbw_profile" type master_password)"
45-
if [ -z "$secret_value" ]; then
46-
exit 1
50+
if [[ "$prompt" == "Master Password" ]]; then
51+
set +e
52+
secret_value="$(secret-tool lookup application rbw profile "$rbw_profile" type master_password)"
53+
err=$?
54+
set -e
55+
56+
if [[ $err == 1 ]]; then
57+
cmd="SETTITLE rbw\n"
58+
cmd+="SETPROMPT Master Password\n"
59+
cmd+="SETDESC Please enter the master password for '$rbw_profile'\n"
60+
cmd+="GETPIN\n"
61+
secret_value="$(printf "$cmd" | pinentry | grep -E "^D " | cut -c3-)"
62+
if [ -n "$secret_value" ]; then
63+
echo -n "$secret_value" | secret-tool store --label="$rbw_profile master password" application rbw profile "$rbw_profile" type master_password >/dev/null 2>&1
64+
fi
65+
fi
66+
67+
printf 'D %s\n' "$secret_value"
68+
echo 'OK'
69+
else
70+
cmd="SETTITLE $title\n"
71+
cmd+="SETPROMPT $prompt\n"
72+
cmd+="SETDESC $desc\n"
73+
cmd+="GETPIN\n"
74+
75+
secret_value="$(printf "$cmd" | pinentry | grep -E "^D " | cut -c3-)"
76+
77+
printf 'D %s\n' "$secret_value"
78+
echo 'OK'
4779
fi
48-
printf 'D %s\n' "$secret_value"
49-
echo 'OK'
5080
;;
5181
BYE)
5282
exit
@@ -63,8 +93,8 @@ case "$command" in
6393
-h|--help|help)
6494
help
6595
;;
66-
-s|--setup|setup)
67-
setup
96+
-c|--clear|clear)
97+
clear
6898
;;
6999
*)
70100
getpin

src/api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ impl Client {
946946

947947
grant_type: "password".to_string(),
948948
scope: "api offline_access".to_string(),
949-
client_id: "desktop".to_string(),
949+
client_id: "cli".to_string(),
950950
device_type: 8,
951951
device_identifier: device_id.to_string(),
952952
device_name: "rbw".to_string(),

0 commit comments

Comments
 (0)