mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 12:14:38 +02:00
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:
@@ -1270,6 +1270,7 @@ void InitDecodedCert(DecodedCert* cert, byte* source, word32 inSz, void* heap)
|
|||||||
cert->signature = 0;
|
cert->signature = 0;
|
||||||
cert->subjectCN = 0;
|
cert->subjectCN = 0;
|
||||||
cert->subjectCNLen = 0;
|
cert->subjectCNLen = 0;
|
||||||
|
cert->subjectCNEnc = CTC_UTF8;
|
||||||
cert->subjectCNStored = 0;
|
cert->subjectCNStored = 0;
|
||||||
cert->altNames = NULL;
|
cert->altNames = NULL;
|
||||||
#ifndef IGNORE_NAME_CONSTRAINTS
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
@@ -1308,16 +1309,22 @@ void InitDecodedCert(DecodedCert* cert, byte* source, word32 inSz, void* heap)
|
|||||||
#ifdef CYASSL_CERT_GEN
|
#ifdef CYASSL_CERT_GEN
|
||||||
cert->subjectSN = 0;
|
cert->subjectSN = 0;
|
||||||
cert->subjectSNLen = 0;
|
cert->subjectSNLen = 0;
|
||||||
|
cert->subjectSNEnc = CTC_UTF8;
|
||||||
cert->subjectC = 0;
|
cert->subjectC = 0;
|
||||||
cert->subjectCLen = 0;
|
cert->subjectCLen = 0;
|
||||||
|
cert->subjectCEnc = CTC_PRINTABLE;
|
||||||
cert->subjectL = 0;
|
cert->subjectL = 0;
|
||||||
cert->subjectLLen = 0;
|
cert->subjectLLen = 0;
|
||||||
|
cert->subjectLEnc = CTC_UTF8;
|
||||||
cert->subjectST = 0;
|
cert->subjectST = 0;
|
||||||
cert->subjectSTLen = 0;
|
cert->subjectSTLen = 0;
|
||||||
|
cert->subjectSTEnc = CTC_UTF8;
|
||||||
cert->subjectO = 0;
|
cert->subjectO = 0;
|
||||||
cert->subjectOLen = 0;
|
cert->subjectOLen = 0;
|
||||||
|
cert->subjectOEnc = CTC_UTF8;
|
||||||
cert->subjectOU = 0;
|
cert->subjectOU = 0;
|
||||||
cert->subjectOULen = 0;
|
cert->subjectOULen = 0;
|
||||||
|
cert->subjectOUEnc = CTC_UTF8;
|
||||||
cert->subjectEmail = 0;
|
cert->subjectEmail = 0;
|
||||||
cert->subjectEmailLen = 0;
|
cert->subjectEmailLen = 0;
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
@@ -1707,8 +1714,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
|
|
||||||
cert->srcIdx += 2;
|
cert->srcIdx += 2;
|
||||||
id = cert->source[cert->srcIdx++];
|
id = cert->source[cert->srcIdx++];
|
||||||
b = cert->source[cert->srcIdx++]; /* strType */
|
b = cert->source[cert->srcIdx++]; /* encoding */
|
||||||
(void)b; /* may want to validate? */
|
|
||||||
|
|
||||||
if (GetLength(cert->source, &cert->srcIdx, &strLen,
|
if (GetLength(cert->source, &cert->srcIdx, &strLen,
|
||||||
cert->maxIdx) < 0)
|
cert->maxIdx) < 0)
|
||||||
@@ -1724,6 +1730,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectCN = (char *)&cert->source[cert->srcIdx];
|
cert->subjectCN = (char *)&cert->source[cert->srcIdx];
|
||||||
cert->subjectCNLen = strLen;
|
cert->subjectCNLen = strLen;
|
||||||
|
cert->subjectCNEnc = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tooBig) {
|
if (!tooBig) {
|
||||||
@@ -1746,6 +1753,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectSN = (char*)&cert->source[cert->srcIdx];
|
cert->subjectSN = (char*)&cert->source[cert->srcIdx];
|
||||||
cert->subjectSNLen = strLen;
|
cert->subjectSNLen = strLen;
|
||||||
|
cert->subjectSNEnc = b;
|
||||||
}
|
}
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@@ -1763,6 +1771,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectC = (char*)&cert->source[cert->srcIdx];
|
cert->subjectC = (char*)&cert->source[cert->srcIdx];
|
||||||
cert->subjectCLen = strLen;
|
cert->subjectCLen = strLen;
|
||||||
|
cert->subjectCEnc = b;
|
||||||
}
|
}
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@@ -1780,6 +1789,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectL = (char*)&cert->source[cert->srcIdx];
|
cert->subjectL = (char*)&cert->source[cert->srcIdx];
|
||||||
cert->subjectLLen = strLen;
|
cert->subjectLLen = strLen;
|
||||||
|
cert->subjectLEnc = b;
|
||||||
}
|
}
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@@ -1797,6 +1807,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectST = (char*)&cert->source[cert->srcIdx];
|
cert->subjectST = (char*)&cert->source[cert->srcIdx];
|
||||||
cert->subjectSTLen = strLen;
|
cert->subjectSTLen = strLen;
|
||||||
|
cert->subjectSTEnc = b;
|
||||||
}
|
}
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@@ -1814,6 +1825,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectO = (char*)&cert->source[cert->srcIdx];
|
cert->subjectO = (char*)&cert->source[cert->srcIdx];
|
||||||
cert->subjectOLen = strLen;
|
cert->subjectOLen = strLen;
|
||||||
|
cert->subjectOEnc = b;
|
||||||
}
|
}
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@@ -1831,6 +1843,7 @@ static int GetName(DecodedCert* cert, int nameType)
|
|||||||
if (nameType == SUBJECT) {
|
if (nameType == SUBJECT) {
|
||||||
cert->subjectOU = (char*)&cert->source[cert->srcIdx];
|
cert->subjectOU = (char*)&cert->source[cert->srcIdx];
|
||||||
cert->subjectOULen = strLen;
|
cert->subjectOULen = strLen;
|
||||||
|
cert->subjectOUEnc = b;
|
||||||
}
|
}
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@@ -5741,42 +5754,49 @@ static int SetNameFromCert(CertName* cn, const byte* der, int derSz)
|
|||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->commonName, decoded.subjectCN, CTC_NAME_SIZE);
|
strncpy(cn->commonName, decoded.subjectCN, CTC_NAME_SIZE);
|
||||||
cn->commonName[sz] = 0;
|
cn->commonName[sz] = 0;
|
||||||
|
cn->commonNameEnc = decoded.subjectCNEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectC) {
|
if (decoded.subjectC) {
|
||||||
sz = (decoded.subjectCLen < CTC_NAME_SIZE) ? decoded.subjectCLen :
|
sz = (decoded.subjectCLen < CTC_NAME_SIZE) ? decoded.subjectCLen :
|
||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->country, decoded.subjectC, CTC_NAME_SIZE);
|
strncpy(cn->country, decoded.subjectC, CTC_NAME_SIZE);
|
||||||
cn->country[sz] = 0;
|
cn->country[sz] = 0;
|
||||||
|
cn->countryEnc = decoded.subjectCEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectST) {
|
if (decoded.subjectST) {
|
||||||
sz = (decoded.subjectSTLen < CTC_NAME_SIZE) ? decoded.subjectSTLen :
|
sz = (decoded.subjectSTLen < CTC_NAME_SIZE) ? decoded.subjectSTLen :
|
||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->state, decoded.subjectST, CTC_NAME_SIZE);
|
strncpy(cn->state, decoded.subjectST, CTC_NAME_SIZE);
|
||||||
cn->state[sz] = 0;
|
cn->state[sz] = 0;
|
||||||
|
cn->stateEnc = decoded.subjectSTEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectL) {
|
if (decoded.subjectL) {
|
||||||
sz = (decoded.subjectLLen < CTC_NAME_SIZE) ? decoded.subjectLLen :
|
sz = (decoded.subjectLLen < CTC_NAME_SIZE) ? decoded.subjectLLen :
|
||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->locality, decoded.subjectL, CTC_NAME_SIZE);
|
strncpy(cn->locality, decoded.subjectL, CTC_NAME_SIZE);
|
||||||
cn->locality[sz] = 0;
|
cn->locality[sz] = 0;
|
||||||
|
cn->localityEnc = decoded.subjectLEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectO) {
|
if (decoded.subjectO) {
|
||||||
sz = (decoded.subjectOLen < CTC_NAME_SIZE) ? decoded.subjectOLen :
|
sz = (decoded.subjectOLen < CTC_NAME_SIZE) ? decoded.subjectOLen :
|
||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->org, decoded.subjectO, CTC_NAME_SIZE);
|
strncpy(cn->org, decoded.subjectO, CTC_NAME_SIZE);
|
||||||
cn->org[sz] = 0;
|
cn->org[sz] = 0;
|
||||||
|
cn->orgEnc = decoded.subjectOEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectOU) {
|
if (decoded.subjectOU) {
|
||||||
sz = (decoded.subjectOULen < CTC_NAME_SIZE) ? decoded.subjectOULen :
|
sz = (decoded.subjectOULen < CTC_NAME_SIZE) ? decoded.subjectOULen :
|
||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->unit, decoded.subjectOU, CTC_NAME_SIZE);
|
strncpy(cn->unit, decoded.subjectOU, CTC_NAME_SIZE);
|
||||||
cn->unit[sz] = 0;
|
cn->unit[sz] = 0;
|
||||||
|
cn->unitEnc = decoded.subjectOUEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectSN) {
|
if (decoded.subjectSN) {
|
||||||
sz = (decoded.subjectSNLen < CTC_NAME_SIZE) ? decoded.subjectSNLen :
|
sz = (decoded.subjectSNLen < CTC_NAME_SIZE) ? decoded.subjectSNLen :
|
||||||
CTC_NAME_SIZE - 1;
|
CTC_NAME_SIZE - 1;
|
||||||
strncpy(cn->sur, decoded.subjectSN, CTC_NAME_SIZE);
|
strncpy(cn->sur, decoded.subjectSN, CTC_NAME_SIZE);
|
||||||
cn->sur[sz] = 0;
|
cn->sur[sz] = 0;
|
||||||
|
cn->surEnc = decoded.subjectSNEnc;
|
||||||
}
|
}
|
||||||
if (decoded.subjectEmail) {
|
if (decoded.subjectEmail) {
|
||||||
sz = (decoded.subjectEmailLen < CTC_NAME_SIZE) ?
|
sz = (decoded.subjectEmailLen < CTC_NAME_SIZE) ?
|
||||||
|
@@ -340,7 +340,8 @@ struct DecodedCert {
|
|||||||
#endif /* HAVE_OCSP */
|
#endif /* HAVE_OCSP */
|
||||||
byte* signature; /* not owned, points into raw cert */
|
byte* signature; /* not owned, points into raw cert */
|
||||||
char* subjectCN; /* CommonName */
|
char* subjectCN; /* CommonName */
|
||||||
int subjectCNLen;
|
int subjectCNLen; /* CommonName Length */
|
||||||
|
char subjectCNEnc; /* CommonName Encoding */
|
||||||
int subjectCNStored; /* have we saved a copy we own */
|
int subjectCNStored; /* have we saved a copy we own */
|
||||||
char issuer[ASN_NAME_MAX]; /* full name including common name */
|
char issuer[ASN_NAME_MAX]; /* full name including common name */
|
||||||
char subject[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 */
|
/* easy access to subject info for other sign */
|
||||||
char* subjectSN;
|
char* subjectSN;
|
||||||
int subjectSNLen;
|
int subjectSNLen;
|
||||||
|
char subjectSNEnc;
|
||||||
char* subjectC;
|
char* subjectC;
|
||||||
int subjectCLen;
|
int subjectCLen;
|
||||||
|
char subjectCEnc;
|
||||||
char* subjectL;
|
char* subjectL;
|
||||||
int subjectLLen;
|
int subjectLLen;
|
||||||
|
char subjectLEnc;
|
||||||
char* subjectST;
|
char* subjectST;
|
||||||
int subjectSTLen;
|
int subjectSTLen;
|
||||||
|
char subjectSTEnc;
|
||||||
char* subjectO;
|
char* subjectO;
|
||||||
int subjectOLen;
|
int subjectOLen;
|
||||||
|
char subjectOEnc;
|
||||||
char* subjectOU;
|
char* subjectOU;
|
||||||
int subjectOULen;
|
int subjectOULen;
|
||||||
|
char subjectOUEnc;
|
||||||
char* subjectEmail;
|
char* subjectEmail;
|
||||||
int subjectEmailLen;
|
int subjectEmailLen;
|
||||||
#endif /* CYASSL_CERT_GEN */
|
#endif /* CYASSL_CERT_GEN */
|
||||||
|
@@ -62,6 +62,11 @@ enum Ctc_SigType {
|
|||||||
CTC_SHA512wECDSA = 526
|
CTC_SHA512wECDSA = 526
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Ctc_Encoding {
|
||||||
|
CTC_UTF8 = 0x0c, /* utf8 */
|
||||||
|
CTC_PRINTABLE = 0x13 /* printable */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef CYASSL_CERT_GEN
|
#ifdef CYASSL_CERT_GEN
|
||||||
|
|
||||||
@@ -76,11 +81,6 @@ enum Ctc_Misc {
|
|||||||
CTC_SERIAL_SIZE = 8
|
CTC_SERIAL_SIZE = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Ctc_Encoding {
|
|
||||||
CTC_UTF8 = 0x0c, /* utf8 */
|
|
||||||
CTC_PRINTABLE = 0x13 /* printable */
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct CertName {
|
typedef struct CertName {
|
||||||
char country[CTC_NAME_SIZE];
|
char country[CTC_NAME_SIZE];
|
||||||
char countryEnc;
|
char countryEnc;
|
||||||
|
Reference in New Issue
Block a user