Skip to content

Commit 6e5b8f2

Browse files
committed
Add ocsp responder test to testsuite.c and tested on windows
1 parent 235f9e1 commit 6e5b8f2

14 files changed

Lines changed: 245 additions & 31 deletions

File tree

IDE/WIN/user_settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
#define HAVE_CRL
4141
#define HAVE_CRL_MONITOR
4242

43+
#define HAVE_OCSP
44+
#define HAVE_OCSP_RESPONDER
45+
#define WOLFSSL_CERT_GEN
46+
#define HAVE_CERTIFICATE_STATUS_REQUEST
47+
4348
#if defined(WOLFSSL_LIB)
4449
/* The lib */
4550
#define OPENSSL_EXTRA

examples/ocsp_responder/ocsp_responder.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@
5353
#include <string.h>
5454

5555
/* Define mygetopt variables (used by mygetopt_long in test.h) */
56+
#ifndef NO_MAIN_DRIVER
5657
int myoptind = 0;
5758
char* myoptarg = NULL;
59+
#endif
5860

5961
#ifdef _WIN32
6062
#include <winsock2.h>
@@ -84,15 +86,6 @@ char* myoptarg = NULL;
8486
#define MAX_PATH_LEN 256
8587
#define MAX_CERTS 16
8688

87-
/* Simple logging macro */
88-
#define LOG_ERROR(...) \
89-
do { \
90-
if (got_signal) \
91-
fprintf(stderr, "Shutdown requested, exiting loop\n"); \
92-
else \
93-
fprintf(stderr, __VA_ARGS__); \
94-
} while (0)
95-
9689

9790
#define LOG_MSG(...) \
9891
do { \
@@ -109,6 +102,21 @@ static void sig_handler(int sig)
109102
(void)sig;
110103
got_signal = 1;
111104
}
105+
106+
/* Simple logging macro */
107+
#define LOG_ERROR(...) \
108+
do { \
109+
if (got_signal) \
110+
fprintf(stderr, "Shutdown requested, exiting loop\n"); \
111+
else \
112+
fprintf(stderr, __VA_ARGS__); \
113+
} while (0)
114+
#else
115+
/* Simple logging macro */
116+
#define LOG_ERROR(...) \
117+
do { \
118+
fprintf(stderr, __VA_ARGS__); \
119+
} while (0)
112120
#endif
113121

114122
/* Index file entry structure */
@@ -737,6 +745,8 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
737745
}
738746
}
739747

748+
myoptind = 0; /* reset for test cases */
749+
740750
/* Validate required options */
741751
if (opts.certFile == NULL) {
742752
LOG_ERROR("Error: CA certificate required (-c)\n");
@@ -855,9 +865,32 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
855865
}
856866
}
857867

868+
#ifdef USE_WINDOWS_API
869+
if (opts.port == 0) {
870+
/* Generate random port for testing */
871+
opts.port = GetRandomPort();
872+
}
873+
#endif /* USE_WINDOWS_API */
874+
858875
/* Create and listen on server socket */
859876
tcp_listen(&sockfd, &opts.port, 1, 0, 0);
860877

878+
#ifndef SINGLE_THREADED
879+
/* Signal readiness via tcp_ready if provided (for in-process testing) */
880+
if (myargs->signal != NULL) {
881+
tcp_ready* ready = myargs->signal;
882+
#ifdef WOLFSSL_COND
883+
THREAD_CHECK_RET(wolfSSL_CondStart(&ready->cond));
884+
#endif
885+
ready->ready = 1;
886+
ready->port = opts.port;
887+
#ifdef WOLFSSL_COND
888+
THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond));
889+
THREAD_CHECK_RET(wolfSSL_CondEnd(&ready->cond));
890+
#endif
891+
}
892+
#endif /* !SINGLE_THREADED */
893+
861894
/* Write ready file if requested */
862895
if (opts.readyFile != NULL) {
863896
XFILE rf = XFOPEN(opts.readyFile, "w");
@@ -1007,10 +1040,6 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
10071040
if (caKeyDer)
10081041
XFREE(caKeyDer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
10091042

1010-
#ifdef _WIN32
1011-
WSACleanup();
1012-
#endif
1013-
10141043
myargs->return_code = ret;
10151044
#ifndef WOLFSSL_THREAD_VOID_RETURN
10161045
return (THREAD_RETURN)0;
@@ -1025,6 +1054,8 @@ int main(int argc, char** argv)
10251054
func_args args;
10261055
int ret;
10271056

1057+
StartTCP();
1058+
10281059
#ifdef HAVE_WNR
10291060
if (wc_InitNetRandom(wnrConfigFile, NULL, 5000) != 0) {
10301061
err_sys("Whitewood netRandom global config failed");

src/crl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ int wolfSSL_X509_CRL_sign(WOLFSSL_X509_CRL* crl, WOLFSSL_EVP_PKEY* pkey,
25542554
CRL_Entry* entry;
25552555
byte* issuerDer = NULL;
25562556
int issuerSz = 0;
2557-
int sigType;
2557+
int sigType = 0;
25582558
int tbsSz = 0;
25592559
int totalSz = 0;
25602560
byte* buf = NULL;
@@ -2794,10 +2794,10 @@ int wolfSSL_X509_CRL_sign(WOLFSSL_X509_CRL* crl, WOLFSSL_EVP_PKEY* pkey,
27942794
*/
27952795
{
27962796
word32 idx = 0;
2797-
int len;
2797+
int len = 0;
27982798
word32 tbsStart = 0;
27992799
word32 tbsLen = 0;
2800-
int sigLen;
2800+
int sigLen = 0;
28012801

28022802
/* Parse outer SEQUENCE */
28032803
if (GetSequence(buf, &idx, &len, (word32)totalSz) < 0) {

src/pk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6015,11 +6015,11 @@ int wolfSSL_PEM_write_bio_PUBKEY(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key)
60156015
break;
60166016
#endif /* WOLFSSL_KEY_GEN && !NO_RSA */
60176017
#if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && \
6018-
(defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN))
6018+
defined(WOLFSSL_KEY_GEN)
60196019
case WC_EVP_PKEY_DSA:
60206020
ret = wolfSSL_PEM_write_bio_DSA_PUBKEY(bio, key->dsa);
60216021
break;
6022-
#endif /* !NO_DSA && !HAVE_SELFTEST && (WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN) */
6022+
#endif /* !NO_DSA && !HAVE_SELFTEST && defined(WOLFSSL_KEY_GEN) */
60236023
#if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
60246024
defined(WOLFSSL_KEY_GEN)
60256025
case WC_EVP_PKEY_EC:

src/ssl_certman.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,10 +2993,10 @@ int AddSigner(WOLFSSL_CERT_MANAGER* cm, Signer *s)
29932993
don't allow chain ones to be added w/o isCA extension */
29942994
int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
29952995
{
2996-
int ret;
2996+
int ret = 0;
29972997
Signer* signer = NULL;
2998-
word32 row;
2999-
byte* subjectHash;
2998+
word32 row = 0;
2999+
byte* subjectHash = NULL;
30003000
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
30013001
DerBuffer* der = *pDer;
30023002

src/tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3237,7 +3237,7 @@ word16 TLSX_CSR_GetSize_ex(CertificateStatusRequest* csr, byte isRequest,
32373237
if (csr->ssl != NULL && SSL_CM(csr->ssl) != NULL &&
32383238
SSL_CM(csr->ssl)->ocsp_stapling != NULL &&
32393239
SSL_CM(csr->ssl)->ocsp_stapling->statusCb != NULL) {
3240-
return OPAQUE8_LEN + OPAQUE24_LEN + csr->ssl->ocspCsrResp[idx].length;
3240+
return (word16)(OPAQUE8_LEN + OPAQUE24_LEN + csr->ssl->ocspCsrResp[idx].length);
32413241
}
32423242
return (word16)(OPAQUE8_LEN + OPAQUE24_LEN +
32433243
csr->responses[idx].length);

src/tls13.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8662,7 +8662,7 @@ static int WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
86628662
if (tmpSz > (OPAQUE8_LEN + OPAQUE24_LEN) &&
86638663
certExts[extIdx] == NULL) {
86648664
/* csr extension is not zero */
8665-
extSz[extIdx] = tmpSz;
8665+
extSz[extIdx] = (word16)tmpSz;
86668666

86678667
ret = AllocDer(&certExts[extIdx], extSz[extIdx] + ex_offset,
86688668
CERT_TYPE, ssl->heap);
@@ -8902,7 +8902,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
89028902
return ret;
89038903

89048904
ret = WriteCSRToBuffer(ssl, &ssl->buffers.certExts[0], &extSz[0],
8905-
1 /* +1 for leaf */ + ssl->buffers.certChainCnt);
8905+
1 /* +1 for leaf */ + (word16)ssl->buffers.certChainCnt);
89068906
if (ret < 0)
89078907
return ret;
89088908
totalextSz += ret;

src/x509.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11641,7 +11641,7 @@ static int CertFromX509(Cert* cert, WOLFSSL_X509* x509)
1164111641
cert->isCA = wolfSSL_X509_get_isCA(x509);
1164211642
cert->basicConstCrit = x509->basicConstCrit;
1164311643
cert->basicConstSet = x509->basicConstSet;
11644-
cert->pathLen = x509->pathLength;
11644+
cert->pathLen = (byte)x509->pathLength;
1164511645
cert->pathLenSet = x509->pathLengthSet;
1164611646

1164711647
#ifdef WOLFSSL_CERT_EXT

testsuite/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ testsuite_testsuite_test_SOURCES = \
1212
examples/echoclient/echoclient.c \
1313
examples/echoserver/echoserver.c \
1414
examples/server/server.c \
15+
examples/ocsp_responder/ocsp_responder.c \
1516
testsuite/testsuite.c
1617
testsuite_testsuite_test_CFLAGS = -DNO_MAIN_DRIVER $(AM_CFLAGS) $(WOLFSENTRY_INCLUDE)
1718
testsuite_testsuite_test_LDADD = src/libwolfssl@LIBSUFFIX@.la $(LIB_STATIC_ADD) $(WOLFSENTRY_LIB)

0 commit comments

Comments
 (0)