Skip to content

Commit 3f97419

Browse files
committed
Return nonzero from pkcs12-create-example on a failed create so the check is not a false pass
1 parent 8b20297 commit 3f97419

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

crypto/pkcs12/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ pkcs12-create-example: pkcs12-create-example.o
1414
.PHONY: clean check
1515

1616
clean:
17-
rm -f *.o pkcs12-example pkcs12-create-example output.p12
17+
rm -f *.o pkcs12-example pkcs12-create-example output.p12 example.log create.log
1818

19-
check: SHELL := /bin/bash
20-
check: .SHELLFLAGS := -eo pipefail -c
19+
# Redirect then grep (no pipe) so the binary's nonzero exit fails the recipe and
20+
# there is no SIGPIPE on the long DER dump; both examples now return nonzero on
21+
# failure, so the exit code carries the result and the grep confirms the output.
2122
check: pkcs12-example pkcs12-create-example
22-
# capture first: grep -q closes the pipe on the long DER dump and pipefail then sees the binary's SIGPIPE
23-
out=$$(./pkcs12-example 2>&1); grep -q 'return value of parsing pkcs12 = 0 SUCCESS' <<< "$$out"
24-
out=$$(./pkcs12-create-example 2>&1); grep -q 'Printing PKCS12 DER file to output.p12' <<< "$$out"
23+
./pkcs12-example > example.log
24+
grep -q 'return value of parsing pkcs12 = 0 SUCCESS' example.log
25+
./pkcs12-create-example > create.log
26+
grep -q 'Printing PKCS12 DER file to output.p12' create.log
2527
@echo "PASS: crypto-pkcs12 checks"

crypto/pkcs12/pkcs12-create-example.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ static int createCert(byte** certDer, word32* certSz, RsaKey* key, WC_RNG* rng)
263263

264264
int main(int argc, char* argv[])
265265
{
266+
int result = 0;
266267
#if defined(HAVE_PKCS12) && defined(WOLFSSL_KEY_GEN) && \
267268
defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
268269
WC_PKCS12* pkcs12 = NULL;
@@ -316,6 +317,7 @@ int main(int argc, char* argv[])
316317
printf("Created new PKCS12 structure now converting to DER\n");
317318
if ((ret = wc_i2d_PKCS12(pkcs12, &pkcs12Der, &pkcs12DerSz)) < 0) {
318319
printf("unable to convert structure to DER\n");
320+
result = -1;
319321
}
320322
else {
321323
char output[] = "output.p12";
@@ -327,6 +329,7 @@ int main(int argc, char* argv[])
327329
}
328330
else {
329331
printf("Issue creating new PKCS12 structure\n");
332+
result = -1;
330333
}
331334

332335
wc_FreeRsaKey(&rsa);
@@ -339,5 +342,5 @@ int main(int argc, char* argv[])
339342
printf("pkcs12-create-key requires wolfssl to be built with:\n");
340343
printf("\t./configure --enable-pkcs12 --enable-pwdbased --enable-des3 --enable-keygen --enable-certgen\n");
341344
#endif
342-
return 0;
345+
return result;
343346
}

0 commit comments

Comments
 (0)