2023-07-17 06:02:29 +03:00
|
|
|
package browserbiometrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2023-12-22 17:29:58 +03:00
|
|
|
|
|
|
|
"github.com/quexten/goldwarden/browserbiometrics/logging"
|
2023-07-17 06:02:29 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const appID = "com.quexten.bw-bio-handler"
|
|
|
|
|
|
|
|
var transportKey []byte
|
|
|
|
|
|
|
|
func Main() {
|
|
|
|
if os.Args[1] == "install" {
|
|
|
|
var err error
|
|
|
|
err = detectAndInstallBrowsers(".config")
|
|
|
|
if err != nil {
|
|
|
|
panic("Failed to detect browsers: " + err.Error())
|
|
|
|
}
|
|
|
|
err = detectAndInstallBrowsers(".mozilla")
|
|
|
|
if err != nil {
|
|
|
|
panic("Failed to detect browsers: " + err.Error())
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-22 17:29:58 +03:00
|
|
|
logging.Debugf("Starting browserbiometrics")
|
2023-07-17 06:02:29 +03:00
|
|
|
transportKey = generateTransportKey()
|
2023-12-22 17:29:58 +03:00
|
|
|
logging.Debugf("Generated transport key")
|
2023-07-17 06:02:29 +03:00
|
|
|
|
|
|
|
setupCommunication()
|
|
|
|
readLoop()
|
|
|
|
}
|
|
|
|
|
2023-08-03 01:42:31 +03:00
|
|
|
func DetectAndInstallBrowsers() error {
|
|
|
|
var err error
|
|
|
|
err = detectAndInstallBrowsers(".config")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = detectAndInstallBrowsers(".mozilla")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-17 06:02:29 +03:00
|
|
|
func detectAndInstallBrowsers(startPath string) error {
|
|
|
|
home := os.Getenv("HOME")
|
|
|
|
err := filepath.Walk(home+"/"+startPath, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var tempPath string
|
|
|
|
if !strings.HasPrefix(path, home) {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
tempPath = strings.TrimPrefix(path, home)
|
|
|
|
}
|
|
|
|
if strings.Count(tempPath, "/") > 3 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-04 22:26:26 +03:00
|
|
|
binPath, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-07-17 06:02:29 +03:00
|
|
|
if info.IsDir() && info.Name() == "native-messaging-hosts" {
|
|
|
|
fmt.Printf("Found mozilla-like browser: %s\n", path)
|
2023-08-04 22:26:26 +03:00
|
|
|
manifest := strings.Replace(templateMozilla, "PATH", binPath, 1)
|
2023-07-17 06:02:29 +03:00
|
|
|
err = os.WriteFile(path+"/com.8bit.bitwarden.json", []byte(manifest), 0644)
|
|
|
|
} else if info.IsDir() && info.Name() == "NativeMessagingHosts" {
|
|
|
|
fmt.Printf("Found chrome-like browser: %s\n", path)
|
2023-08-04 22:26:26 +03:00
|
|
|
manifest := strings.Replace(templateChrome, "PATH", binPath, 1)
|
2023-07-17 06:02:29 +03:00
|
|
|
err = os.WriteFile(path+"/com.8bit.bitwarden.json", []byte(manifest), 0644)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|