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.
This commit is contained in:
Moisés Guimarães
2014-05-23 11:42:37 -03:00
parent e517459f89
commit 263d3439d9
3 changed files with 35 additions and 8 deletions

View File

@@ -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) ?

View File

@@ -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 */

View File

@@ -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;