Skip to content

Commit 549f4a1

Browse files
committed
Unbreak interactive GPG prompt upon signing
With the recent update in efee955 (gpg-interface: check gpg signature creation status, 2016-06-17), we ask GPG to send all status updates to stderr, and then catch the stderr in an strbuf. But GPG might fail, and send error messages to stderr. And we simply do not show them to the user. Even worse: this swallows any interactive prompt for a passphrase. And detaches stderr from the tty so that the passphrase cannot be read. So while the first problem could be fixed (by printing the captured stderr upon error), the second problem cannot be easily fixed, and presents a major regression. So let's just revert commit efee955. This fixes #871 Cc: Michael J Gruber <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 07221a0 commit 549f4a1

File tree

2 files changed

+2
-44
lines changed

2 files changed

+2
-44
lines changed

gpg-interface.c

+2-13
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
950950
struct child_process gpg = CHILD_PROCESS_INIT;
951951
int ret;
952952
size_t bottom;
953-
const char *cp;
954-
struct strbuf gpg_status = STRBUF_INIT;
955953

956954
strvec_pushl(&gpg.args,
957955
use_format->program,
958-
"--status-fd=2",
959956
"-bsau", signing_key,
960957
NULL);
961958

@@ -967,18 +964,10 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
967964
*/
968965
sigchain_push(SIGPIPE, SIG_IGN);
969966
ret = pipe_command(&gpg, buffer->buf, buffer->len,
970-
signature, 1024, &gpg_status, 0);
967+
signature, 1024, NULL, 0);
971968
sigchain_pop(SIGPIPE);
972969

973-
for (cp = gpg_status.buf;
974-
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
975-
cp++) {
976-
if (cp == gpg_status.buf || cp[-1] == '\n')
977-
break; /* found */
978-
}
979-
ret |= !cp;
980-
strbuf_release(&gpg_status);
981-
if (ret)
970+
if (ret || signature->len == bottom)
982971
return error(_("gpg failed to sign the data"));
983972

984973
/* Strip CR from the line endings, in case we are on Windows. */

t/t7004-tag.sh

-31
Original file line numberDiff line numberDiff line change
@@ -1375,44 +1375,13 @@ test_expect_success GPG \
13751375
'test_config user.signingkey BobTheMouse &&
13761376
test_must_fail git tag -s -m tail tag-gpg-failure'
13771377

1378-
# try to produce invalid signature
1379-
test_expect_success GPG \
1380-
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1381-
'test_config gpg.program echo &&
1382-
test_must_fail git tag -s -m tail tag-gpg-failure'
1383-
1384-
# try to produce invalid signature
1385-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1386-
git tag -s -m tail tag-gpg-double-sig &&
1387-
git cat-file tag tag-gpg-double-sig >tag &&
1388-
othersigheader=$(test_oid othersigheader) &&
1389-
sed -ne "/^\$/q;p" tag >new-tag &&
1390-
cat <<-EOM >>new-tag &&
1391-
$othersigheader -----BEGIN PGP SIGNATURE-----
1392-
someinvaliddata
1393-
-----END PGP SIGNATURE-----
1394-
EOM
1395-
sed -e "1,/^tagger/d" tag >>new-tag &&
1396-
new_tag=$(git hash-object -t tag -w new-tag) &&
1397-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1398-
git verify-tag tag-gpg-double-sig &&
1399-
git fsck
1400-
'
1401-
14021378
# try to sign with bad user.signingkey
14031379
test_expect_success GPGSM \
14041380
'git tag -s fails if gpgsm is misconfigured (bad key)' \
14051381
'test_config user.signingkey BobTheMouse &&
14061382
test_config gpg.format x509 &&
14071383
test_must_fail git tag -s -m tail tag-gpg-failure'
14081384

1409-
# try to produce invalid signature
1410-
test_expect_success GPGSM \
1411-
'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1412-
'test_config gpg.x509.program echo &&
1413-
test_config gpg.format x509 &&
1414-
test_must_fail git tag -s -m tail tag-gpg-failure'
1415-
14161385
# try to verify without gpg:
14171386

14181387
rm -rf gpghome

0 commit comments

Comments
 (0)