Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass Get unmarshaling error #120

Open
yashasolutions opened this issue Feb 5, 2023 · 1 comment
Open

pass Get unmarshaling error #120

yashasolutions opened this issue Feb 5, 2023 · 1 comment

Comments

@yashasolutions
Copy link

yashasolutions commented Feb 5, 2023

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?

@guanzo
Copy link

guanzo commented Mar 15, 2023

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 40e4469#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants