From 5059632d090df5fef0c11b4bb69e02824152dba2 Mon Sep 17 00:00:00 2001 From: Claas Lisowski Date: Thu, 31 Aug 2023 12:31:51 +0200 Subject: [PATCH 1/3] fix the totp fallback via bw cli --- src/bitwarden.go | 17 +++++++++++++++-- workflow/info.plist | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bitwarden.go b/src/bitwarden.go index 9ce05fd..c0c65bf 100644 --- a/src/bitwarden.go +++ b/src/bitwarden.go @@ -288,6 +288,8 @@ func runGetItem() { receivedItem = decryptedString } if bwData.UserId == "" || isDecryptSecretFromJsonFailed || attachment != "" { + log.Println("Falling back to Bitwarden CLI to get item.") + // Run the Bitwarden CLI to get the secret // Use it also for getting attachments if attachment != "" { @@ -297,8 +299,10 @@ func runGetItem() { message := "Failed to get Bitwarden item." args := fmt.Sprintf("%s get item %s --pretty --session %s", conf.BwExec, id, token) if totp { + log.Println("Trying to get totp via Bitwarden cli") args = fmt.Sprintf("%s get totp %s --session %s", conf.BwExec, id, token) } else if attachment != "" { + log.Println("Trying to get attachment via Bitwarden cli") args = fmt.Sprintf("%s get attachment %s --itemid %s --output %s --session %s --raw", conf.BwExec, attachment, id, conf.OutputFolder, token) } @@ -314,8 +318,17 @@ func runGetItem() { return } - receivedItem = "" - if jsonPath != "" { + if totp { + var combinedString string + for _, str := range result { + combinedString += str + " " + } + receivedItem = combinedString + } else { + receivedItem = "" + } + if jsonPath != "" && !(totp || attachment != "" || attachment == "") { + log.Println("Sent jsonPath is", jsonPath) // jsonpath operation to get only required part of the item singleString := strings.Join(result, " ") var item interface{} diff --git a/workflow/info.plist b/workflow/info.plist index 447db6a..10e40c7 100644 --- a/workflow/info.plist +++ b/workflow/info.plist @@ -2548,7 +2548,7 @@ Caching of the secret/item names (not the secret values itself) are cached so th true version - 3.0.0 + 3.0.1 webaddress https://github.com/blacs30/bitwarden-alfred-workflow From ba607264b2dd95c87f010776765c01af494be182 Mon Sep 17 00:00:00 2001 From: Claas Lisowski Date: Thu, 31 Aug 2023 12:36:15 +0200 Subject: [PATCH 2/3] remove unused code for totp --- src/bitwarden.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/bitwarden.go b/src/bitwarden.go index c0c65bf..70d2b83 100644 --- a/src/bitwarden.go +++ b/src/bitwarden.go @@ -319,11 +319,7 @@ func runGetItem() { } if totp { - var combinedString string - for _, str := range result { - combinedString += str + " " - } - receivedItem = combinedString + return } else { receivedItem = "" } From c1c1c008c9a0b0dd43d425c08fdc007d0daa7333 Mon Sep 17 00:00:00 2001 From: Claas Lisowski Date: Thu, 31 Aug 2023 12:40:40 +0200 Subject: [PATCH 3/3] don't check for attachment; otherwise never entring jsonPath checks --- src/bitwarden.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bitwarden.go b/src/bitwarden.go index 70d2b83..d2b886c 100644 --- a/src/bitwarden.go +++ b/src/bitwarden.go @@ -319,11 +319,10 @@ func runGetItem() { } if totp { - return } else { receivedItem = "" } - if jsonPath != "" && !(totp || attachment != "" || attachment == "") { + if jsonPath != "" && !totp { log.Println("Sent jsonPath is", jsonPath) // jsonpath operation to get only required part of the item singleString := strings.Join(result, " ")