Skip to content

Commit 1932c5a

Browse files
authored
Merge pull request #9196 from kareem-wolfssl/zd20038_3
Fix building and running tests and examples with coding/PEM support disabled.
2 parents 2172a4d + b302e8e commit 1932c5a

File tree

12 files changed

+413
-188
lines changed

12 files changed

+413
-188
lines changed

.github/workflows/os-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
'--disable-sys-ca-certs',
6161
'--enable-all CPPFLAGS=-DWOLFSSL_DEBUG_CERTS ',
6262
'--enable-all CFLAGS="-DWOLFSSL_CHECK_MEM_ZERO"',
63+
'--enable-coding=no',
6364
]
6465
name: make check
6566
if: github.repository_owner == 'wolfssl'

examples/client/client.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
22212221
#ifdef HAVE_RPK
22222222
int useRPK = 0;
22232223
#endif /* HAVE_RPK */
2224+
#ifdef WOLFSSL_PEM_TO_DER
22242225
int fileFormat = WOLFSSL_FILETYPE_PEM;
2226+
#else
2227+
int fileFormat = WOLFSSL_FILETYPE_ASN1;
2228+
#endif
22252229
#if defined(WOLFSSL_SYS_CRYPTO_POLICY)
22262230
const char * policy = NULL;
22272231
#endif /* WOLFSSL_SYS_CRYPTO_POLICY */

examples/echoserver/echoserver.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ THREAD_RETURN WOLFSSL_THREAD echoserver_test(void* args)
180180
if (doPSK == 0) {
181181
#if defined(HAVE_ECC) && !defined(WOLFSSL_SNIFFER)
182182
/* ecc */
183-
if (wolfSSL_CTX_use_certificate_file(ctx, eccCertFile, WOLFSSL_FILETYPE_PEM)
183+
if (wolfSSL_CTX_use_certificate_file(ctx, eccCertFile, CERT_FILETYPE)
184184
!= WOLFSSL_SUCCESS)
185185
err_sys("can't load server cert file, "
186186
"Please run from wolfSSL home dir");
187187

188-
if (wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, WOLFSSL_FILETYPE_PEM)
188+
if (wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, CERT_FILETYPE)
189189
!= WOLFSSL_SUCCESS)
190190
err_sys("can't load server key file, "
191191
"Please run from wolfSSL home dir");
@@ -196,7 +196,7 @@ THREAD_RETURN WOLFSSL_THREAD echoserver_test(void* args)
196196
err_sys("can't load server cert file, "
197197
"Please run from wolfSSL home dir");
198198

199-
if (wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile, WOLFSSL_FILETYPE_PEM)
199+
if (wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile, CERT_FILETYPE)
200200
!= WOLFSSL_SUCCESS)
201201
err_sys("can't load server key file, "
202202
"Please run from wolfSSL home dir");
@@ -208,19 +208,19 @@ THREAD_RETURN WOLFSSL_THREAD echoserver_test(void* args)
208208
"Please run from wolfSSL home dir");
209209

210210
if (wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
211-
WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
211+
CERT_FILETYPE) != WOLFSSL_SUCCESS)
212212
err_sys("can't load server key file, "
213213
"Please run from wolfSSL home dir");
214214
#elif defined(NO_CERTS)
215215
/* do nothing, just don't load cert files */
216216
#else
217217
/* normal */
218-
if (wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM)
218+
if (wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, CERT_FILETYPE)
219219
!= WOLFSSL_SUCCESS)
220220
err_sys("can't load server cert file, "
221221
"Please run from wolfSSL home dir");
222222

223-
if (wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM)
223+
if (wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, CERT_FILETYPE)
224224
!= WOLFSSL_SUCCESS)
225225
err_sys("can't load server key file, "
226226
"Please run from wolfSSL home dir");
@@ -309,7 +309,7 @@ THREAD_RETURN WOLFSSL_THREAD echoserver_test(void* args)
309309
if (ssl == NULL) err_sys("SSL_new failed");
310310
wolfSSL_set_fd(ssl, clientfd);
311311
#if !defined(NO_FILESYSTEM) && !defined(NO_DH) && !defined(NO_ASN)
312-
wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
312+
wolfSSL_SetTmpDH_file(ssl, dhParamFile, CERT_FILETYPE);
313313
#elif !defined(NO_DH)
314314
SetDH(ssl); /* will repick suites with DHE, higher than PSK */
315315
#endif

examples/server/server.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,8 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
27712771
wolfSSL_CTX_set_TicketEncCtx(ctx, &myTicketCtx);
27722772
#endif
27732773

2774-
#if defined(WOLFSSL_SNIFFER) && defined(WOLFSSL_STATIC_EPHEMERAL)
2774+
#if defined(WOLFSSL_SNIFFER) && defined(WOLFSSL_STATIC_EPHEMERAL) && \
2775+
defined(WOLFSSL_PEM_TO_DER)
27752776
/* used for testing only to set a static/fixed ephemeral key
27762777
for use with the sniffer */
27772778
#if defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
@@ -2804,7 +2805,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
28042805
err_sys_ex(runWithErrors, "error loading static X25519 key");
28052806
}
28062807
#endif
2807-
#endif /* WOLFSSL_SNIFFER && WOLFSSL_STATIC_EPHEMERAL */
2808+
#endif /* WOLFSSL_SNIFFER && WOLFSSL_STATIC_EPHEMERAL && WOLFSSL_PEM_TO_DER */
28082809

28092810
if (cipherList && !useDefCipherList) {
28102811
if (SSL_CTX_set_cipher_list(ctx, cipherList) != WOLFSSL_SUCCESS)
@@ -2849,8 +2850,13 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
28492850
WOLFSSL_FILETYPE_ASN1) != WOLFSSL_SUCCESS)
28502851
err_sys_ex(catastrophic, "can't load server cert buffer");
28512852
#elif !defined(TEST_LOAD_BUFFER)
2853+
#if defined(WOLFSSL_PEM_TO_DER)
28522854
if (SSL_CTX_use_certificate_chain_file(ctx, ourCert)
28532855
!= WOLFSSL_SUCCESS)
2856+
#else
2857+
if (wolfSSL_CTX_use_certificate_chain_file_format(ctx, ourCert,
2858+
WOLFSSL_FILETYPE_ASN1) != WOLFSSL_SUCCESS)
2859+
#endif
28542860
err_sys_ex(catastrophic, "can't load server cert file, check file "
28552861
"and run from wolfSSL home dir");
28562862
#else
@@ -2892,8 +2898,13 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
28922898
sizeof_server_key_der_2048, SSL_FILETYPE_ASN1) != WOLFSSL_SUCCESS)
28932899
err_sys_ex(catastrophic, "can't load server private key buffer");
28942900
#elif !defined(TEST_LOAD_BUFFER)
2901+
#if defined(WOLFSSL_PEM_TO_DER)
28952902
if (SSL_CTX_use_PrivateKey_file(ctx, ourKey, WOLFSSL_FILETYPE_PEM)
28962903
!= WOLFSSL_SUCCESS)
2904+
#else
2905+
if (SSL_CTX_use_PrivateKey_file(ctx, ourKey, WOLFSSL_FILETYPE_ASN1)
2906+
!= WOLFSSL_SUCCESS)
2907+
#endif
28972908
err_sys_ex(catastrophic, "can't load server private key file, "
28982909
"check file and run from wolfSSL home dir");
28992910
#ifdef WOLFSSL_DUAL_ALG_CERTS

src/ssl_certman.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ int wolfSSL_CertManagerLoadCABufferType(WOLFSSL_CERT_MANAGER* cm,
600600
ret = WOLFSSL_FATAL_ERROR;
601601
} else {
602602
if (format == WOLFSSL_FILETYPE_PEM) {
603+
#ifndef WOLFSSL_PEM_TO_DER
604+
ret = NOT_COMPILED_IN;
605+
#else
603606
ret = PemToDer(buff, sz, CERT_TYPE, &der, cm->heap, NULL, NULL);
604607
if (!ret) {
605608
/* Replace buffer pointer and size with DER buffer. */
@@ -610,6 +613,7 @@ int wolfSSL_CertManagerLoadCABufferType(WOLFSSL_CERT_MANAGER* cm,
610613
WOLFSSL_ERROR(ret);
611614
ret = WOLFSSL_FATAL_ERROR;
612615
}
616+
#endif
613617
}
614618

615619
if (ret == WOLFSSL_SUCCESS) {

src/ssl_load.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,9 +3018,15 @@ int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
30183018
}
30193019

30203020
if (file != NULL) {
3021+
#ifdef WOLFSSL_PEM_TO_DER
30213022
/* Load the PEM formatted CA file */
30223023
ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_PEM, CA_TYPE, NULL, 0,
30233024
NULL, verify);
3025+
#else
3026+
/* Load the DER formatted CA file */
3027+
ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_ASN1, CA_TYPE, NULL, 0,
3028+
NULL, verify);
3029+
#endif
30243030
#ifndef NO_WOLFSSL_DIR
30253031
if (ret == 1) {
30263032
/* Include success in overall count. */
@@ -3029,7 +3035,11 @@ int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
30293035
#endif
30303036
#if defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS)
30313037
/* Load CA as a trusted peer certificate. */
3038+
#ifdef WOLFSSL_PEM_TO_DER
30323039
ret = wolfSSL_CTX_trust_peer_cert(ctx, file, WOLFSSL_FILETYPE_PEM);
3040+
#else
3041+
ret = wolfSSL_CTX_trust_peer_cert(ctx, file, WOLFSSL_FILETYPE_ASN1);
3042+
#endif
30333043
if (ret != 1) {
30343044
WOLFSSL_MSG("wolfSSL_CTX_trust_peer_cert error");
30353045
}
@@ -3592,8 +3602,13 @@ int wolfSSL_CTX_use_certificate_chain_file(WOLFSSL_CTX* ctx, const char* file)
35923602
/* process up to MAX_CHAIN_DEPTH plus subject cert */
35933603
WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_chain_file");
35943604

3605+
#ifdef WOLFSSL_PEM_TO_DER
35953606
ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_PEM, CERT_TYPE, NULL, 1, NULL,
35963607
GET_VERIFY_SETTING_CTX(ctx));
3608+
#else
3609+
ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_ASN1, CERT_TYPE, NULL, 1, NULL,
3610+
GET_VERIFY_SETTING_CTX(ctx));
3611+
#endif
35973612

35983613
/* Return 1 on success or 0 on failure. */
35993614
return WS_RC(ret);
@@ -3895,8 +3910,13 @@ int wolfSSL_use_certificate_chain_file(WOLFSSL* ssl, const char* file)
38953910
ret = BAD_FUNC_ARG;
38963911
}
38973912
else {
3913+
#ifdef WOLFSSL_PEM_TO_DER
38983914
ret = ProcessFile(ssl->ctx, file, WOLFSSL_FILETYPE_PEM, CERT_TYPE, ssl,
38993915
1, NULL, GET_VERIFY_SETTING_SSL(ssl));
3916+
#else
3917+
ret = ProcessFile(ssl->ctx, file, WOLFSSL_FILETYPE_ASN1, CERT_TYPE, ssl,
3918+
1, NULL, GET_VERIFY_SETTING_SSL(ssl));
3919+
#endif
39003920
/* Return 1 on success or 0 on failure. */
39013921
ret = WS_RC(ret);
39023922
}
@@ -4483,8 +4503,13 @@ int wolfSSL_CTX_use_certificate_chain_buffer_format(WOLFSSL_CTX* ctx,
44834503
int wolfSSL_CTX_use_certificate_chain_buffer(WOLFSSL_CTX* ctx,
44844504
const unsigned char* in, long sz)
44854505
{
4506+
#ifdef WOLFSSL_PEM_TO_DER
44864507
return wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, in, sz,
44874508
WOLFSSL_FILETYPE_PEM);
4509+
#else
4510+
return wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, in, sz,
4511+
WOLFSSL_FILETYPE_ASN1);
4512+
#endif
44884513
}
44894514

44904515
/* Load a user certificate in a buffer into SSL.
@@ -4823,8 +4848,13 @@ int wolfSSL_use_certificate_chain_buffer_format(WOLFSSL* ssl,
48234848
int wolfSSL_use_certificate_chain_buffer(WOLFSSL* ssl, const unsigned char* in,
48244849
long sz)
48254850
{
4851+
#ifdef WOLFSSL_PEM_TO_DER
48264852
return wolfSSL_use_certificate_chain_buffer_format(ssl, in, sz,
48274853
WOLFSSL_FILETYPE_PEM);
4854+
#else
4855+
return wolfSSL_use_certificate_chain_buffer_format(ssl, in, sz,
4856+
WOLFSSL_FILETYPE_ASN1);
4857+
#endif
48284858
}
48294859

48304860
#if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \

0 commit comments

Comments
 (0)