goldwarden-vaultwarden-bitw.../agent/systemauth/biometrics/polkit.go

102 lines
2.4 KiB
Go
Raw Normal View History

2023-09-12 01:22:48 +02:00
//go:build linux || freebsd
package biometrics
2023-08-03 00:42:31 +02:00
import (
"github.com/amenzhinsky/go-polkit"
)
const POLICY = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
2023-09-19 22:29:21 +02:00
"http://www.freedesktop.org/software/polkit/policyconfig-1.dtd">
2023-08-03 00:42:31 +02:00
<policyconfig>
2023-09-19 22:29:21 +02:00
<action id="com.quexten.goldwarden.accessvault">
<description>Allow access to the vault</description>
<message>Allows access to the vault</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
</action>
<action id="com.quexten.goldwarden.usesshkey">
<description>Use SSH Key</description>
<message>Authenticate to use an SSH Key from your vault</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
</action>
<action id="com.quexten.goldwarden.browserbiometrics">
<description>Browser Biometrics</description>
<message>Authenticate to allow Goldwarden to unlock your browser</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
</action>
2023-08-03 00:42:31 +02:00
</policyconfig>`
func CheckBiometrics(approvalType Approval) bool {
2023-09-12 01:22:48 +02:00
if biometricsDisabled {
2023-08-21 13:52:06 +02:00
return true
}
2023-08-03 00:42:31 +02:00
2023-08-21 18:37:34 +02:00
log.Info("Checking biometrics for %s", approvalType.String())
2023-08-03 00:42:31 +02:00
authority, err := polkit.NewAuthority()
if err != nil {
2023-09-19 21:49:56 +02:00
log.Error("Failed to create polkit authority: %s", err.Error())
2023-08-03 00:42:31 +02:00
return false
}
result, err := authority.CheckAuthorization(
approvalType.String(),
nil,
2023-09-19 21:49:56 +02:00
uint32(polkit.AuthenticationRequiredRetained), "",
2023-08-03 00:42:31 +02:00
)
if err != nil {
2023-09-19 21:49:56 +02:00
log.Error("Failed to create polkit authority: %s", err.Error())
2023-08-03 00:42:31 +02:00
return false
}
log.Info("Biometrics result: %t", result.IsAuthorized)
return result.IsAuthorized
}
2023-09-19 21:49:56 +02:00
func BiometricsWorking() bool {
if biometricsDisabled {
return false
}
authority, err := polkit.NewAuthority()
if err != nil {
return false
}
result, err := authority.EnumerateActions("en")
if err != nil {
return false
}
if len(result) == 0 {
return false
}
testFor := AccessVault
for _, action := range result {
if Approval(action.ActionID) == testFor {
return true
}
}
return false
}