Skip to content
New issue

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

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

Already on GitHub? # to your account

Distinct exit code for invalid master password #104

Closed
msladek opened this issue Nov 11, 2021 · 7 comments
Closed

Distinct exit code for invalid master password #104

msladek opened this issue Nov 11, 2021 · 7 comments

Comments

@msladek
Copy link
Contributor

msladek commented Nov 11, 2021

Hey there, firstly thanks a lot for the tool, it is very helpful when working mostly with CLI.

I recently noticed while incorporating enpasscli in some bash scripts that all non-successful exits return 1, e.g. when unable to copy because the card wasn't found:

$ enp copy asdf || echo "Exit code: $?"
Enter master password: <VALID>
FATA[0004] card not found                               
Exit code: 1

However it would be useful to have distinct exit code for providing an invalid master password. Currently it also returns 1:

$ enp copy asdf || echo "Exit code: $?"
Enter master password: <INVALID>
FATA[0001] could not retrieve cards                      error="could not retrieve cards from database: file is not a database"
Exit code: 1

Now I'm not at all familiar with golang, but if I'm not mistaken we'd simply need to add e.g. os.Exit(2) in the error checks after getting the entries from the vault. I guess that'd be sufficient for my needs at least.

WDYT?

@hazcod
Copy link
Owner

hazcod commented Nov 11, 2021

Hi @msladek!
Thanks for reporting this feature. I've added it in 0c57602.
It should pop up in a new release in a couple of minutes.

@hazcod hazcod closed this as completed Nov 11, 2021
@msladek
Copy link
Contributor Author

msladek commented Nov 11, 2021

Wow that was quick, thanks @hazcod!

Quick question: if I provide an invalid master password (with keyfile) I don't get the message could not open vault, instead I get the one above could not retrieve cards. Will it then still exit with code 1 in my case?

@hazcod
Copy link
Owner

hazcod commented Nov 11, 2021

Ohh, my mistake in being too fast.
I can look into this further for you or would appreciate a PR.

@hazcod hazcod reopened this Nov 11, 2021
@msladek
Copy link
Contributor Author

msladek commented Nov 11, 2021

I guess the problem is a different one now: why doesn't it in my case (pw+keyfile) fail already within vault.Initialize? I guess an invalid password should already fail at vault.openEncryptedDatabase.

Can you reproduce this issue or do you have a clue what could be the cause? I'd be happy to provide a PR if I knew how to solve it.

@hazcod
Copy link
Owner

hazcod commented Nov 11, 2021

I was thinking the same thing, when looking at https://github.com/hazcod/enpass-cli/blob/master/pkg/enpass/vault.go#L131

@msladek
Copy link
Contributor Author

msladek commented Jan 3, 2022

@hazcod I've found the issue, opened a PR with a solution for this.

@hazcod
Copy link
Owner

hazcod commented Jan 3, 2022

@msladek ahh that makes sense, thank you for the work! Closing.

@hazcod hazcod closed this as completed Jan 3, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants