Skip to content

Commit 5fa3a70

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 1ae1b14 commit 5fa3a70

File tree

2 files changed

+3
-49
lines changed

2 files changed

+3
-49
lines changed

gpg-interface.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -978,12 +978,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
978978
struct child_process gpg = CHILD_PROCESS_INIT;
979979
int ret;
980980
size_t bottom;
981-
const char *cp;
982-
struct strbuf gpg_status = STRBUF_INIT;
983981

984982
strvec_pushl(&gpg.args,
985983
use_format->program,
986-
"--status-fd=2",
987984
"-bsau", signing_key,
988985
NULL);
989986

@@ -995,23 +992,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
995992
*/
996993
sigchain_push(SIGPIPE, SIG_IGN);
997994
ret = pipe_command(&gpg, buffer->buf, buffer->len,
998-
signature, 1024, &gpg_status, 0);
995+
signature, 1024, NULL, 0);
999996
sigchain_pop(SIGPIPE);
1000997

1001-
for (cp = gpg_status.buf;
1002-
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
1003-
cp++) {
1004-
if (cp == gpg_status.buf || cp[-1] == '\n')
1005-
break; /* found */
1006-
}
1007-
ret |= !cp;
1008-
if (ret) {
1009-
error(_("gpg failed to sign the data:\n%s"),
1010-
gpg_status.len ? gpg_status.buf : "(no gpg output)");
1011-
strbuf_release(&gpg_status);
1012-
return -1;
1013-
}
1014-
strbuf_release(&gpg_status);
998+
if (ret || signature->len == bottom)
999+
return error(_("gpg failed to sign the data"));
10151000

10161001
/* Strip CR from the line endings, in case we are on Windows. */
10171002
remove_cr_after(signature, bottom);

t/t7004-tag.sh

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,44 +1465,13 @@ test_expect_success GPG 'git tag -s fails if gpg is misconfigured (bad key)' '
14651465
test_must_fail git tag -s -m tail tag-gpg-failure
14661466
'
14671467

1468-
# try to produce invalid signature
1469-
test_expect_success GPG 'git tag -s fails if gpg is misconfigured (bad signature format)' '
1470-
test_config gpg.program echo &&
1471-
test_must_fail git tag -s -m tail tag-gpg-failure
1472-
'
1473-
1474-
# try to produce invalid signature
1475-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1476-
git tag -s -m tail tag-gpg-double-sig &&
1477-
git cat-file tag tag-gpg-double-sig >tag &&
1478-
othersigheader=$(test_oid othersigheader) &&
1479-
sed -ne "/^\$/q;p" tag >new-tag &&
1480-
cat <<-EOM >>new-tag &&
1481-
$othersigheader -----BEGIN PGP SIGNATURE-----
1482-
someinvaliddata
1483-
-----END PGP SIGNATURE-----
1484-
EOM
1485-
sed -e "1,/^tagger/d" tag >>new-tag &&
1486-
new_tag=$(git hash-object -t tag -w new-tag) &&
1487-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1488-
git verify-tag tag-gpg-double-sig &&
1489-
git fsck
1490-
'
1491-
14921468
# try to sign with bad user.signingkey
14931469
test_expect_success GPGSM 'git tag -s fails if gpgsm is misconfigured (bad key)' '
14941470
test_config user.signingkey BobTheMouse &&
14951471
test_config gpg.format x509 &&
14961472
test_must_fail git tag -s -m tail tag-gpg-failure
14971473
'
14981474

1499-
# try to produce invalid signature
1500-
test_expect_success GPGSM 'git tag -s fails if gpgsm is misconfigured (bad signature format)' '
1501-
test_config gpg.x509.program echo &&
1502-
test_config gpg.format x509 &&
1503-
test_must_fail git tag -s -m tail tag-gpg-failure
1504-
'
1505-
15061475
# try to verify without gpg:
15071476

15081477
test_expect_success GPG 'verify signed tag fails when public key is not present' '

0 commit comments

Comments
 (0)