From 263d3439d955a780d6d56dfc175a67511c06dfd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Guimar=C3=A3es?= Date: Fri, 23 May 2014 11:42:37 -0300 Subject: [PATCH] DecodedCert: * add structure fields to persist encoding format of subject parts; * set default encoding formats at InitDecodedCert; * retrieve encoding format from buffer at GetName; * copy encoding format from DecodedCert to CertName at SetNameFromCert. --- ctaocrypt/src/asn.c | 24 ++++++++++++++++++++++-- cyassl/ctaocrypt/asn.h | 9 ++++++++- cyassl/ctaocrypt/asn_public.h | 10 +++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index b82748dd2..af8c25426 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -1270,6 +1270,7 @@ void InitDecodedCert(DecodedCert* cert, byte* source, word32 inSz, void* heap) cert->signature = 0; cert->subjectCN = 0; cert->subjectCNLen = 0; + cert->subjectCNEnc = CTC_UTF8; cert->subjectCNStored = 0; cert->altNames = NULL; #ifndef IGNORE_NAME_CONSTRAINTS @@ -1308,16 +1309,22 @@ void InitDecodedCert(DecodedCert* cert, byte* source, word32 inSz, void* heap) #ifdef CYASSL_CERT_GEN cert->subjectSN = 0; cert->subjectSNLen = 0; + cert->subjectSNEnc = CTC_UTF8; cert->subjectC = 0; cert->subjectCLen = 0; + cert->subjectCEnc = CTC_PRINTABLE; cert->subjectL = 0; cert->subjectLLen = 0; + cert->subjectLEnc = CTC_UTF8; cert->subjectST = 0; cert->subjectSTLen = 0; + cert->subjectSTEnc = CTC_UTF8; cert->subjectO = 0; cert->subjectOLen = 0; + cert->subjectOEnc = CTC_UTF8; cert->subjectOU = 0; cert->subjectOULen = 0; + cert->subjectOUEnc = CTC_UTF8; cert->subjectEmail = 0; cert->subjectEmailLen = 0; #endif /* CYASSL_CERT_GEN */ @@ -1707,8 +1714,7 @@ static int GetName(DecodedCert* cert, int nameType) cert->srcIdx += 2; id = cert->source[cert->srcIdx++]; - b = cert->source[cert->srcIdx++]; /* strType */ - (void)b; /* may want to validate? */ + b = cert->source[cert->srcIdx++]; /* encoding */ if (GetLength(cert->source, &cert->srcIdx, &strLen, cert->maxIdx) < 0) @@ -1724,6 +1730,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectCN = (char *)&cert->source[cert->srcIdx]; cert->subjectCNLen = strLen; + cert->subjectCNEnc = b; } if (!tooBig) { @@ -1746,6 +1753,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectSN = (char*)&cert->source[cert->srcIdx]; cert->subjectSNLen = strLen; + cert->subjectSNEnc = b; } #endif /* CYASSL_CERT_GEN */ #ifdef OPENSSL_EXTRA @@ -1763,6 +1771,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectC = (char*)&cert->source[cert->srcIdx]; cert->subjectCLen = strLen; + cert->subjectCEnc = b; } #endif /* CYASSL_CERT_GEN */ #ifdef OPENSSL_EXTRA @@ -1780,6 +1789,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectL = (char*)&cert->source[cert->srcIdx]; cert->subjectLLen = strLen; + cert->subjectLEnc = b; } #endif /* CYASSL_CERT_GEN */ #ifdef OPENSSL_EXTRA @@ -1797,6 +1807,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectST = (char*)&cert->source[cert->srcIdx]; cert->subjectSTLen = strLen; + cert->subjectSTEnc = b; } #endif /* CYASSL_CERT_GEN */ #ifdef OPENSSL_EXTRA @@ -1814,6 +1825,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectO = (char*)&cert->source[cert->srcIdx]; cert->subjectOLen = strLen; + cert->subjectOEnc = b; } #endif /* CYASSL_CERT_GEN */ #ifdef OPENSSL_EXTRA @@ -1831,6 +1843,7 @@ static int GetName(DecodedCert* cert, int nameType) if (nameType == SUBJECT) { cert->subjectOU = (char*)&cert->source[cert->srcIdx]; cert->subjectOULen = strLen; + cert->subjectOUEnc = b; } #endif /* CYASSL_CERT_GEN */ #ifdef OPENSSL_EXTRA @@ -5741,42 +5754,49 @@ static int SetNameFromCert(CertName* cn, const byte* der, int derSz) CTC_NAME_SIZE - 1; strncpy(cn->commonName, decoded.subjectCN, CTC_NAME_SIZE); cn->commonName[sz] = 0; + cn->commonNameEnc = decoded.subjectCNEnc; } if (decoded.subjectC) { sz = (decoded.subjectCLen < CTC_NAME_SIZE) ? decoded.subjectCLen : CTC_NAME_SIZE - 1; strncpy(cn->country, decoded.subjectC, CTC_NAME_SIZE); cn->country[sz] = 0; + cn->countryEnc = decoded.subjectCEnc; } if (decoded.subjectST) { sz = (decoded.subjectSTLen < CTC_NAME_SIZE) ? decoded.subjectSTLen : CTC_NAME_SIZE - 1; strncpy(cn->state, decoded.subjectST, CTC_NAME_SIZE); cn->state[sz] = 0; + cn->stateEnc = decoded.subjectSTEnc; } if (decoded.subjectL) { sz = (decoded.subjectLLen < CTC_NAME_SIZE) ? decoded.subjectLLen : CTC_NAME_SIZE - 1; strncpy(cn->locality, decoded.subjectL, CTC_NAME_SIZE); cn->locality[sz] = 0; + cn->localityEnc = decoded.subjectLEnc; } if (decoded.subjectO) { sz = (decoded.subjectOLen < CTC_NAME_SIZE) ? decoded.subjectOLen : CTC_NAME_SIZE - 1; strncpy(cn->org, decoded.subjectO, CTC_NAME_SIZE); cn->org[sz] = 0; + cn->orgEnc = decoded.subjectOEnc; } if (decoded.subjectOU) { sz = (decoded.subjectOULen < CTC_NAME_SIZE) ? decoded.subjectOULen : CTC_NAME_SIZE - 1; strncpy(cn->unit, decoded.subjectOU, CTC_NAME_SIZE); cn->unit[sz] = 0; + cn->unitEnc = decoded.subjectOUEnc; } if (decoded.subjectSN) { sz = (decoded.subjectSNLen < CTC_NAME_SIZE) ? decoded.subjectSNLen : CTC_NAME_SIZE - 1; strncpy(cn->sur, decoded.subjectSN, CTC_NAME_SIZE); cn->sur[sz] = 0; + cn->surEnc = decoded.subjectSNEnc; } if (decoded.subjectEmail) { sz = (decoded.subjectEmailLen < CTC_NAME_SIZE) ? diff --git a/cyassl/ctaocrypt/asn.h b/cyassl/ctaocrypt/asn.h index 239c07491..309ea6392 100644 --- a/cyassl/ctaocrypt/asn.h +++ b/cyassl/ctaocrypt/asn.h @@ -340,7 +340,8 @@ struct DecodedCert { #endif /* HAVE_OCSP */ byte* signature; /* not owned, points into raw cert */ char* subjectCN; /* CommonName */ - int subjectCNLen; + int subjectCNLen; /* CommonName Length */ + char subjectCNEnc; /* CommonName Encoding */ int subjectCNStored; /* have we saved a copy we own */ char issuer[ASN_NAME_MAX]; /* full name including common name */ char subject[ASN_NAME_MAX]; /* full name including common name */ @@ -411,16 +412,22 @@ struct DecodedCert { /* easy access to subject info for other sign */ char* subjectSN; int subjectSNLen; + char subjectSNEnc; char* subjectC; int subjectCLen; + char subjectCEnc; char* subjectL; int subjectLLen; + char subjectLEnc; char* subjectST; int subjectSTLen; + char subjectSTEnc; char* subjectO; int subjectOLen; + char subjectOEnc; char* subjectOU; int subjectOULen; + char subjectOUEnc; char* subjectEmail; int subjectEmailLen; #endif /* CYASSL_CERT_GEN */ diff --git a/cyassl/ctaocrypt/asn_public.h b/cyassl/ctaocrypt/asn_public.h index 0a6d62530..8873fcaf2 100644 --- a/cyassl/ctaocrypt/asn_public.h +++ b/cyassl/ctaocrypt/asn_public.h @@ -62,6 +62,11 @@ enum Ctc_SigType { CTC_SHA512wECDSA = 526 }; +enum Ctc_Encoding { + CTC_UTF8 = 0x0c, /* utf8 */ + CTC_PRINTABLE = 0x13 /* printable */ +}; + #ifdef CYASSL_CERT_GEN @@ -76,11 +81,6 @@ enum Ctc_Misc { CTC_SERIAL_SIZE = 8 }; -enum Ctc_Encoding { - CTC_UTF8 = 0x0c, /* utf8 */ - CTC_PRINTABLE = 0x13 /* printable */ -}; - typedef struct CertName { char country[CTC_NAME_SIZE]; char countryEnc;