atom / github

:octocat: Git and GitHub integration for Atom
https://github.atom.io
MIT License
1.11k stars 393 forks source link

Atom fails to accept password to sign commit #1518

Open Arcanemagus opened 6 years ago

Arcanemagus commented 6 years ago

Prerequisites

Description

If you normally use a GPG agent to sign the commit, but attempt to cancel the dialog from that Atom will present you a dialog of its own to gather the passphrase for the key, but entering the correct passphrase fails to sign the commit with an error message.

Steps to Reproduce

  1. Ensure you will get a prompt for the key by stopping any running gpg-agent with gpgconf --kill gpg-agent
  2. Be in a repository/environment where commits are signed (commit.gpgsign=true)
  3. Attempt to commit through Atom, the normal GPG agent window should show.
  4. Cancel this window
  5. Atom should now show its own dialog for entering the passphrase for the key
  6. Enter the correct passphrase (or an incorrect one, it doesn't matter...)
  7. Watch it fail to commit.

Expected behavior:

Atom to sign the commit.

Actual behavior:

Atom fails to sign the commit with the following stack trace:

Uncaught (in promise) GitError: git commit --cleanup=strip -m foo in C:\Users\abneyl\Documents\GitHub\linter-flake8 exited with code 128
stdout: 
stderr: 15:02:45.041030 exec_cmd.c:236          trace: resolved executable dir: C:/Users/abneyl/AppData/Local/Atom x64/app-dev/resources/app.asar.unpacked/node_modules/dugite/git/mingw64/bin
15:02:45.043963 git.c:344               trace: built-in: git commit --cleanup=strip -m foo
15:02:45.055963 run-command.c:640       trace: run_command: 'C:\Users\abneyl\AppData\Local\Temp\github-11858-7460-1nfaufe.bpb2\gpg-wrapper.sh' -bsau 4414384AEEE3FB2B
15:02:45.108964 exec_cmd.c:236          trace: resolved executable dir: C:/Users/abneyl/AppData/Local/Atom x64/app-dev/resources/app.asar.unpacked/node_modules/dugite/git/mingw64/bin
15:02:45.109964 git.c:344               trace: built-in: git config gpg.program
15:02:45.132961 exec_cmd.c:236          trace: resolved executable dir: C:/Users/abneyl/AppData/Local/Atom x64/app-dev/resources/app.asar.unpacked/node_modules/dugite/git/mingw64/bin
15:02:45.133963 git.c:344               trace: built-in: git config user.signingkey
git-askpass-atom: no user askpass specified
git-askpass-atom: requesting dialog through Atom socket
git-askpass-atom: prompt = "Please enter the passphrase for the GPG key '4414384AEEE3FB2B'."
git-askpass-atom: connection established
git-askpass-atom: writing payload
git-askpass-atom: payload written
git-askpass-atom: Atom socket stream terminated
git-askpass-atom: Atom reply parsed
git-askpass-atom: success
gpg: failed to translate osfhandle 0x00000003
error: gpg failed to sign the data
fatal: failed to write commit object

    at new GitError (C:\Users\abneyl\AppData\Local\Atom x64\app-dev\resources\app\node_modules\github\lib\git-shell-out-strategy.js:121:24)
    at Promise (C:\Users\abneyl\AppData\Local\Atom x64\app-dev\resources\app\node_modules\github\lib\git-shell-out-strategy.js:385:29)
    at <anonymous>

2018-06-08_15-17-08

Reproduces how often:

100% of the time.

Versions

OS: Windows 10 x64 Enterprise

# atom --version
Atom    : 1.29.0-dev-9e0065c8f
Electron: 2.0.1
Chrome  : 61.0.3163.100
Node    : 8.9.3

# apm --version
apm  1.19.0
npm  3.10.10
node 6.9.5 x64
atom 1.29.0-dev-9e0065c8f
python 2.7.15
git 2.17.0.windows.1
visual studio 2015

# gpg --version
gpg (GnuPG) 2.2.7
libgcrypt 1.8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: C:/Users/abneyl/AppData/Roaming/gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

Additional Information

I've manually specified gpg.program to be C:\Program Files (x86)\GnuPG\bin\gpg.exe instead of letting git determine it automatically. It's been a while since I set it up, but this was necessary to get things working properly with the GPG agent.

Note: This is possibly the same issue at its core as https://github.com/atom/github/issues/814, but with a different stack trace.

50Wliu commented 6 years ago

I get the same 0x00000003 handle error. I also have gpg.program manually set.

smashwilson commented 6 years ago

It's been a while, but I believe gpg 2.2.x doesn't work with Atom's credential dialog because gpg has been deprecating the --passphrase-fd option that we use to provide the entered passphrase. (I think it was 2.1 that gated it behind a non-default gpg-agent configuration option, and 2.2 ignored it entirely). The "real solution" here is to create an isolated GNUPGHOME with a dedicated gpg-agent process configured with a pinentry program that talks back to Atom through the named pipe we use for passwords elsewhere. This is what I was working toward with squeegpg, but alas that keeps being bumped for other priorities.

In the meantime, you'll likely have the best luck configuring your gpg-agent to use a graphical pinentry program. I got one automatically when I installed gpg4win - I'm not sure if they offer it as a stand-alone download, though.

Arcanemagus commented 6 years ago

In the meantime, you'll likely have the best luck configuring your gpg-agent to use a graphical pinentry program.

Just to note, steps 3-4 are to explicitly cancel exactly that so this can be reproduced 😆.

smashwilson commented 6 years ago

Oh! Right, I see that now.

Unfortunately I don't think I can distinguish an explicit cancellation of the native pinentry from a pinentry failure due to not being able to allocate a tty (which is the normal case we want to intercept). I think implementing a custom pinentry ourselves is still the path forward here.

the-j0k3r commented 6 years ago

Im confused with this report, this is nothing new and well known @smashwilson since https://github.com/atom/github/pull/846 and https://github.com/atom/github/issues/1373

You have to use the GPG pinentry because the built in one DOESNT work for yonks.

Or am I missing something?

Edit: Ive now left a trail of breadcrumbs related to this issue and picking on #814, past work #846 and current work into #1373 so anyone paying attention to that relation can goto in a jip.

Arcanemagus commented 6 years ago

Im confused with this report, this is nothing new and well known @smashwilson since #846 and #1373

846 definitely seems to cover the root of this issue, feel free to close this in favor of that @smashwilson!

This was mainly filed due to the stack trace not having been recorded yet @the-j0k3r 😉.

Edit: Ive now left a trail of breadcrumbs related to this issue and picking on #814

If you read the additional information section I actually already said that this is probably the same issue at the core as #814, but as it's a different platform and different stack trace it's not actually the same issue.

Thanks for linking everything together!

the-j0k3r commented 6 years ago

This was mainly filed due to the stack trace not having been recorded yet @the-j0k3r wink.

who knows the other issues I quoted are closed, so maybe just like you said.

If you read the additional information section I actually already said that this is probably the same issue at the core as #814, but as it's a different platform and different stack trace it's not actually the same issue.

Thanks for linking everything together!

Yes ;) this is one of those instances where the right kind of bot would probably do same job, sadly the only bot I know that checks for duplicates and such things still requires human interaction by someone with access to trigger it, that said, Im happy to do such linking once in a while in issues that interest me/affect me once in a while.

I thinks its helpful so you're welcome and thanks :)

lucknaumann commented 4 years ago

Well, thought I'd throw my hat into the "GPG not working with commits" ring here. Since there are a number of these issues I decided not to open yet another one, even though my issue is slightly different so stack trace error also differs. Of course, if you want me to open another one, I will. :smile:

Windows 10 v1809 Home. I never got the pinentry from an outside GPG program, just the internal Atom one. Not until I changed git config --global gpg.program from C:/Program Files/Git/usr/bin/gpg.exe to C:/Program Files (x86)/GnuPG/bin/gpg.exe. Then I got the GPG4Win pinentry and it actually worked. But Atom's pinentry doesn't.

What happens with Git for Windows as the git config --global gpg.program C:/Program Files/Git/usr/bin/gpg.exe is that the pinentry works with other Git Clients, like GitHub Desktop, but in Atom I get the internal Atom pinentry, which refuses to work. Atom knew my Git GPG key so it must have read from the Git for Windows GPG and not GPG4Win as that one didn't have my keys imported (did that later). I tried adding each gpg pinentry program (Git for Windows and GPG4Win) into gpg-agent.conf via pinentry-program path\program.exe with no difference in results (although, maybe I did something wrong with this setting). See below for trace output with Git for Windows git config --global gpg.program used, Git Diagnostics enabled and the internal Atom pinentry used.

Unable to commit

00:06:56.691068 exec-cmd.c:236          trace: resolved executable dir: C:/Users/ME/AppData/Local/atom/app-1.45.0/resources/app.asar.unpacked/node_modules/dugite/git/mingw64/bin
00:06:56.694066 git.c:415               trace: built-in: git commit --cleanup=verbatim -m 'Will GPG work with Atom?'
00:06:56.701067 run-command.c:643       trace: run_command: 'C:\Users\ME\AppData\Local\Temp\github-2020327-112024-17hexop.ljrd\gpg-wrapper.sh' -bsau THIS-IS-MY-KEY
00:06:56.882958 exec-cmd.c:236          trace: resolved executable dir: C:/Users/ME/AppData/Local/atom/app-1.45.0/resources/app.asar.unpacked/node_modules/dugite/git/mingw64/bin
00:06:56.884957 git.c:415               trace: built-in: git config gpg.program
00:06:57.099818 exec-cmd.c:236          trace: resolved executable dir: C:/Users/ME/AppData/Local/atom/app-1.45.0/resources/app.asar.unpacked/node_modules/dugite/git/mingw64/bin
00:06:57.100818 git.c:415               trace: built-in: git config user.signingkey
git-askpass-atom: no user askpass specified
git-askpass-atom: requesting dialog through Atom socket
git-askpass-atom: prompt = "Please enter the passphrase for the GPG key 'THIS-IS-MY-KEY'."
git-askpass-atom: connection established
git-askpass-atom: writing query
git-askpass-atom: query written
git-askpass-atom: Atom socket stream terminated
git-askpass-atom: Atom reply parsed
git-askpass-atom: success
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
gpg: no valid OpenPGP data found.
gpg: processing message failed: Unknown system error
error: gpg failed to sign the data
fatal: failed to write commit object
ryleu commented 3 years ago

Same here. Both of the IntelliJ based editors I use (Android Studio and IDEA) use the normal gpg4win dialog, while Atom uses its own thing and throws errors. I'm not able to commit since I started signing everything.

Edit: If I use git4win it uses the gpg4win dialog thingy too, so I started just using that temporarily.