Skip to content

Commit 84c42f4

Browse files
committed
ASN.1 template: store issuer common name
Under certain configurations the certificate issuer's common name is kept in a DecodedCert. Wasn't implemented in ASN.1 template code.
1 parent 924c0fd commit 84c42f4

1 file changed

Lines changed: 164 additions & 0 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12661,6 +12661,17 @@ static int GetHashId(const byte* id, int length, byte* hash, int hashAlg)
1266112661
(((id) - 3) >= 0 && ((id) - 3) < certNameSubjectSz && \
1266212662
(certNameSubject[(id) - 3].strLen > 0))
1266312663

12664+
/* Set the string for a name component into the issuer name. */
12665+
#define SetCertNameIssuer(cert, id, val) \
12666+
*((char**)(((byte *)(cert)) + certNameSubject[(id) - 3].dataI)) = (val)
12667+
/* Set the string length for a name component into the issuer name. */
12668+
#define SetCertNameIssuerLen(cert, id, val) \
12669+
*((int*)(((byte *)(cert)) + certNameSubject[(id) - 3].lenI)) = (int)(val)
12670+
/* Set the encoding for a name component into the issuer name. */
12671+
#define SetCertNameIssuerEnc(cert, id, val) \
12672+
*((byte*)(((byte *)(cert)) + certNameSubject[(id) - 3].encI)) = (val)
12673+
12674+
1266412675
/* Mapping of certificate name component to useful information. */
1266512676
typedef struct CertNameData {
1266612677
/* Type string of name component. */
@@ -12674,6 +12685,14 @@ typedef struct CertNameData {
1267412685
size_t len;
1267512686
/* Offset of encoding in subject name component. */
1267612687
size_t enc;
12688+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12689+
/* Offset of data in subject name component. */
12690+
size_t dataI;
12691+
/* Offset of length in subject name component. */
12692+
size_t lenI;
12693+
/* Offset of encoding in subject name component. */
12694+
size_t encI;
12695+
#endif
1267712696
#endif
1267812697
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1267912698
/* NID of type for subject name component. */
@@ -12690,6 +12709,11 @@ static const CertNameData certNameSubject[] = {
1269012709
OFFSETOF(DecodedCert, subjectCN),
1269112710
OFFSETOF(DecodedCert, subjectCNLen),
1269212711
OFFSETOF(DecodedCert, subjectCNEnc),
12712+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12713+
OFFSETOF(DecodedCert, issuerCN),
12714+
OFFSETOF(DecodedCert, issuerCNLen),
12715+
OFFSETOF(DecodedCert, issuerCNEnc),
12716+
#endif
1269312717
#endif
1269412718
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1269512719
NID_commonName
@@ -12702,6 +12726,11 @@ static const CertNameData certNameSubject[] = {
1270212726
OFFSETOF(DecodedCert, subjectSN),
1270312727
OFFSETOF(DecodedCert, subjectSNLen),
1270412728
OFFSETOF(DecodedCert, subjectSNEnc),
12729+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12730+
OFFSETOF(DecodedCert, issuerSN),
12731+
OFFSETOF(DecodedCert, issuerSNLen),
12732+
OFFSETOF(DecodedCert, issuerSNEnc),
12733+
#endif
1270512734
#endif
1270612735
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1270712736
NID_surname
@@ -12714,6 +12743,11 @@ static const CertNameData certNameSubject[] = {
1271412743
OFFSETOF(DecodedCert, subjectSND),
1271512744
OFFSETOF(DecodedCert, subjectSNDLen),
1271612745
OFFSETOF(DecodedCert, subjectSNDEnc),
12746+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12747+
OFFSETOF(DecodedCert, issuerSND),
12748+
OFFSETOF(DecodedCert, issuerSNDLen),
12749+
OFFSETOF(DecodedCert, issuerSNDEnc),
12750+
#endif
1271712751
#endif
1271812752
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1271912753
NID_serialNumber
@@ -12726,6 +12760,11 @@ static const CertNameData certNameSubject[] = {
1272612760
OFFSETOF(DecodedCert, subjectC),
1272712761
OFFSETOF(DecodedCert, subjectCLen),
1272812762
OFFSETOF(DecodedCert, subjectCEnc),
12763+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12764+
OFFSETOF(DecodedCert, issuerC),
12765+
OFFSETOF(DecodedCert, issuerCLen),
12766+
OFFSETOF(DecodedCert, issuerCEnc),
12767+
#endif
1272912768
#endif
1273012769
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1273112770
NID_countryName
@@ -12738,6 +12777,11 @@ static const CertNameData certNameSubject[] = {
1273812777
OFFSETOF(DecodedCert, subjectL),
1273912778
OFFSETOF(DecodedCert, subjectLLen),
1274012779
OFFSETOF(DecodedCert, subjectLEnc),
12780+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12781+
OFFSETOF(DecodedCert, issuerL),
12782+
OFFSETOF(DecodedCert, issuerLLen),
12783+
OFFSETOF(DecodedCert, issuerLEnc),
12784+
#endif
1274112785
#endif
1274212786
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1274312787
NID_localityName
@@ -12750,6 +12794,11 @@ static const CertNameData certNameSubject[] = {
1275012794
OFFSETOF(DecodedCert, subjectST),
1275112795
OFFSETOF(DecodedCert, subjectSTLen),
1275212796
OFFSETOF(DecodedCert, subjectSTEnc),
12797+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12798+
OFFSETOF(DecodedCert, issuerST),
12799+
OFFSETOF(DecodedCert, issuerSTLen),
12800+
OFFSETOF(DecodedCert, issuerSTEnc),
12801+
#endif
1275312802
#endif
1275412803
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1275512804
NID_stateOrProvinceName
@@ -12762,6 +12811,11 @@ static const CertNameData certNameSubject[] = {
1276212811
OFFSETOF(DecodedCert, subjectStreet),
1276312812
OFFSETOF(DecodedCert, subjectStreetLen),
1276412813
OFFSETOF(DecodedCert, subjectStreetEnc),
12814+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12815+
0,
12816+
0,
12817+
0,
12818+
#endif
1276512819
#endif
1276612820
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1276712821
NID_streetAddress
@@ -12774,6 +12828,11 @@ static const CertNameData certNameSubject[] = {
1277412828
OFFSETOF(DecodedCert, subjectO),
1277512829
OFFSETOF(DecodedCert, subjectOLen),
1277612830
OFFSETOF(DecodedCert, subjectOEnc),
12831+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12832+
OFFSETOF(DecodedCert, issuerO),
12833+
OFFSETOF(DecodedCert, issuerOLen),
12834+
OFFSETOF(DecodedCert, issuerOEnc),
12835+
#endif
1277712836
#endif
1277812837
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1277912838
NID_organizationName
@@ -12786,6 +12845,11 @@ static const CertNameData certNameSubject[] = {
1278612845
OFFSETOF(DecodedCert, subjectOU),
1278712846
OFFSETOF(DecodedCert, subjectOULen),
1278812847
OFFSETOF(DecodedCert, subjectOUEnc),
12848+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12849+
OFFSETOF(DecodedCert, issuerOU),
12850+
OFFSETOF(DecodedCert, issuerOULen),
12851+
OFFSETOF(DecodedCert, issuerOUEnc),
12852+
#endif
1278912853
#endif
1279012854
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1279112855
NID_organizationalUnitName
@@ -12798,6 +12862,11 @@ static const CertNameData certNameSubject[] = {
1279812862
0,
1279912863
0,
1280012864
0,
12865+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12866+
0,
12867+
0,
12868+
0,
12869+
#endif
1280112870
#endif
1280212871
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1280312872
0,
@@ -12810,6 +12879,11 @@ static const CertNameData certNameSubject[] = {
1281012879
0,
1281112880
0,
1281212881
0,
12882+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12883+
0,
12884+
0,
12885+
0,
12886+
#endif
1281312887
#endif
1281412888
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1281512889
0,
@@ -12822,6 +12896,11 @@ static const CertNameData certNameSubject[] = {
1282212896
0,
1282312897
0,
1282412898
0,
12899+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12900+
0,
12901+
0,
12902+
0,
12903+
#endif
1282512904
#endif
1282612905
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1282712906
0,
@@ -12834,6 +12913,11 @@ static const CertNameData certNameSubject[] = {
1283412913
OFFSETOF(DecodedCert, subjectBC),
1283512914
OFFSETOF(DecodedCert, subjectBCLen),
1283612915
OFFSETOF(DecodedCert, subjectBCEnc),
12916+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12917+
0,
12918+
0,
12919+
0,
12920+
#endif
1283712921
#endif
1283812922
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1283912923
NID_businessCategory
@@ -12846,6 +12930,11 @@ static const CertNameData certNameSubject[] = {
1284612930
0,
1284712931
0,
1284812932
0,
12933+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12934+
0,
12935+
0,
12936+
0,
12937+
#endif
1284912938
#endif
1285012939
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1285112940
0,
@@ -12858,6 +12947,11 @@ static const CertNameData certNameSubject[] = {
1285812947
OFFSETOF(DecodedCert, subjectPC),
1285912948
OFFSETOF(DecodedCert, subjectPCLen),
1286012949
OFFSETOF(DecodedCert, subjectPCEnc),
12950+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12951+
0,
12952+
0,
12953+
0,
12954+
#endif
1286112955
#endif
1286212956
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1286312957
NID_postalCode
@@ -12870,6 +12964,11 @@ static const CertNameData certNameSubject[] = {
1287012964
OFFSETOF(DecodedCert, subjectUID),
1287112965
OFFSETOF(DecodedCert, subjectUIDLen),
1287212966
OFFSETOF(DecodedCert, subjectUIDEnc),
12967+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12968+
0,
12969+
0,
12970+
0,
12971+
#endif
1287312972
#endif
1287412973
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1287512974
NID_userId
@@ -12883,6 +12982,11 @@ static const CertNameData certNameSubject[] = {
1288312982
OFFSETOF(DecodedCert, subjectN),
1288412983
OFFSETOF(DecodedCert, subjectNLen),
1288512984
OFFSETOF(DecodedCert, subjectNEnc),
12985+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
12986+
0,
12987+
0,
12988+
0,
12989+
#endif
1288612990
#endif
1288712991
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1288812992
NID_name
@@ -12895,6 +12999,11 @@ static const CertNameData certNameSubject[] = {
1289512999
OFFSETOF(DecodedCert, subjectGN),
1289613000
OFFSETOF(DecodedCert, subjectGNLen),
1289713001
OFFSETOF(DecodedCert, subjectGNEnc),
13002+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
13003+
0,
13004+
0,
13005+
0,
13006+
#endif
1289813007
#endif
1289913008
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1290013009
NID_givenName
@@ -12907,6 +13016,11 @@ static const CertNameData certNameSubject[] = {
1290713016
OFFSETOF(DecodedCert, subjectI),
1290813017
OFFSETOF(DecodedCert, subjectILen),
1290913018
OFFSETOF(DecodedCert, subjectIEnc),
13019+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
13020+
0,
13021+
0,
13022+
0,
13023+
#endif
1291013024
#endif
1291113025
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1291213026
NID_initials
@@ -12919,6 +13033,11 @@ static const CertNameData certNameSubject[] = {
1291913033
OFFSETOF(DecodedCert, subjectDNQ),
1292013034
OFFSETOF(DecodedCert, subjectDNQLen),
1292113035
OFFSETOF(DecodedCert, subjectDNQEnc),
13036+
#ifdef WOLFSSL_HAVE_ISSUER_NAMES
13037+
0,
13038+
0,
13039+
0,
13040+
#endif
1292213041
#endif
1292313042
#ifdef WOLFSSL_X509_NAME_AVAILABLE
1292413043
NID_dnQualifier
@@ -12930,6 +13049,7 @@ static const CertNameData certNameSubject[] = {
1293013049
static const int certNameSubjectSz =
1293113050
(int) (sizeof(certNameSubject) / sizeof(CertNameData));
1293213051

13052+
1293313053
/* ASN.1 template for an RDN.
1293413054
* X.509: RFC 5280, 4.1.2.4 - RelativeDistinguishedName
1293513055
*/
@@ -13270,6 +13390,43 @@ static int SetSubject(DecodedCert* cert, int id, byte* str, int strLen,
1327013390
return ret;
1327113391
}
1327213392

13393+
#if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT)) && \
13394+
defined(WOLFSSL_HAVE_ISSUER_NAMES)
13395+
/* Set the details of an issuer name component into a certificate.
13396+
*
13397+
* @param [in, out] cert Certificate object.
13398+
* @param [in] id Id of component.
13399+
* @param [in] str String for component.
13400+
* @param [in] strLen Length of string.
13401+
* @param [in] tag BER tag representing encoding of string.
13402+
* @return 0 on success, negative values on failure.
13403+
*/
13404+
static int SetIssuer(DecodedCert* cert, int id, byte* str, int strLen,
13405+
byte tag)
13406+
{
13407+
int ret = 0;
13408+
13409+
/* Put string and encoding into certificate. */
13410+
if (id == ASN_COMMON_NAME) {
13411+
cert->issuerCN = (char *)str;
13412+
cert->issuerCNLen = (int)strLen;
13413+
cert->issuerCNEnc = (char)tag;
13414+
}
13415+
else if (id > ASN_COMMON_NAME && id <= ASN_USER_ID) {
13416+
/* Use table and offsets to put data into appropriate fields. */
13417+
SetCertNameIssuer(cert, id, (char*)str);
13418+
SetCertNameIssuerLen(cert, id, strLen);
13419+
SetCertNameIssuerEnc(cert, id, tag);
13420+
}
13421+
else if (id == ASN_EMAIL) {
13422+
cert->issuerEmail = (char*)str;
13423+
cert->issuerEmailLen = strLen;
13424+
}
13425+
13426+
return ret;
13427+
}
13428+
#endif
13429+
1327313430
/* Get a RelativeDistinguishedName from the encoding and put in certificate.
1327413431
*
1327513432
* @param [in, out] cert Certificate object.
@@ -13402,6 +13559,13 @@ static int GetRDN(DecodedCert* cert, char* full, word32* idx, int* nid,
1340213559
/* Store subject field components. */
1340313560
ret = SetSubject(cert, id, str, (int)strLen, tag);
1340413561
}
13562+
#if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT)) && \
13563+
defined(WOLFSSL_HAVE_ISSUER_NAMES)
13564+
/* Put issuer common name string and encoding into certificate. */
13565+
else {
13566+
ret = SetIssuer(cert, id, str, (int)strLen, tag);
13567+
}
13568+
#endif
1340513569
if (ret == 0) {
1340613570
/* Check there is space for this in the full name string and
1340713571
* terminating NUL character. */

0 commit comments

Comments
 (0)