Skip to content

Commit 9aa0742

Browse files
authored
Merge pull request #7798 from dgarske/asn_macros
ASN macro simplification merged with github CI tests failing due to unrelated upstream changes (same tests all previously succeeded on this PR, with only 25d14f1 added in the meantime). supplementary testing with `wolfssl-multi-test.sh ... super-quick-check` after rebase on then-current `master` 15e99c8.
2 parents 35b45aa + 25d14f1 commit 9aa0742

21 files changed

Lines changed: 815 additions & 697 deletions

File tree

configure.ac

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ AC_ARG_ENABLE([ffmpeg],
19921992
)
19931993

19941994

1995-
#IP alternative name Support
1995+
# IP alternative name Support
19961996
AC_ARG_ENABLE([ip-alt-name],
19971997
[AS_HELP_STRING([--enable-ip-alt-name],[Enable IP subject alternative name (default: disabled)])],
19981998
[ ENABLE_IP_ALT_NAME=$enableval ],
@@ -2004,7 +2004,7 @@ then
20042004
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_IP_ALT_NAME"
20052005
fi
20062006

2007-
#Qt Support
2007+
# QT Support
20082008
AC_ARG_ENABLE([qt],
20092009
[AS_HELP_STRING([--enable-qt],[Enable qt (default: disabled)])],
20102010
[ ENABLED_QT=$enableval ],
@@ -4743,43 +4743,52 @@ fi
47434743

47444744

47454745
# ASN
4746+
47464747
# turn off asn, which means no certs, no rsa, no dsa, no ecc,
47474748
# and no big int (unless dh is on)
4749+
4750+
# turn off ASN if leanpsk on
4751+
if test "$ENABLED_LEANPSK" = "yes"
4752+
then
4753+
enable_asn=no
4754+
fi
4755+
47484756
AC_ARG_ENABLE([asn],
47494757
[AS_HELP_STRING([--enable-asn],[Enable ASN (default: enabled)])],
47504758
[ ENABLED_ASN=$enableval ],
47514759
[ ENABLED_ASN=yes ]
47524760
)
47534761

4754-
if test "$ENABLED_ASN" = "no"
4755-
then
4756-
AM_CFLAGS="$AM_CFLAGS -DNO_ASN -DNO_ASN_CRYPT"
4757-
enable_pwdbased=no
4758-
else
4759-
if test "$ENABLED_ASN" = "template"; then
4760-
ENABLED_ASN="yes"
4761-
fi
4762-
if test "$ENABLED_ASN" = "yes"; then
4762+
for v in `echo $ENABLED_ASN | tr "," " "`
4763+
do
4764+
case $v in
4765+
all)
4766+
# Enable all ASN features
4767+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ASN_ALL"
4768+
ENABLED_ASN=yes
4769+
;;
4770+
template | yes)
47634771
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ASN_TEMPLATE"
4764-
elif test "$ENABLED_ASN" = "original"; then
4772+
ENABLED_ASN=yes
4773+
;;
4774+
original)
47654775
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ASN_ORIGINAL"
4766-
else
4767-
AC_MSG_ERROR([Invalid asn option. Valid are: template or original. Seen: $ENABLED_ASN.])
4768-
fi
4769-
4770-
# turn off ASN if leanpsk on
4771-
if test "$ENABLED_LEANPSK" = "yes"
4772-
then
4773-
AM_CFLAGS="$AM_CFLAGS -DNO_ASN -DNO_BIG_INT"
4776+
ENABLED_ASN=yes
4777+
;;
4778+
nocrypt)
4779+
AM_CFLAGS="$AM_CFLAGS -DNO_ASN_CRYPT"
4780+
enable_pwdbased=no
4781+
;;
4782+
no)
4783+
AM_CFLAGS="$AM_CFLAGS -DNO_ASN -DNO_ASN_CRYPT"
4784+
enable_pwdbased=no
47744785
ENABLED_ASN=no
4775-
else
4776-
if test "$ENABLED_ASN" = "nocrypt"
4777-
then
4778-
AM_CFLAGS="$AM_CFLAGS -DNO_ASN_CRYPT"
4779-
enable_pwdbased=no
4780-
fi
4781-
fi
4782-
fi
4786+
;;
4787+
*)
4788+
AC_MSG_ERROR([Invalid asn option. Valid are: all, template/yes, original, nocrypt or no. Seen: $ENABLED_ASN.])
4789+
break;;
4790+
esac
4791+
done
47834792

47844793
if test "$ENABLED_RSA" = "yes" && test "$ENABLED_RSAVFY" = "no" && \
47854794
test "$ENABLED_ASN" = "no" && test "$ENABLED_LOWRESOURCE" = "no"

src/internal.c

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12543,13 +12543,13 @@ int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen,
1254312543
while (altName) {
1254412544
WOLFSSL_MSG("\tindividual AltName check");
1254512545

12546-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
12546+
#ifdef WOLFSSL_IP_ALT_NAME
1254712547
if (altName->type == ASN_IP_TYPE) {
1254812548
buf = altName->ipString;
1254912549
len = (word32)XSTRLEN(buf);
1255012550
}
1255112551
else
12552-
#endif /* OPENSSL_ALL || WOLFSSL_IP_ALT_NAME */
12552+
#endif /* WOLFSSL_IP_ALT_NAME */
1255312553
{
1255412554
buf = altName->name;
1255512555
len = (word32)altName->len;
@@ -12820,6 +12820,7 @@ static int CopyREQAttributes(WOLFSSL_X509* x509, DecodedCert* dCert)
1282012820
int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1282112821
{
1282212822
int ret = 0;
12823+
int minSz;
1282312824

1282412825
if (x509 == NULL || dCert == NULL ||
1282512826
dCert->subjectCNLen < 0)
@@ -12869,49 +12870,45 @@ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1286912870
#endif /* WOLFSSL_CERT_REQ */
1287012871

1287112872
#ifdef WOLFSSL_SEP
12872-
{
12873-
int minSz = min(dCert->deviceTypeSz, EXTERNAL_SERIAL_SIZE);
12874-
if (minSz > 0) {
12875-
x509->deviceTypeSz = minSz;
12876-
XMEMCPY(x509->deviceType, dCert->deviceType, minSz);
12877-
}
12878-
else
12879-
x509->deviceTypeSz = 0;
12880-
minSz = min(dCert->hwTypeSz, EXTERNAL_SERIAL_SIZE);
12881-
if (minSz > 0) {
12882-
x509->hwTypeSz = minSz;
12883-
XMEMCPY(x509->hwType, dCert->hwType, minSz);
12884-
}
12885-
else
12886-
x509->hwTypeSz = 0;
12887-
minSz = min(dCert->hwSerialNumSz, EXTERNAL_SERIAL_SIZE);
12888-
if (minSz > 0) {
12889-
x509->hwSerialNumSz = minSz;
12890-
XMEMCPY(x509->hwSerialNum, dCert->hwSerialNum, minSz);
12891-
}
12892-
else
12893-
x509->hwSerialNumSz = 0;
12873+
minSz = min(dCert->deviceTypeSz, EXTERNAL_SERIAL_SIZE);
12874+
if (minSz > 0) {
12875+
x509->deviceTypeSz = minSz;
12876+
XMEMCPY(x509->deviceType, dCert->deviceType, minSz);
12877+
}
12878+
else
12879+
x509->deviceTypeSz = 0;
12880+
minSz = min(dCert->hwTypeSz, EXTERNAL_SERIAL_SIZE);
12881+
if (minSz > 0) {
12882+
x509->hwTypeSz = minSz;
12883+
XMEMCPY(x509->hwType, dCert->hwType, minSz);
12884+
}
12885+
else
12886+
x509->hwTypeSz = 0;
12887+
minSz = min(dCert->hwSerialNumSz, EXTERNAL_SERIAL_SIZE);
12888+
if (minSz > 0) {
12889+
x509->hwSerialNumSz = minSz;
12890+
XMEMCPY(x509->hwSerialNum, dCert->hwSerialNum, minSz);
1289412891
}
12892+
else
12893+
x509->hwSerialNumSz = 0;
1289512894
#endif /* WOLFSSL_SEP */
12896-
{
12897-
int minSz;
12898-
if (dCert->beforeDateLen > 0) {
12899-
minSz = (int)min(dCert->beforeDate[1], MAX_DATE_SZ);
12900-
x509->notBefore.type = dCert->beforeDate[0];
12901-
x509->notBefore.length = minSz;
12902-
XMEMCPY(x509->notBefore.data, &dCert->beforeDate[2], minSz);
12903-
}
12904-
else
12905-
x509->notBefore.length = 0;
12906-
if (dCert->afterDateLen > 0) {
12907-
minSz = (int)min(dCert->afterDate[1], MAX_DATE_SZ);
12908-
x509->notAfter.type = dCert->afterDate[0];
12909-
x509->notAfter.length = minSz;
12910-
XMEMCPY(x509->notAfter.data, &dCert->afterDate[2], minSz);
12911-
}
12912-
else
12913-
x509->notAfter.length = 0;
12895+
12896+
if (dCert->beforeDateLen > 0) {
12897+
minSz = (int)min(dCert->beforeDate[1], MAX_DATE_SZ);
12898+
x509->notBefore.type = dCert->beforeDate[0];
12899+
x509->notBefore.length = minSz;
12900+
XMEMCPY(x509->notBefore.data, &dCert->beforeDate[2], minSz);
12901+
}
12902+
else
12903+
x509->notBefore.length = 0;
12904+
if (dCert->afterDateLen > 0) {
12905+
minSz = (int)min(dCert->afterDate[1], MAX_DATE_SZ);
12906+
x509->notAfter.type = dCert->afterDate[0];
12907+
x509->notAfter.length = minSz;
12908+
XMEMCPY(x509->notAfter.data, &dCert->afterDate[2], minSz);
1291412909
}
12910+
else
12911+
x509->notAfter.length = 0;
1291512912

1291612913
if (dCert->publicKey != NULL && dCert->pubKeySize != 0) {
1291712914
x509->pubKey.buffer = (byte*)XMALLOC(
@@ -13050,7 +13047,7 @@ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1305013047
ret = MEMORY_E;
1305113048
}
1305213049
}
13053-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
13050+
#ifdef WOLFSSL_ASN_CA_ISSUER
1305413051
if (dCert->extAuthInfoCaIssuer != NULL && dCert->extAuthInfoCaIssuerSz > 0) {
1305513052
x509->authInfoCaIssuer = (byte*)XMALLOC(dCert->extAuthInfoCaIssuerSz, x509->heap,
1305613053
DYNAMIC_TYPE_X509_EXT);
@@ -13136,10 +13133,10 @@ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1313613133
#ifndef IGNORE_NETSCAPE_CERT_TYPE
1313713134
x509->nsCertType = dCert->nsCertType;
1313813135
#endif
13139-
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_QT)
13136+
#ifdef WOLFSSL_SEP
1314013137
x509->certPolicySet = dCert->extCertPolicySet;
1314113138
x509->certPolicyCrit = dCert->extCertPolicyCrit;
13142-
#endif /* WOLFSSL_SEP || WOLFSSL_QT */
13139+
#endif
1314313140
#ifdef WOLFSSL_CERT_EXT
1314413141
{
1314513142
int i;

src/ocsp.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int GetOcspStatus(WOLFSSL_OCSP* ocsp, OcspRequest* request,
284284
* ocsp Context object for OCSP status.
285285
* response OCSP response message data.
286286
* responseSz Length of OCSP response message data.
287-
* reponseBuffer Buffer object to return the response with.
287+
* responseBuffer Buffer object to return the response with.
288288
* status The certificate status object.
289289
* entry The OCSP entry for this certificate.
290290
* ocspRequest Request corresponding to response.
@@ -668,8 +668,9 @@ int CheckOcspResponder(OcspResponse *bs, DecodedCert *cert, void* vp)
668668
return ret;
669669
}
670670

671-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
672-
defined(WOLFSSL_APACHE_HTTPD) || defined(HAVE_LIGHTY)
671+
672+
/* compatibility layer OCSP functions */
673+
#ifdef OPENSSL_EXTRA
673674
int wolfSSL_OCSP_resp_find_status(WOLFSSL_OCSP_BASICRESP *bs,
674675
WOLFSSL_OCSP_CERTID* id, int* status, int* reason,
675676
WOLFSSL_ASN1_TIME** revtime, WOLFSSL_ASN1_TIME** thisupd,
@@ -695,10 +696,17 @@ int wolfSSL_OCSP_resp_find_status(WOLFSSL_OCSP_BASICRESP *bs,
695696

696697
if (status != NULL)
697698
*status = single->status->status;
699+
#ifdef WOLFSSL_OCSP_PARSE_STATUS
698700
if (thisupd != NULL)
699701
*thisupd = &single->status->thisDateParsed;
700702
if (nextupd != NULL)
701703
*nextupd = &single->status->nextDateParsed;
704+
#else
705+
if (thisupd != NULL)
706+
*thisupd = NULL;
707+
if (nextupd != NULL)
708+
*nextupd = NULL;
709+
#endif
702710

703711
/* TODO: Not needed for Nginx or httpd */
704712
if (reason != NULL)
@@ -872,10 +880,8 @@ int wolfSSL_OCSP_basic_verify(WOLFSSL_OCSP_BASICRESP *bs,
872880
return WOLFSSL_FAILURE;
873881
#endif
874882

875-
#ifdef OPENSSL_EXTRA
876883
if (bs->verifyError != OCSP_VERIFY_ERROR_NONE)
877884
goto out;
878-
#endif
879885

880886
if (flags & OCSP_TRUSTOTHER) {
881887
for (idx = 0; idx < wolfSSL_sk_X509_num(certs); idx++) {
@@ -1191,9 +1197,7 @@ WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_CERTID_dup(WOLFSSL_OCSP_CERTID* id)
11911197
}
11921198
return certId;
11931199
}
1194-
#endif
11951200

1196-
#if defined(OPENSSL_ALL) || defined(APACHE_HTTPD) || defined(WOLFSSL_HAPROXY)
11971201
#ifndef NO_BIO
11981202
int wolfSSL_i2d_OCSP_REQUEST_bio(WOLFSSL_BIO* out,
11991203
WOLFSSL_OCSP_REQUEST *req)
@@ -1295,7 +1299,8 @@ WOLFSSL_OCSP_CERTID* wolfSSL_d2i_OCSP_CERTID(WOLFSSL_OCSP_CERTID** cidOut,
12951299
return NULL;
12961300
}
12971301

1298-
const WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_SINGLERESP_get0_id(const WOLFSSL_OCSP_SINGLERESP *single)
1302+
const WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_SINGLERESP_get0_id(
1303+
const WOLFSSL_OCSP_SINGLERESP *single)
12991304
{
13001305
return single;
13011306
}
@@ -1343,11 +1348,17 @@ int wolfSSL_OCSP_single_get0_status(WOLFSSL_OCSP_SINGLERESP *single,
13431348
if (single == NULL)
13441349
return WOLFSSL_FAILURE;
13451350

1351+
#ifdef WOLFSSL_OCSP_PARSE_STATUS
13461352
if (thisupd != NULL)
13471353
*thisupd = &single->status->thisDateParsed;
13481354
if (nextupd != NULL)
13491355
*nextupd = &single->status->nextDateParsed;
1350-
1356+
#else
1357+
if (thisupd != NULL)
1358+
*thisupd = NULL;
1359+
if (nextupd != NULL)
1360+
*nextupd = NULL;
1361+
#endif
13511362
if (reason != NULL)
13521363
*reason = 0;
13531364
if (revtime != NULL)
@@ -1392,9 +1403,6 @@ WOLFSSL_OCSP_SINGLERESP* wolfSSL_OCSP_resp_get0(WOLFSSL_OCSP_BASICRESP *bs, int
13921403
return single;
13931404
}
13941405

1395-
#endif /* OPENSSL_ALL || APACHE_HTTPD || WOLFSSL_HAPROXY */
1396-
1397-
#ifdef OPENSSL_EXTRA
13981406
#ifndef NO_WOLFSSL_STUB
13991407
int wolfSSL_OCSP_REQUEST_add_ext(OcspRequest* req, WOLFSSL_X509_EXTENSION* ext,
14001408
int idx)
@@ -1467,12 +1475,14 @@ int wolfSSL_OCSP_id_get0_info(WOLFSSL_ASN1_STRING **name,
14671475

14681476
#if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
14691477
/* Serial number starts at 0 index of ser->data */
1470-
XMEMCPY(&ser->data[i], cid->status->serial, (size_t)cid->status->serialSz);
1478+
XMEMCPY(&ser->data[i], cid->status->serial,
1479+
(size_t)cid->status->serialSz);
14711480
ser->length = cid->status->serialSz;
14721481
#else
14731482
ser->data[i++] = ASN_INTEGER;
14741483
i += SetLength(cid->status->serialSz, ser->data + i);
1475-
XMEMCPY(&ser->data[i], cid->status->serial, (size_t)cid->status->serialSz);
1484+
XMEMCPY(&ser->data[i], cid->status->serial,
1485+
(size_t)cid->status->serialSz);
14761486
ser->length = i + cid->status->serialSz;
14771487
#endif
14781488

src/ssl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,8 +5359,7 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
53595359

53605360
InitDecodedCert(cert, der->buffer, der->length, cm->heap);
53615361

5362-
#if defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ASN_TEMPLATE) && \
5363-
defined(HAVE_OID_DECODING)
5362+
#ifdef WC_ASN_UNKNOWN_EXT_CB
53645363
if (cm->unknownExtCallback != NULL) {
53655364
wc_SetUnknownExtCallback(cert, cm->unknownExtCallback);
53665365
}
@@ -22731,7 +22730,7 @@ void wolfSSL_ERR_remove_state(unsigned long id)
2273122730
}
2273222731
}
2273322732

22734-
#endif /* OPENSSL_EXTRA */
22733+
#endif /* OPENSSL_EXTRA */
2273522734

2273622735
#ifdef OPENSSL_ALL
2273722736

src/ssl_certman.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,7 @@ void wolfSSL_CertManagerSetVerify(WOLFSSL_CERT_MANAGER* cm, VerifyCallback vc)
609609
}
610610
#endif /* NO_WOLFSSL_CM_VERIFY */
611611

612-
#if defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ASN_TEMPLATE) \
613-
&& defined(HAVE_OID_DECODING)
612+
#ifdef WC_ASN_UNKNOWN_EXT_CB
614613
void wolfSSL_CertManagerSetUnknownExtCallback(WOLFSSL_CERT_MANAGER* cm,
615614
wc_UnknownExtCallback cb)
616615
{
@@ -620,7 +619,7 @@ void wolfSSL_CertManagerSetUnknownExtCallback(WOLFSSL_CERT_MANAGER* cm,
620619
}
621620

622621
}
623-
#endif /* WOLFSSL_CUSTOM_OID && WOLFSSL_ASN_TEMPLATE && HAVE_OID_DECODING */
622+
#endif /* WC_ASN_UNKNOWN_EXT_CB */
624623

625624
#if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
626625
/* Verify the certificate.
@@ -690,8 +689,7 @@ int CM_VerifyBuffer_ex(WOLFSSL_CERT_MANAGER* cm, const unsigned char* buff,
690689
/* Create a decoded certificate with DER buffer. */
691690
InitDecodedCert(cert, buff, (word32)sz, cm->heap);
692691

693-
#if defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ASN_TEMPLATE) \
694-
&& defined(HAVE_OID_DECODING)
692+
#ifdef WC_ASN_UNKNOWN_EXT_CB
695693
if (cm->unknownExtCallback != NULL)
696694
wc_SetUnknownExtCallback(cert, cm->unknownExtCallback);
697695
#endif

0 commit comments

Comments
 (0)