Skip to content

Commit ab11a73

Browse files
committed
Better logging
1 parent 23e515d commit ab11a73

2 files changed

Lines changed: 36 additions & 29 deletions

File tree

examples/ocsp_responder/ocsp_responder.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ char* myoptarg = NULL;
8989
fprintf(stderr, __VA_ARGS__); \
9090
} while (0)
9191

92+
93+
#define LOG_MSG(...) \
94+
do { \
95+
printf(__VA_ARGS__); \
96+
fflush(stdout); \
97+
} while(0)
98+
9299
#ifndef _WIN32
93100
/* Signal handler flag */
94101
static volatile int got_signal = 0;
@@ -127,17 +134,17 @@ typedef struct {
127134
/* Usage help */
128135
static void Usage(void)
129136
{
130-
printf("OCSP Responder Example\n\n");
131-
printf("Usage: ocsp_responder [options]\n\n");
132-
printf("Options:\n");
133-
printf(" -? Help\n");
134-
printf(" -p <num> Port (default %d)\n", DEFAULT_PORT);
135-
printf(" -c <file> CA certificate\n");
136-
printf(" -k <file> CA private key\n");
137-
printf(" -i <file> Index file for cert status\n");
138-
printf(" -n <num> Exit after n requests\n");
139-
printf(" -v Verbose\n");
140-
printf(" -x Exclude certs from response\n");
137+
LOG_MSG("OCSP Responder Example\n\n");
138+
LOG_MSG("Usage: ocsp_responder [options]\n\n");
139+
LOG_MSG("Options:\n");
140+
LOG_MSG(" -? Help\n");
141+
LOG_MSG(" -p <num> Port (default %d)\n", DEFAULT_PORT);
142+
LOG_MSG(" -c <file> CA certificate\n");
143+
LOG_MSG(" -k <file> CA private key\n");
144+
LOG_MSG(" -i <file> Index file for cert status\n");
145+
LOG_MSG(" -n <num> Exit after n requests\n");
146+
LOG_MSG(" -v Verbose\n");
147+
LOG_MSG(" -x Exclude certs from response\n");
141148
}
142149

143150
/* Load file into buffer, auto-detect PEM vs DER */
@@ -739,7 +746,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
739746
goto cleanup;
740747
}
741748
if (opts.verbose) {
742-
printf("Loaded CA certificate: %s (%d bytes)\n", opts.certFile, caCertDerSz);
749+
LOG_MSG("Loaded CA certificate: %s (%d bytes)\n", opts.certFile, caCertDerSz);
743750
}
744751

745752
/* Load CA key */
@@ -750,7 +757,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
750757
goto cleanup;
751758
}
752759
if (opts.verbose) {
753-
printf("Loaded CA key: %s (%d bytes)\n", opts.keyFile, caKeyDerSz);
760+
LOG_MSG("Loaded CA key: %s (%d bytes)\n", opts.keyFile, caKeyDerSz);
754761
}
755762

756763
/* Parse CA certificate to get subject */
@@ -772,7 +779,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
772779
LOG_ERROR("Warning: Could not parse index file: %s\n", opts.indexFile);
773780
}
774781
else if (opts.verbose) {
775-
printf("Loaded index file: %s\n", opts.indexFile);
782+
LOG_MSG("Loaded index file: %s\n", opts.indexFile);
776783
}
777784
}
778785

@@ -792,7 +799,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
792799
goto cleanup;
793800
}
794801
if (opts.verbose) {
795-
printf("Added CA to responder\n");
802+
LOG_MSG("Added CA to responder\n");
796803
}
797804

798805
/* Populate responder with certificate statuses from index */
@@ -802,7 +809,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
802809
LOG_ERROR("Error populating responder from index: %d\n", statusCount);
803810
}
804811
else if (opts.verbose) {
805-
printf("Populated responder with %d certificate statuses\n", statusCount);
812+
LOG_MSG("Populated responder with %d certificate statuses\n", statusCount);
806813
}
807814
}
808815

@@ -813,7 +820,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
813820
ret = -1;
814821
goto cleanup;
815822
}
816-
printf("OCSP Responder listening on port %d\n", opts.port);
823+
LOG_MSG("OCSP Responder listening on port %d\n", opts.port);
817824

818825
#ifndef _WIN32
819826
/* Install signal handlers for clean shutdown */
@@ -826,7 +833,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
826833
sigaction(SIGINT, &sa, NULL);
827834
}
828835
if (opts.verbose) {
829-
printf("Signal handlers installed\n");
836+
LOG_MSG("Signal handlers installed\n");
830837
}
831838
#endif
832839

@@ -851,7 +858,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
851858
}
852859

853860
if (opts.verbose) {
854-
printf("Connection from %s:%d\n",
861+
LOG_MSG("Connection from %s:%d\n",
855862
inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port));
856863
}
857864

@@ -865,7 +872,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
865872
httpBuf[recvLen] = '\0';
866873

867874
if (opts.verbose) {
868-
printf("Received %d bytes\n", recvLen);
875+
LOG_MSG("Received %d bytes\n", recvLen);
869876
}
870877

871878
/* Parse HTTP request */
@@ -878,7 +885,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
878885
}
879886

880887
if (opts.verbose) {
881-
printf("OCSP request: %d bytes, path: %s\n", ocspReqSz, path);
888+
LOG_MSG("OCSP request: %d bytes, path: %s\n", ocspReqSz, path);
882889
}
883890

884891
/* Process OCSP request and generate response */
@@ -904,13 +911,13 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
904911
}
905912

906913
if (opts.verbose) {
907-
printf("Generated OCSP error response (status=%d): %d bytes\n",
914+
LOG_MSG("Generated OCSP error response (status=%d): %d bytes\n",
908915
errStatus, respSz);
909916
}
910917
}
911918

912919
if (opts.verbose) {
913-
printf("Generated OCSP response: %d bytes\n", respSz);
920+
LOG_MSG("Generated OCSP response: %d bytes\n", respSz);
914921
}
915922

916923
/* Send HTTP response */
@@ -924,7 +931,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
924931
requestsProcessed++;
925932

926933
if (opts.verbose) {
927-
printf("Processed request %d\n", requestsProcessed);
934+
LOG_MSG("Processed request %d\n", requestsProcessed);
928935
}
929936
}
930937

scripts/ocsp-responder-openssl-interop.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ print_responder_logs() {
9494
for log in $resp_logs; do
9595
if [ -f "$log" ]; then
9696
echo "=== $(basename $log) ==="
97-
tail -50 "$log"
97+
cat "$log"
9898
echo
9999
fi
100100
done
@@ -134,7 +134,7 @@ query_ocsp() {
134134
"$expected" "$status" "$rc"
135135
tests_failed=$((tests_failed+1))
136136
echo "--- openssl output ---"
137-
echo "$output" | tail -20
137+
echo "$output"
138138
echo "----------------------"
139139
print_responder_logs
140140
fi
@@ -201,7 +201,7 @@ echo " Responder 4 (root-ca): port $port4, pid $pid4"
201201
sleep 0.1
202202

203203
# Verify all responders are running
204-
for p in $pid1 $pid2 $pid3 $pid4; do
204+
for p in $resp_pids; do
205205
if ! kill -0 "$p" 2>/dev/null; then
206206
echo "FATAL: Responder pid $p failed to start" 1>&2
207207
exit 1
@@ -325,7 +325,7 @@ else
325325
printf "FAILED (expected OCSP internalerror, got rc: %d)\n" "$rc"
326326
tests_failed=$((tests_failed+1))
327327
echo "--- openssl output ---"
328-
echo "$output" | tail -20
328+
echo "$output"
329329
echo "----------------------"
330330
print_responder_logs
331331
fi
@@ -353,7 +353,7 @@ else
353353
printf "FAILED (expected OCSP malformedrequest, got rc: %d)\n" "$rc"
354354
tests_failed=$((tests_failed+1))
355355
echo "--- openssl output ---"
356-
echo "$output" | tail -20
356+
echo "$output"
357357
echo "----------------------"
358358
print_responder_logs
359359
fi

0 commit comments

Comments
 (0)