goldwarden-vaultwarden-bitw.../agent/systemauth/pinentry/pinentry.go

62 lines
1.3 KiB
Go
Raw Normal View History

2023-09-12 02:54:46 +02:00
package pinentry
2023-08-21 18:37:34 +02:00
2023-09-12 01:22:48 +02:00
import (
2024-02-09 00:24:28 +01:00
"errors"
2023-09-12 01:22:48 +02:00
"os"
"github.com/quexten/goldwarden/logging"
)
2023-09-12 02:54:46 +02:00
var log = logging.GetLogger("Goldwarden", "Pinentry")
2023-08-21 18:37:34 +02:00
var systemAuthDisabled = false
2024-02-09 00:24:28 +01:00
type Pinentry struct {
GetPassword func(title string, description string) (string, error)
GetApproval func(title string, description string) (bool, error)
}
var externalPinentry Pinentry = Pinentry{}
2023-08-21 18:37:34 +02:00
func init() {
if os.Getenv("GOLDWARDEN_SYSTEM_AUTH_DISABLED") == "true" {
systemAuthDisabled = true
}
}
2024-02-09 00:24:28 +01:00
func SetExternalPinentry(pinentry Pinentry) error {
if externalPinentry.GetPassword != nil {
return errors.New("External pinentry already set")
}
externalPinentry = pinentry
return nil
}
func GetPassword(title string, description string) (string, error) {
// password, err := getPassword(title, description)
// if err == nil {
// return password, nil
// }
if externalPinentry.GetPassword != nil {
return externalPinentry.GetPassword(title, description)
}
return "", errors.New("Not implemented")
// return password, nil
}
func GetApproval(title string, description string) (bool, error) {
// approval, err := getApproval(title, description)
// if err == nil {
// return approval, nil
// }
if externalPinentry.GetApproval != nil {
return externalPinentry.GetApproval(title, description)
}
// return approval, nil
return true, errors.New("Not implemented")
}