keyring
keyring copied to clipboard
pass Get unmarshaling error
for a given entry with pass:
$ pass show dummy
plop
The given code is stumbling upon some unmarshall issue:
func Execute() {
fmt.Println(Pass("", "dummy"))
}
func Pass(prefix string,key string) string {
ring, err := keyring.Open(keyring.Config{
ServiceName: "example",
PassCmd: "pass",
AllowedBackends: []keyring.BackendType{"pass"},
PassDir: "~/.password-store",
PassPrefix: prefix,
})
if err != nil {
panic(err)
}
i, err := ring.Get(key)
if err != nil {
panic(err)
}
return string(i.Data)
}
So ring.Get(key)
is failing with the following error:
panic: invalid character 'p' looking for beginning of value
From what I could gather, in the Get function - I have annoted value I get some delve debugging.
func (k *passKeyring) Get(key string) (Item, error) {
if !k.itemExists(key) {
return Item{}, ErrKeyNotFound
}
name := filepath.Join(k.prefix, key)
// this is working
cmd := k.pass("show", name)
output, err := cmd.Output()
// output value is "plop\n"
if err != nil {
return Item{}, err
}
var decoded Item
err = json.Unmarshal(output, &decoded)
// this is failing
// in json.Unmarshal -> err := checkValid(data, &d.scan)
// is msg: "invalid character 'p' looking for beginning of value",
return decoded, err
}
I am not sure what is the issue, nor why it needs to be unmarshalled, pass is not returning no json, just a string.
Am I missing something?
Oh my god, this has been driving me nuts for hours. I can't use aws-vault
due to this. Idk how, but it just broke one day. I didn't upgrade aws-vault
. The only thing I can remember upgrading is Ubuntu from 18 to 22. After that, I started seeing this error.
What I don't understand is that the json.Unmarshal
call has been there since the beginning https://github.com/99designs/keyring/commit/40e4469399e3054bf023aa1db2144ac80a786e11#diff-fe959f3f1c2102c7721cb294b61563089edfbccada0a23e5632f82a30859f82eR51, but afaik the pass show <name>
command never returned JSON. So why was it working before?
EDIT: ok my issue with aws-vault was unrelated to this issue.
From what I understand, this lib relies on the stored data having this structure.
https://github.com/99designs/keyring/blob/master/keyring.go#L77-L86
It cannot Get
a plain string. You must Set
your string with this lib, so that it gets converted to the expected json structure.