Skip to content

Commit a075e79

Browse files
FStelzergitster
authored andcommitted
gpg-interface/gpgsm: fix for v2.3
Checking if signing was successful will now accept '[GNUPG]: SIG_CREATED' on the beginning of the first or any subsequent line. Not just explictly the second one anymore. Gpgsm v2.3 changed its output when listing keys from `fingerprint` to `sha1/2 fpr`. This leads to the gpgsm tests silently not being executed because of a failed prerequisite. Switch to gpg's `--with-colons` output format when evaluating test prerequisites to make parsing more robust. This also allows us to combine the existing grep/cut/tr/echo pipe for writing the trustlist.txt into a single awk expression. Adjust error message checking in test for v2.3 specific output changes. Helped-By: Junio C Hamano <[email protected]> Helped-By: Todd Zullinger <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c53a8c commit a075e79

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

gpg-interface.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
920920
struct child_process gpg = CHILD_PROCESS_INIT;
921921
int ret;
922922
size_t bottom;
923+
const char *cp;
923924
struct strbuf gpg_status = STRBUF_INIT;
924925

925926
strvec_pushl(&gpg.args,
@@ -939,7 +940,13 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
939940
signature, 1024, &gpg_status, 0);
940941
sigchain_pop(SIGPIPE);
941942

942-
ret |= !strstr(gpg_status.buf, "\n[GNUPG:] SIG_CREATED ");
943+
for (cp = gpg_status.buf;
944+
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
945+
cp++) {
946+
if (cp == gpg_status.buf || cp[-1] == '\n')
947+
break; /* found */
948+
}
949+
ret |= !cp;
943950
strbuf_release(&gpg_status);
944951
if (ret)
945952
return error(_("gpg failed to sign the data"));

t/lib-gpg.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ test_lazy_prereq GPGSM '
7272
--passphrase-fd 0 --pinentry-mode loopback \
7373
--import "$TEST_DIRECTORY"/lib-gpg/gpgsm_cert.p12 &&
7474
75-
gpgsm --homedir "${GNUPGHOME}" -K |
76-
grep fingerprint: |
77-
cut -d" " -f4 |
78-
tr -d "\\n" >"${GNUPGHOME}/trustlist.txt" &&
75+
gpgsm --homedir "${GNUPGHOME}" -K --with-colons |
76+
awk -F ":" "/^fpr:/ {printf \"%s S relax\\n\", \$10}" \
77+
>"${GNUPGHOME}/trustlist.txt" &&
7978
80-
echo " S relax" >>"${GNUPGHOME}/trustlist.txt" &&
8179
echo hello | gpgsm --homedir "${GNUPGHOME}" >/dev/null \
8280
-u [email protected] -o /dev/null --sign -
8381
'

t/t4202-log.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,8 @@ test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 miss
19311931
git merge --no-ff -m msg signed_tag_x509_nokey &&
19321932
GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey >actual &&
19331933
grep "^|\\\ merged tag" actual &&
1934-
grep "^| | gpgsm: certificate not found" actual
1934+
grep -e "^| | gpgsm: certificate not found" \
1935+
-e "^| | gpgsm: failed to find the certificate: Not found" actual
19351936
'
19361937

19371938
test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 bad signature' '

0 commit comments

Comments
 (0)