Skip to content

Commit 0cd5a29

Browse files
author
Lealem Amedie
committed
Fix for parsing pkcs9_contentType
1 parent 4821859 commit 0cd5a29

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

src/x509.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12632,6 +12632,10 @@ static int get_dn_attr_by_nid(int n, const char** buf)
1263212632
str = "DC";
1263312633
len = 2;
1263412634
break;
12635+
case NID_pkcs9_contentType:
12636+
str = "contentType";
12637+
len = 11;
12638+
break;
1263512639
default:
1263612640
WOLFSSL_MSG("Attribute type not found");
1263712641
str = NULL;

wolfcrypt/src/asn.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13194,6 +13194,16 @@ static int GetRDN(DecodedCert* cert, char* full, word32* idx, int* nid,
1319413194
*nid = NID_favouriteDrink;
1319513195
#endif
1319613196
}
13197+
else if (oidSz == sizeof(attrPkcs9ContentTypeOid) &&
13198+
XMEMCMP(oid, attrPkcs9ContentTypeOid, oidSz) == 0) {
13199+
/* Set the pkcs9_contentType, type string, length and NID. */
13200+
id = ASN_CONTENT_TYPE;
13201+
typeStr = WOLFSSL_CONTENT_TYPE;
13202+
typeStrLen = sizeof(WOLFSSL_CONTENT_TYPE) - 1;
13203+
#ifdef WOLFSSL_X509_NAME_AVAILABLE
13204+
*nid = NID_pkcs9_contentType;
13205+
#endif
13206+
}
1319713207
/* Other OIDs that start with the same values. */
1319813208
else if (oidSz == sizeof(dcOid) && XMEMCMP(oid, dcOid, oidSz-1) == 0) {
1319913209
WOLFSSL_MSG("Unknown pilot attribute type");
@@ -13845,7 +13855,6 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1384513855
nid = NID_userId;
1384613856
#endif /* OPENSSL_EXTRA */
1384713857
break;
13848-
1384913858
case ASN_DOMAIN_COMPONENT:
1385013859
copy = WOLFSSL_DOMAIN_COMPONENT;
1385113860
copyLen = sizeof(WOLFSSL_DOMAIN_COMPONENT) - 1;
@@ -13864,7 +13873,15 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1386413873
nid = NID_favouriteDrink;
1386513874
#endif /* OPENSSL_EXTRA */
1386613875
break;
13867-
13876+
case ASN_CONTENT_TYPE:
13877+
copy = WOLFSSL_CONTENT_TYPE;
13878+
copyLen = sizeof(WOLFSSL_CONTENT_TYPE) - 1;
13879+
#if (defined(OPENSSL_EXTRA) || \
13880+
defined(OPENSSL_EXTRA_X509_SMALL)) \
13881+
&& !defined(WOLFCRYPT_ONLY)
13882+
nid = NID_pkcs9_contentType;
13883+
#endif /* OPENSSL_EXTRA */
13884+
break;
1386813885
default:
1386913886
WOLFSSL_MSG("Unknown pilot attribute type");
1387013887
#if (defined(OPENSSL_EXTRA) || \
@@ -26458,6 +26475,9 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2645826475
firstSz = cname->custom.oidSz;
2645926476
break;
2646026477
#endif
26478+
case ASN_CONTENT_TYPE:
26479+
thisLen += (int)sizeof(attrPkcs9ContentTypeOid);
26480+
firstSz = (int)sizeof(attrPkcs9ContentTypeOid);
2646126481
default:
2646226482
thisLen += DN_OID_SZ;
2646326483
firstSz = DN_OID_SZ;
@@ -26522,6 +26542,13 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2652226542
name->encoded[idx++] = nameTag;
2652326543
break;
2652426544
#endif
26545+
case ASN_CONTENT_TYPE:
26546+
XMEMCPY(name->encoded + idx, attrPkcs9ContentTypeOid,
26547+
sizeof(attrPkcs9ContentTypeOid));
26548+
idx += (int)sizeof(attrPkcs9ContentTypeOid);
26549+
/* str type */
26550+
name->encoded[idx++] = nameTag;
26551+
break;
2652526552
default:
2652626553
name->encoded[idx++] = 0x55;
2652726554
name->encoded[idx++] = 0x04;
@@ -26594,6 +26621,10 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2659426621
oidSz = cname->custom.oidSz;
2659526622
break;
2659626623
#endif
26624+
case ASN_CONTENT_TYPE:
26625+
oid = attrPkcs9ContentTypeOid;
26626+
oidSz = sizeof(attrPkcs9ContentTypeOid);
26627+
break;
2659726628
default:
2659826629
/* Construct OID using type. */
2659926630
dnOid[2] = type;

wolfssl/wolfcrypt/asn.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ enum DN_Tags {
710710
ASN_DNQUALIFIER = 0x2e, /* dnQualifier */
711711
#endif /* WOLFSSL_CERT_NAME_ALL */
712712

713-
ASN_CONTENT_TYPE = 0x03, /* pkcs9_contentType */
714713

715-
ASN_EMAIL_NAME = 0x98, /* not actual OID (see attrEmailOid) */
716-
ASN_CUSTOM_NAME = 0x99, /* not actual OID (see CertOidField) */
714+
ASN_CONTENT_TYPE = 0x97, /* not actual OID (see attrPkcs9ContentTypeOid) */
715+
ASN_EMAIL_NAME = 0x98, /* not actual OID (see attrEmailOid) */
716+
ASN_CUSTOM_NAME = 0x99, /* not actual OID (see CertOidField) */
717717

718718
/* pilot attribute types
719719
* OID values of 0.9.2342.19200300.100.1.* */
@@ -770,6 +770,7 @@ extern const WOLFSSL_ObjectInfo wolfssl_object_info[];
770770
#define WOLFSSL_USER_ID "/UID="
771771
#define WOLFSSL_DOMAIN_COMPONENT "/DC="
772772
#define WOLFSSL_FAVOURITE_DRINK "/favouriteDrink="
773+
#define WOLFSSL_CONTENT_TYPE "/contentType="
773774

774775
#if defined(WOLFSSL_APACHE_HTTPD)
775776
/* otherName strings */

0 commit comments

Comments
 (0)