gopasspw / gopass-jsonapi

Gopass Browser Bindings
MIT License
48 stars 17 forks source link

Fails to create new entries #118

Open innovate-invent opened 6 months ago

innovate-invent commented 6 months ago

Summary

gopass-jsonapi fails to create new entries. This is caused by no recipients being selected: https://github.com/gopasspw/gopass/blob/77cc13955e85a70b9f9a3dd50e066703cd761695/internal/store/leaf/write.go#L28C2-L34

--recipients is not being appended when calling /usr/bin/gpg --quiet --yes --compress-algo=none --no-encrypt-to --no-auto-check-trustdb --encrypt. I assume because the list is empty here: https://github.com/gopasspw/gopass/blob/master/internal/backend/crypto/gpg/cli/encrypt.go#L37

I am lost in the code past this point.

Steps To Reproduce

$ echo -ne '\x70\x00\x00\x00{"type":"create","entry_name":"test","login":"foo","password":"","length":24,"generate":true,"use_symbols":true}' | GPG_TTY=/dev/pts/0 GOPASS_DEBUG=1 gopass-jsonapi listen; stty echo
You did not specify a user ID. (you may use "-r")

Current recipients:

Enter the user ID.  End with an empty line: 

Expected behavior

Should successfully create an entry with the owner as a recipient.

Environment

Git based GPG store.

Additional context

I can create / manage passwords with the gopass cli without issue.

$ cat .config/gopass/config 
[mounts]
    path = /home/nolan/.local/share/gopass/stores/root
[recipients]
    hash = 6c99eaa0ef0baee84c02c63cbce57a4764235be7be4cf6b5913499daeac4d1ab
    check = false

$ cat /home/nolan/.local/share/gopass/stores/root/.gpg-id 
0x6B26A21B58632C38

$ /usr/bin/gpg --with-colons --with-fingerprint --fixed-list-mode --list-public-keys 0x6B26A21B58632C38
tru::1:1690753575:0:3:1:5
pub:-:4096:1:6B26A21B58632C38:1690751449:::-:::scESCA::::::23:1690753800:5 http\x3a//keyserver.ubuntu.com/pks/lookup?op=get&search=0x421d842cba8ffd18152321b66b26a21b58632c38:
fpr:::::::::421D842CBA8FFD18152321B66B26A21B58632C38:
uid:-::::1690751449::080083D9CCD9124D20233109B719F98D15AAC5A7::Nolan Woods <nolan@i2labs.ca>:::::::::1690753800:5:
sub:-:4096:1:D6B842FAF9035B0C:1690751666::::::a::::::23:
fpr:::::::::D6CE130A97ED72307853003AD6B842FAF9035B0C:
sub:-:4096:1:F7A39355C1D08046:1690751449::::::e::::::23:
fpr:::::::::F92D3B3F6221A8BEE54606EBF7A39355C1D08046:
Log (click to expand) ``` 2023/12/20 22:43:42.259840 gitconfig/configs.go:163 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] trying to find global configs in [/home/nolan/.config/gopass/config] 2023/12/20 22:43:42.259885 gitconfig/configs.go:177 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] loaded global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.259892 gitconfig/configs.go:72 gitconfig.(*Configs).LoadAll Loading gitconfigs for GitConfigs{Workdir: - Env: GOPASS_CONFIG - System: /etc/gopass/config - Global: - Local: config - Worktree: config.worktree} 2023/12/20 22:43:42.259899 gitconfig/configs.go:78 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load system config: open /etc/gopass/config: no such file or directory 2023/12/20 22:43:42.259902 gitconfig/configs.go:163 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] trying to find global configs in [/home/nolan/.config/gopass/config] 2023/12/20 22:43:42.259909 gitconfig/configs.go:177 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] loaded global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.259912 gitconfig/configs.go:72 gitconfig.(*Configs).LoadAll Loading gitconfigs for GitConfigs{Workdir: /home/nolan/.local/share/gopass/stores/root - Env: GOPASS_CONFIG - System: /etc/gopass/config - Global: - Local: config - Worktree: config.worktree} 2023/12/20 22:43:42.259916 gitconfig/configs.go:78 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load system config: open /etc/gopass/config: no such file or directory 2023/12/20 22:43:42.259919 gitconfig/configs.go:151 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] reloading existing global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.259929 gitconfig/configs.go:99 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load local config from /home/nolan/.local/share/gopass/stores/root/config: open /home/nolan/.local/share/gopass/stores/root/config: no such file or directory 2023/12/20 22:43:42.259933 gitconfig/configs.go:114 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load worktree config from /home/nolan/.local/share/gopass/stores/root/config.worktree: open /home/nolan/.local/share/gopass/stores/root/config.worktree: no such file or directory 2023/12/20 22:43:42.259941 config/config.go:320 config.(*Config).migrateOptions migrateOptions running 2023/12/20 22:43:42.259944 gitconfig/configs.go:256 gitconfig.(*Configs).GetGlobal [GOPASS_CONFIG] no value for core.showsafecontent found 2023/12/20 22:43:42.259946 gitconfig/configs.go:271 gitconfig.(*Configs).GetLocal [GOPASS_CONFIG] no value for core.showsafecontent found 2023/12/20 22:43:42.259955 gitconfig/configs.go:256 gitconfig.(*Configs).GetGlobal [GOPASS_CONFIG] no value for core.autoclip found 2023/12/20 22:43:42.259962 gitconfig/configs.go:271 gitconfig.(*Configs).GetLocal [GOPASS_CONFIG] no value for core.autoclip found 2023/12/20 22:43:42.259965 gitconfig/configs.go:256 gitconfig.(*Configs).GetGlobal [GOPASS_CONFIG] no value for core.showautoclip found 2023/12/20 22:43:42.259968 gitconfig/configs.go:271 gitconfig.(*Configs).GetLocal [GOPASS_CONFIG] no value for core.showautoclip found 2023/12/20 22:43:42.259976 root/store.go:35 root.New created store Store(Path: , Mounts: ) 2023/12/20 22:43:42.259982 root/init.go:18 root.(*Store).IsInitialized initializing store and possible sub-stores 2023/12/20 22:43:42.259985 root/init.go:80 root.(*Store).initialize initialize - /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.259989 leaf/store.go:52 leaf.New Instantiating "" at "/home/nolan/.local/share/gopass/stores/root" 2023/12/20 22:43:42.260001 backend/storage.go:80 backend.DetectStorage Trying gitfs for /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.260007 fsutil/fsutil.go:36 fsutil.ExpandHomedir No tilde found in /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.260015 backend/storage.go:86 backend.DetectStorage Using detected gitfs for /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.260018 fsutil/fsutil.go:36 fsutil.ExpandHomedir No tilde found in /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.260026 fsutil/fsutil.go:36 fsutil.ExpandHomedir No tilde found in /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.260028 gitconfig/configs.go:72 gitconfig.(*Configs).LoadAll Loading gitconfigs for GitConfigs{Workdir: /home/nolan/.local/share/gopass/stores/root/.git - Env: GIT_CONFIG - System: /etc/gitconfig - Global: .gitconfig - Local: config - Worktree: config.worktree} 2023/12/20 22:43:42.260032 gitconfig/configs.go:78 gitconfig.(*Configs).LoadAll [GIT_CONFIG] failed to load system config: open /etc/gitconfig: no such file or directory 2023/12/20 22:43:42.260035 gitconfig/configs.go:163 gitconfig.(*Configs).loadGlobalConfigs [GIT_CONFIG] trying to find global configs in [/home/nolan/.config/gopass/config /home/nolan/.gitconfig] 2023/12/20 22:43:42.260042 gitconfig/configs.go:177 gitconfig.(*Configs).loadGlobalConfigs [GIT_CONFIG] loaded global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.260055 gitconfig/configs.go:103 gitconfig.(*Configs).LoadAll [GIT_CONFIG] loaded local config from /home/nolan/.local/share/gopass/stores/root/.git/config 2023/12/20 22:43:42.260060 gitconfig/configs.go:114 gitconfig.(*Configs).LoadAll [GIT_CONFIG] failed to load worktree config from /home/nolan/.local/share/gopass/stores/root/.git/config.worktree: open /home/nolan/.local/share/gopass/stores/root/.git/config.worktree: no such file or directory 2023/12/20 22:43:42.260063 leaf/store.go:64 leaf.New Storage for => /home/nolan/.local/share/gopass/stores/root initialized as gitfs(2.34.1,path:/home/nolan/.local/share/gopass/stores/root) 2023/12/20 22:43:42.260845 backend/crypto.go:80 backend.DetectCrypto Trying gpgcli for gitfs(2.34.1,path:/home/nolan/.local/share/gopass/stores/root) 2023/12/20 22:43:42.261589 fs/store.go:154 fs.(*Store).Exists Checking if '.gpg-id' exists at /home/nolan/.local/share/gopass/stores/root/.gpg-id: true 2023/12/20 22:43:42.261595 backend/crypto.go:86 backend.DetectCrypto Using gpgcli for gitfs(2.34.1,path:/home/nolan/.local/share/gopass/stores/root) 2023/12/20 22:43:42.262191 cli/loader.go:26 cli.loader.New Using Crypto Backend: gpgcli 2023/12/20 22:43:42.262200 cli/gpg.go:62 cli.New failed to read GPG config: open /home/nolan/.gnupg/gpg.conf: no such file or directory 2023/12/20 22:43:42.262717 gpgconf/binary_others.go:29 gpgconf.detectBinary gpgconf returned "/usr/bin/gpg" for gpg 2023/12/20 22:43:42.262725 cli/gpg.go:84 cli.New binary detected as /usr/bin/gpg 2023/12/20 22:43:42.262731 leaf/store.go:71 leaf.New Crypto for => /home/nolan/.local/share/gopass/stores/root initialized as &{/usr/bin/gpg [--quiet --yes --compress-algo=none --no-encrypt-to --no-auto-check-trustdb] [] [] 0xc000302360 false} 2023/12/20 22:43:42.262741 root/init.go:87 root.(*Store).initialize Root Store initialized at /home/nolan/.local/share/gopass/stores/root 2023/12/20 22:43:42.262747 root/init.go:25 root.(*Store).IsInitialized root store is initialized 2023/12/20 22:43:42.262752 fs/store.go:154 fs.(*Store).Exists Checking if '.gpg-id' exists at /home/nolan/.local/share/gopass/stores/root/.gpg-id: true 2023/12/20 22:43:42.262756 leaf/init.go:20 leaf.(*Store).IsInitialized store "/home/nolan/.local/share/gopass/stores/root" is initialized: true 2023/12/20 22:43:42.262822 fs/store.go:44 fs.(*Store).Get Reading test.gpg from /home/nolan/.local/share/gopass/stores/root/test.gpg 2023/12/20 22:43:42.262828 leaf/read.go:21 leaf.(*Store).Get File test.gpg not found: open /home/nolan/.local/share/gopass/stores/root/test.gpg: no such file or directory 2023/12/20 22:43:42.262850 secrets/akv.go:333 secrets.newScanner Using buffer of len 0 and max 0 2023/12/20 22:43:42.262855 config/context.go:36 config.FromContext no config in context, loading anew 2023/12/20 22:43:42.262859 gitconfig/configs.go:72 gitconfig.(*Configs).LoadAll Loading gitconfigs for GitConfigs{Workdir: - Env: GOPASS_CONFIG - System: /etc/gopass/config - Global: - Local: config - Worktree: config.worktree} 2023/12/20 22:43:42.262864 gitconfig/configs.go:78 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load system config: open /etc/gopass/config: no such file or directory 2023/12/20 22:43:42.262867 gitconfig/configs.go:163 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] trying to find global configs in [/home/nolan/.config/gopass/config] 2023/12/20 22:43:42.262880 gitconfig/configs.go:177 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] loaded global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.262884 gitconfig/configs.go:217 gitconfig.(*Configs).Get [GOPASS_CONFIG] no value for core.readonly found 2023/12/20 22:43:42.262889 fs/store.go:154 fs.(*Store).Exists Checking if 'test/.gpg-id' exists at /home/nolan/.local/share/gopass/stores/root/test/.gpg-id: false 2023/12/20 22:43:42.262892 fs/store.go:154 fs.(*Store).Exists Checking if '.gpg-id' exists at /home/nolan/.local/share/gopass/stores/root/.gpg-id: true 2023/12/20 22:43:42.262895 fs/store.go:44 fs.(*Store).Get Reading .gpg-id from /home/nolan/.local/share/gopass/stores/root/.gpg-id 2023/12/20 22:43:42.262904 config/context.go:36 config.FromContext no config in context, loading anew 2023/12/20 22:43:42.262907 gitconfig/configs.go:72 gitconfig.(*Configs).LoadAll Loading gitconfigs for GitConfigs{Workdir: - Env: GOPASS_CONFIG - System: /etc/gopass/config - Global: - Local: config - Worktree: config.worktree} 2023/12/20 22:43:42.262910 gitconfig/configs.go:78 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load system config: open /etc/gopass/config: no such file or directory 2023/12/20 22:43:42.262913 gitconfig/configs.go:163 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] trying to find global configs in [/home/nolan/.config/gopass/config] 2023/12/20 22:43:42.262920 gitconfig/configs.go:177 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] loaded global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.262924 fs/store.go:44 fs.(*Store).Get Reading .gpg-id from /home/nolan/.local/share/gopass/stores/root/.gpg-id 2023/12/20 22:43:42.262929 config/context.go:36 config.FromContext no config in context, loading anew 2023/12/20 22:43:42.262932 gitconfig/configs.go:72 gitconfig.(*Configs).LoadAll Loading gitconfigs for GitConfigs{Workdir: - Env: GOPASS_CONFIG - System: /etc/gopass/config - Global: - Local: config - Worktree: config.worktree} 2023/12/20 22:43:42.262935 gitconfig/configs.go:78 gitconfig.(*Configs).LoadAll [GOPASS_CONFIG] failed to load system config: open /etc/gopass/config: no such file or directory 2023/12/20 22:43:42.262938 gitconfig/configs.go:163 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] trying to find global configs in [/home/nolan/.config/gopass/config] 2023/12/20 22:43:42.262944 gitconfig/configs.go:177 gitconfig.(*Configs).loadGlobalConfigs [GOPASS_CONFIG] loaded global config from /home/nolan/.config/gopass/config 2023/12/20 22:43:42.262957 cli/keyring.go:35 cli.(*GPG).listKeys /usr/bin/gpg [/usr/bin/gpg --with-colons --with-fingerprint --fixed-list-mode --list-secret-keys 0x6B26A21B58632C38] 2023/12/20 22:43:42.264500 cli/keyring.go:35 cli.(*GPG).listKeys /usr/bin/gpg [/usr/bin/gpg --with-colons --with-fingerprint --fixed-list-mode --list-public-keys 0x6B26A21B58632C38] 2023/12/20 22:43:42.265546 cli/encrypt.go:48 cli.(*GPG).Encrypt /usr/bin/gpg [/usr/bin/gpg --quiet --yes --compress-algo=none --no-encrypt-to --no-auto-check-trustdb --encrypt] 2023/12/20 22:43:43.683843 leaf/write.go:38 leaf.(*Store).Set Failed encrypt secret: signal: interrupt ```
dominikschulz commented 6 months ago

There is a potential pitfall: key trust.

For historical reasons the gopass CLI defaults to always trust while the integrations do not. This should only matter during encryption and I don't think many users are actually using the jsonapi to create secrets. So you might be the first one to hit this issue.

See https://github.com/gopasspw/gopass/blob/master/main.go#L299

I'll add some more logging into so this becomes clearer from the logs, but to fix the issue you should make sure you properly trust your own keys.

innovate-invent commented 6 months ago

(bash) One-liner fix for anyone having this issue:

gpg --command-fd 0 --edit-key "$(<$(gopass config mounts.path)/.gpg-id)"  <<<$'trust\n5\ny\nq\n'