Skip to content

Commit 1fce0d2

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 df02abf commit 1fce0d2

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
@@ -980,12 +980,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
980980
struct child_process gpg = CHILD_PROCESS_INIT;
981981
int ret;
982982
size_t bottom;
983-
const char *cp;
984-
struct strbuf gpg_status = STRBUF_INIT;
985983

986984
strvec_pushl(&gpg.args,
987985
use_format->program,
988-
"--status-fd=2",
989986
"-bsau", signing_key,
990987
NULL);
991988

@@ -997,23 +994,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
997994
*/
998995
sigchain_push(SIGPIPE, SIG_IGN);
999996
ret = pipe_command(&gpg, buffer->buf, buffer->len,
1000-
signature, 1024, &gpg_status, 0);
997+
signature, 1024, NULL, 0);
1001998
sigchain_pop(SIGPIPE);
1002999

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

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

t/t7004-tag.sh

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,44 +1403,13 @@ test_expect_success GPG \
14031403
'test_config user.signingkey BobTheMouse &&
14041404
test_must_fail git tag -s -m tail tag-gpg-failure'
14051405

1406-
# try to produce invalid signature
1407-
test_expect_success GPG \
1408-
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1409-
'test_config gpg.program echo &&
1410-
test_must_fail git tag -s -m tail tag-gpg-failure'
1411-
1412-
# try to produce invalid signature
1413-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1414-
git tag -s -m tail tag-gpg-double-sig &&
1415-
git cat-file tag tag-gpg-double-sig >tag &&
1416-
othersigheader=$(test_oid othersigheader) &&
1417-
sed -ne "/^\$/q;p" tag >new-tag &&
1418-
cat <<-EOM >>new-tag &&
1419-
$othersigheader -----BEGIN PGP SIGNATURE-----
1420-
someinvaliddata
1421-
-----END PGP SIGNATURE-----
1422-
EOM
1423-
sed -e "1,/^tagger/d" tag >>new-tag &&
1424-
new_tag=$(git hash-object -t tag -w new-tag) &&
1425-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1426-
git verify-tag tag-gpg-double-sig &&
1427-
git fsck
1428-
'
1429-
14301406
# try to sign with bad user.signingkey
14311407
test_expect_success GPGSM \
14321408
'git tag -s fails if gpgsm is misconfigured (bad key)' \
14331409
'test_config user.signingkey BobTheMouse &&
14341410
test_config gpg.format x509 &&
14351411
test_must_fail git tag -s -m tail tag-gpg-failure'
14361412

1437-
# try to produce invalid signature
1438-
test_expect_success GPGSM \
1439-
'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1440-
'test_config gpg.x509.program echo &&
1441-
test_config gpg.format x509 &&
1442-
test_must_fail git tag -s -m tail tag-gpg-failure'
1443-
14441413
# try to verify without gpg:
14451414

14461415
rm -rf gpghome

0 commit comments

Comments
 (0)