42 lines
705 B
Go
42 lines
705 B
Go
package pincache
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/awnumar/memguard"
|
|
"github.com/quexten/goldwarden/agent/systemauth/biometrics"
|
|
)
|
|
|
|
var cachedPin *memguard.Enclave
|
|
|
|
func SetPin(useMemguard bool, pin []byte) {
|
|
cachedPin = memguard.NewEnclave(pin)
|
|
}
|
|
|
|
func GetPin() ([]byte, error) {
|
|
approved := biometrics.CheckBiometrics(biometrics.SSHKey)
|
|
if approved {
|
|
bufer, err := cachedPin.Open()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return bufer.Bytes(), nil
|
|
} else {
|
|
return nil, errors.New("biometrics not approved")
|
|
}
|
|
}
|
|
|
|
func HasPin() bool {
|
|
return cachedPin != nil
|
|
}
|
|
|
|
func ClearPin() {
|
|
pin, err := cachedPin.Open()
|
|
if err != nil {
|
|
cachedPin = nil
|
|
return
|
|
}
|
|
pin.Destroy()
|
|
cachedPin = nil
|
|
}
|