From 623fdcb719b0fe38ddfede7c09012eefa5e01c22 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Sat, 17 Feb 2024 12:28:04 +0100 Subject: [PATCH] Add flatpak biometric setup --- browserbiometrics/main.go | 39 ++++++++++++++++++++++++++-------- browserbiometrics/manifests.go | 11 ++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/browserbiometrics/main.go b/browserbiometrics/main.go index 1535726..bc65d2e 100644 --- a/browserbiometrics/main.go +++ b/browserbiometrics/main.go @@ -108,19 +108,40 @@ func detectAndInstallBrowsers(startPath string) error { return nil } - binPath, err := os.Executable() - if err != nil { - return err - } - if info.IsDir() && info.Name() == "native-messaging-hosts" { fmt.Printf("Found mozilla-like browser: %s\n", path) - manifest := strings.Replace(templateMozilla, "PATH", binPath, 1) - err = os.WriteFile(path+"/com.8bit.bitwarden.json", []byte(manifest), 0644) + + os.Chown(path+"/com.8bit.bitwarden.json", 7, 7) + os.Remove(path + "/com.8bit.bitwarden.json") + os.Chown(path+"/goldwarden-proxy.sh", 7, 7) + os.Remove(path + "/goldwarden-proxy.sh") + + manifest := strings.Replace(templateMozilla, "PATH", path+"/goldwarden-proxy.sh", 1) + err = os.WriteFile(path+"/com.8bit.bitwarden.json", []byte(manifest), 0444) + if err != nil { + return err + } + err = os.WriteFile(path+"/goldwarden-proxy.sh", []byte(proxyScript), 0755) + if err != nil { + return err + } } else if info.IsDir() && info.Name() == "NativeMessagingHosts" { fmt.Printf("Found chrome-like browser: %s\n", path) - manifest := strings.Replace(templateChrome, "PATH", binPath, 1) - err = os.WriteFile(path+"/com.8bit.bitwarden.json", []byte(manifest), 0644) + + os.Chown(path+"/com.8bit.bitwarden.json", 7, 7) + os.Remove(path + "/com.8bit.bitwarden.json") + os.Chown(path+"/goldwarden-proxy.sh", 7, 7) + os.Remove(path + "/goldwarden-proxy.sh") + + manifest := strings.Replace(templateChrome, "PATH", path+"/goldwarden-proxy.sh", 1) + err = os.WriteFile(path+"/com.8bit.bitwarden.json", []byte(manifest), 0444) + if err != nil { + return err + } + err = os.WriteFile(path+"/goldwarden-proxy.sh", []byte(proxyScript), 0755) + if err != nil { + return err + } } return err diff --git a/browserbiometrics/manifests.go b/browserbiometrics/manifests.go index cab481f..3a7dc93 100644 --- a/browserbiometrics/manifests.go +++ b/browserbiometrics/manifests.go @@ -21,3 +21,14 @@ const templateChrome = `{ "chrome-extension://ccnckbpmaceehanjmeomladnmlffdjgn/" ] }` + +const proxyScript = `#!/bin/bash + +# Check if the "com.quexten.Goldwarden" Flatpak is installed +if flatpak list | grep -q "com.quexten.Goldwarden"; then + flatpak run --command=goldwarden com.quexten.Goldwarden "$@" +else + # If not installed, attempt to run the local version + goldwarden "$@" +fi +`