Cleanup mess of ASN_NAME_MAX.

This commit is contained in:
David Garske
2022-02-24 13:56:08 -08:00
parent a2381ba954
commit ae1072afad
5 changed files with 35 additions and 28 deletions

View File

@ -11127,7 +11127,7 @@ static int GetRDN(DecodedCert* cert, char* full, word32* idx, int* nid,
if (ret == 0) { if (ret == 0) {
/* Check there is space for this in the full name string and /* Check there is space for this in the full name string and
* terminating NUL character. */ * terminating NUL character. */
if ((typeStrLen + strLen) < (word32)(ASN_NAME_MAX - *idx)) if ((typeStrLen + strLen) < (word32)(WC_ASN_NAME_MAX - *idx))
{ {
/* Add RDN to full string. */ /* Add RDN to full string. */
XMEMCPY(&full[*idx], typeStr, typeStrLen); XMEMCPY(&full[*idx], typeStr, typeStrLen);
@ -11525,7 +11525,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
if ((strLen + copyLen) > (int)(ASN_NAME_MAX - idx)) { if ((strLen + copyLen) > (int)(WC_ASN_NAME_MAX - idx)) {
WOLFSSL_MSG("ASN Name too big, skipping"); WOLFSSL_MSG("ASN Name too big, skipping");
tooBig = TRUE; tooBig = TRUE;
} }
@ -11559,14 +11559,14 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
return ASN_PARSE_E; return ASN_PARSE_E;
} }
if (strLen > (int)(ASN_NAME_MAX - idx)) { if (strLen > (int)(WC_ASN_NAME_MAX - idx)) {
WOLFSSL_MSG("ASN name too big, skipping"); WOLFSSL_MSG("ASN name too big, skipping");
tooBig = TRUE; tooBig = TRUE;
} }
if (email) { if (email) {
copyLen = sizeof(WOLFSSL_EMAIL_ADDR) - 1; copyLen = sizeof(WOLFSSL_EMAIL_ADDR) - 1;
if ((copyLen + strLen) > (int)(ASN_NAME_MAX - idx)) { if ((copyLen + strLen) > (int)(WC_ASN_NAME_MAX - idx)) {
WOLFSSL_MSG("ASN name too big, skipping"); WOLFSSL_MSG("ASN name too big, skipping");
tooBig = TRUE; tooBig = TRUE;
} }
@ -11664,7 +11664,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
} }
} }
} }
if ((copyLen + strLen) > (int)(ASN_NAME_MAX - idx)) if ((copyLen + strLen) > (int)(WC_ASN_NAME_MAX - idx))
{ {
WOLFSSL_MSG("ASN Name too big, skipping"); WOLFSSL_MSG("ASN Name too big, skipping");
tooBig = TRUE; tooBig = TRUE;
@ -11707,14 +11707,14 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
if (nameType == ISSUER) { if (nameType == ISSUER) {
#if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY)) && \ #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY)) && \
(defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT)) (defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT))
dName->rawLen = min(cert->issuerRawLen, ASN_NAME_MAX); dName->rawLen = min(cert->issuerRawLen, WC_ASN_NAME_MAX);
XMEMCPY(dName->raw, cert->issuerRaw, dName->rawLen); XMEMCPY(dName->raw, cert->issuerRaw, dName->rawLen);
#endif #endif
cert->issuerName = dName; cert->issuerName = dName;
} }
else { else {
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX)
dName->rawLen = min(cert->subjectRawLen, ASN_NAME_MAX); dName->rawLen = min(cert->subjectRawLen, WC_ASN_NAME_MAX);
XMEMCPY(dName->raw, cert->subjectRaw, dName->rawLen); XMEMCPY(dName->raw, cert->subjectRaw, dName->rawLen);
#endif #endif
cert->subjectName = dName; cert->subjectName = dName;
@ -11838,14 +11838,14 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
#if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
defined(HAVE_LIGHTY)) && \ defined(HAVE_LIGHTY)) && \
(defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT)) (defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT))
dName->rawLen = min(cert->issuerRawLen, ASN_NAME_MAX); dName->rawLen = min(cert->issuerRawLen, WC_ASN_NAME_MAX);
XMEMCPY(dName->raw, cert->issuerRaw, dName->rawLen); XMEMCPY(dName->raw, cert->issuerRaw, dName->rawLen);
#endif #endif
cert->issuerName = dName; cert->issuerName = dName;
} }
else { else {
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX)
dName->rawLen = min(cert->subjectRawLen, ASN_NAME_MAX); dName->rawLen = min(cert->subjectRawLen, WC_ASN_NAME_MAX);
XMEMCPY(dName->raw, cert->subjectRaw, dName->rawLen); XMEMCPY(dName->raw, cert->subjectRaw, dName->rawLen);
#endif #endif
cert->subjectName = dName; cert->subjectName = dName;
@ -20880,8 +20880,8 @@ typedef struct DerCert {
byte version[MAX_VERSION_SZ]; /* version encoded */ byte version[MAX_VERSION_SZ]; /* version encoded */
byte serial[(int)CTC_SERIAL_SIZE + (int)MAX_LENGTH_SZ]; /* serial number encoded */ byte serial[(int)CTC_SERIAL_SIZE + (int)MAX_LENGTH_SZ]; /* serial number encoded */
byte sigAlgo[MAX_ALGO_SZ]; /* signature algo encoded */ byte sigAlgo[MAX_ALGO_SZ]; /* signature algo encoded */
byte issuer[ASN_NAME_MAX]; /* issuer encoded */ byte issuer[WC_ASN_NAME_MAX]; /* issuer encoded */
byte subject[ASN_NAME_MAX]; /* subject encoded */ byte subject[WC_ASN_NAME_MAX]; /* subject encoded */
byte validity[MAX_DATE_SIZE*2 + MAX_SEQ_SZ*2]; /* before and after dates */ byte validity[MAX_DATE_SIZE*2 + MAX_SEQ_SZ*2]; /* before and after dates */
byte publicKey[MAX_PUBLIC_KEY_SZ]; /* rsa public key encoded */ byte publicKey[MAX_PUBLIC_KEY_SZ]; /* rsa public key encoded */
byte ca[MAX_CA_SZ]; /* basic constraint CA true size */ byte ca[MAX_CA_SZ]; /* basic constraint CA true size */
@ -23017,11 +23017,11 @@ int SetNameEx(byte* output, word32 outputSz, CertName* name, void* heap)
/* header */ /* header */
idx = SetSequence(totalBytes, output); idx = SetSequence(totalBytes, output);
totalBytes += idx; totalBytes += idx;
if (totalBytes > ASN_NAME_MAX) { if (totalBytes > WC_ASN_NAME_MAX) {
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
WOLFSSL_MSG("Total Bytes is greater than ASN_NAME_MAX"); WOLFSSL_MSG("Total Bytes is greater than WC_ASN_NAME_MAX");
return BUFFER_E; return BUFFER_E;
} }
@ -24549,7 +24549,7 @@ static int MakeAnyCert(Cert* cert, byte* derBuffer, word32 derSz,
#endif #endif
{ {
/* Calcuate issuer name encoding size. */ /* Calcuate issuer name encoding size. */
issuerSz = SetNameEx(NULL, ASN_NAME_MAX, &cert->issuer, cert->heap); issuerSz = SetNameEx(NULL, WC_ASN_NAME_MAX, &cert->issuer, cert->heap);
ret = issuerSz; ret = issuerSz;
} }
} }
@ -24565,7 +24565,7 @@ static int MakeAnyCert(Cert* cert, byte* derBuffer, word32 derSz,
#endif #endif
{ {
/* Calcuate subject name encoding size. */ /* Calcuate subject name encoding size. */
subjectSz = SetNameEx(NULL, ASN_NAME_MAX, &cert->subject, cert->heap); subjectSz = SetNameEx(NULL, WC_ASN_NAME_MAX, &cert->subject, cert->heap);
ret = subjectSz; ret = subjectSz;
} }
} }
@ -25385,7 +25385,7 @@ static int MakeCertReq(Cert* cert, byte* derBuffer, word32 derSz,
else else
#endif #endif
{ {
subjectSz = SetNameEx(NULL, ASN_NAME_MAX, &cert->subject, cert->heap); subjectSz = SetNameEx(NULL, WC_ASN_NAME_MAX, &cert->subject, cert->heap);
ret = subjectSz; ret = subjectSz;
} }
} }

View File

@ -3812,7 +3812,18 @@ typedef struct Arrays {
} Arrays; } Arrays;
#ifndef ASN_NAME_MAX #ifndef ASN_NAME_MAX
#define ASN_NAME_MAX 256 #ifndef NO_ASN
/* use value from asn.h */
#define ASN_NAME_MAX WC_ASN_NAME_MAX
#else
/* calculate for WOLFSSL_X509 */
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
defined(WOLFSSL_CERT_EXT)
#define ASN_NAME_MAX 330
#else
#define ASN_NAME_MAX 256
#endif
#endif
#endif #endif
#ifndef MAX_DATE_SZ #ifndef MAX_DATE_SZ

View File

@ -20,10 +20,7 @@
#include <wolfssl/wolfcrypt/random.h> #include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/mem_track.h> #include <wolfssl/wolfcrypt/mem_track.h>
#include <wolfssl/wolfio.h> #include <wolfssl/wolfio.h>
#if defined(SHOW_CERTS) && \ #include <wolfssl/wolfcrypt/asn.h>
(defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
#include <wolfssl/wolfcrypt/asn.h> /* for domain component NID value */
#endif
#ifdef ATOMIC_USER #ifdef ATOMIC_USER
#include <wolfssl/wolfcrypt/aes.h> #include <wolfssl/wolfcrypt/aes.h>
@ -31,7 +28,6 @@
#include <wolfssl/wolfcrypt/hmac.h> #include <wolfssl/wolfcrypt/hmac.h>
#endif #endif
#ifdef HAVE_PK_CALLBACKS #ifdef HAVE_PK_CALLBACKS
#include <wolfssl/wolfcrypt/asn.h>
#ifndef NO_RSA #ifndef NO_RSA
#include <wolfssl/wolfcrypt/rsa.h> #include <wolfssl/wolfcrypt/rsa.h>
#endif #endif
@ -1053,7 +1049,7 @@ static WC_INLINE void ShowX509Ex(WOLFSSL_X509* x509, const char* hdr,
#if defined(SHOW_CERTS) && defined(OPENSSL_EXTRA) #if defined(SHOW_CERTS) && defined(OPENSSL_EXTRA)
{ {
WOLFSSL_BIO* bio; WOLFSSL_BIO* bio;
char buf[256]; /* should be size of ASN_NAME_MAX */ char buf[WC_ASN_NAME_MAX];
int textSz; int textSz;
/* print out domain component if certificate has it */ /* print out domain component if certificate has it */

View File

@ -840,13 +840,13 @@ enum ECC_TYPES
#define ASN_JOI_ST 0x2 #define ASN_JOI_ST 0x2
#ifndef WC_ASN_NAME_MAX #ifndef WC_ASN_NAME_MAX
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
defined(WOLFSSL_CERT_EXT)
#define WC_ASN_NAME_MAX 330 #define WC_ASN_NAME_MAX 330
#else #else
#define WC_ASN_NAME_MAX 256 #define WC_ASN_NAME_MAX 256
#endif #endif
#endif #endif
#define ASN_NAME_MAX WC_ASN_NAME_MAX
enum Misc_ASN { enum Misc_ASN {
MAX_SALT_SIZE = 64, /* MAX PKCS Salt length */ MAX_SALT_SIZE = 64, /* MAX PKCS Salt length */
@ -1487,8 +1487,8 @@ struct DecodedCert {
char* subjectCN; /* CommonName */ char* subjectCN; /* CommonName */
int subjectCNLen; /* CommonName Length */ int subjectCNLen; /* CommonName Length */
char subjectCNEnc; /* CommonName Encoding */ char subjectCNEnc; /* CommonName Encoding */
char issuer[ASN_NAME_MAX]; /* full name including common name */ char issuer[WC_ASN_NAME_MAX]; /* full name including common name */
char subject[ASN_NAME_MAX]; /* full name including common name */ char subject[WC_ASN_NAME_MAX];/* full name including common name */
int verify; /* Default to yes, but could be off */ int verify; /* Default to yes, but could be off */
const byte* source; /* byte buffer holder cert, NOT owner */ const byte* source; /* byte buffer holder cert, NOT owner */
word32 srcIdx; /* current offset into buffer */ word32 srcIdx; /* current offset into buffer */

View File

@ -156,7 +156,7 @@ enum Pkcs7_Misc {
MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE, MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE,
#endif #endif
MAX_RECIP_SZ = MAX_VERSION_SZ + MAX_RECIP_SZ = MAX_VERSION_SZ +
MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ + MAX_SEQ_SZ + WC_ASN_NAME_MAX + MAX_SN_SZ +
MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ, MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ,
}; };