2023-07-17 03:23:26 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-17 05:02:29 +02:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2023-08-21 18:37:34 +02:00
|
|
|
"github.com/quexten/goldwarden/agent/config"
|
2023-07-17 05:02:29 +02:00
|
|
|
"github.com/quexten/goldwarden/browserbiometrics"
|
2023-07-17 03:23:26 +02:00
|
|
|
"github.com/quexten/goldwarden/cmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-08-21 18:37:34 +02:00
|
|
|
var configPath string
|
|
|
|
if path, found := os.LookupEnv("GOLDWARDEN_CONFIG_DIRECTORY"); found {
|
|
|
|
configPath = path
|
|
|
|
} else {
|
|
|
|
configPath = config.DefaultConfigPath
|
|
|
|
}
|
|
|
|
userHome, _ := os.UserHomeDir()
|
|
|
|
configPath = strings.ReplaceAll(configPath, "~", userHome)
|
|
|
|
|
|
|
|
runtimeConfig := config.RuntimeConfig{
|
2023-08-21 21:38:16 +02:00
|
|
|
WebsocketDisabled: os.Getenv("GOLDWARDEN_WEBSOCKET_DISABLED") == "true",
|
|
|
|
DisableSSHAgent: os.Getenv("GOLDWARDEN_SSH_AGENT_DISABLED") == "true",
|
|
|
|
DisableAuth: os.Getenv("GOLDWARDEN_SYSTEM_AUTH_DISABLED") == "true",
|
2023-08-21 18:37:34 +02:00
|
|
|
DisablePinRequirement: os.Getenv("GOLDWARDEN_PIN_REQUIREMENT_DISABLED") == "true",
|
|
|
|
DoNotPersistConfig: os.Getenv("GOLDWARDEN_DO_NOT_PERSIST_CONFIG") == "true",
|
|
|
|
ApiURI: os.Getenv("GOLDWARDEN_API_URI"),
|
|
|
|
IdentityURI: os.Getenv("GOLDWARDEN_IDENTITY_URI"),
|
|
|
|
SingleProcess: os.Getenv("GOLDWARDEN_SINGLE_PROCESS") == "true",
|
|
|
|
DeviceUUID: os.Getenv("GOLDWARDEN_DEVICE_UUID"),
|
|
|
|
AuthMethod: os.Getenv("GOLDWARDEN_AUTH_METHOD"),
|
|
|
|
User: os.Getenv("GOLDWARDEN_AUTH_USER"),
|
|
|
|
Password: os.Getenv("GOLDWARDEN_AUTH_PASSWORD"),
|
|
|
|
Pin: os.Getenv("GOLDWARDEN_PIN"),
|
2023-12-22 08:02:23 +01:00
|
|
|
UseMemguard: os.Getenv("GOLDWARDEN_NO_MEMGUARD") != "true",
|
2023-12-30 18:53:01 +01:00
|
|
|
SSHAgentSocketPath: os.Getenv("GOLDWARDEN_SSH_AUTH_SOCK"),
|
|
|
|
GoldwardenSocketPath: os.Getenv("GOLDWARDEN_SOCKET_PATH"),
|
2023-08-21 18:37:34 +02:00
|
|
|
|
|
|
|
ConfigDirectory: configPath,
|
|
|
|
}
|
|
|
|
|
2023-12-30 18:53:01 +01:00
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if runtimeConfig.SSHAgentSocketPath == "" {
|
|
|
|
runtimeConfig.SSHAgentSocketPath = home + "/.goldwarden-ssh-agent.sock"
|
|
|
|
}
|
|
|
|
if runtimeConfig.GoldwardenSocketPath == "" {
|
|
|
|
runtimeConfig.GoldwardenSocketPath = home + "/.goldwarden.sock"
|
|
|
|
}
|
|
|
|
|
2024-01-07 23:00:49 +01:00
|
|
|
if len(os.Args) > 1 && (strings.Contains(os.Args[1], "com.8bit.bitwarden.json") || strings.Contains(os.Args[1], "chrome-extension://")) {
|
|
|
|
browserbiometrics.Main(&runtimeConfig)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-30 18:53:01 +01:00
|
|
|
_, err = os.Stat("/.flatpak-info")
|
|
|
|
isFlatpak := err == nil
|
|
|
|
if isFlatpak {
|
|
|
|
userHome, _ := os.UserHomeDir()
|
|
|
|
runtimeConfig.ConfigDirectory = userHome + "/.var/app/com.quexten.Goldwarden/config/goldwarden.json"
|
|
|
|
runtimeConfig.ConfigDirectory = strings.ReplaceAll(runtimeConfig.ConfigDirectory, "~", userHome)
|
|
|
|
println("Flatpak Config directory: " + runtimeConfig.ConfigDirectory)
|
|
|
|
runtimeConfig.SSHAgentSocketPath = userHome + "/.var/app/com.quexten.Goldwarden/data/ssh-auth-sock"
|
|
|
|
runtimeConfig.GoldwardenSocketPath = userHome + "/.var/app/com.quexten.Goldwarden/data/goldwarden.sock"
|
|
|
|
}
|
|
|
|
|
2023-08-21 18:37:34 +02:00
|
|
|
if runtimeConfig.SingleProcess {
|
|
|
|
runtimeConfig.DisablePinRequirement = true
|
|
|
|
runtimeConfig.DisableAuth = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtimeConfig.DisablePinRequirement {
|
|
|
|
runtimeConfig.DoNotPersistConfig = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtimeConfig.DisableAuth {
|
|
|
|
os.Setenv("GOLDWARDEN_SYSTEM_AUTH_DISABLED", "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Execute(runtimeConfig)
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|