Skip to content

Commit f4955cd

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 343b488 commit f4955cd

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
@@ -970,12 +970,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
970970
struct child_process gpg = CHILD_PROCESS_INIT;
971971
int ret;
972972
size_t bottom;
973-
const char *cp;
974-
struct strbuf gpg_status = STRBUF_INIT;
975973

976974
strvec_pushl(&gpg.args,
977975
use_format->program,
978-
"--status-fd=2",
979976
"-bsau", signing_key,
980977
NULL);
981978

@@ -987,23 +984,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
987984
*/
988985
sigchain_push(SIGPIPE, SIG_IGN);
989986
ret = pipe_command(&gpg, buffer->buf, buffer->len,
990-
signature, 1024, &gpg_status, 0);
987+
signature, 1024, NULL, 0);
991988
sigchain_pop(SIGPIPE);
992989

993-
for (cp = gpg_status.buf;
994-
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
995-
cp++) {
996-
if (cp == gpg_status.buf || cp[-1] == '\n')
997-
break; /* found */
998-
}
999-
ret |= !cp;
1000-
if (ret) {
1001-
error(_("gpg failed to sign the data:\n%s"),
1002-
gpg_status.len ? gpg_status.buf : "(no gpg output)");
1003-
strbuf_release(&gpg_status);
1004-
return -1;
1005-
}
1006-
strbuf_release(&gpg_status);
990+
if (ret || signature->len == bottom)
991+
return error(_("gpg failed to sign the data"));
1007992

1008993
/* Strip CR from the line endings, in case we are on Windows. */
1009994
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)