Skip to content

Commit 2acc4a6

Browse files
Merge pull request #6561 from lealem47/zd16348
Fix for adding pkcs9 contentType entry name
2 parents c2a3f53 + acac3fe commit 2acc4a6

4 files changed

Lines changed: 69 additions & 8 deletions

File tree

src/x509.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10500,6 +10500,7 @@ static int ConvertNIDToWolfSSL(int nid)
1050010500
case NID_organizationName: return ASN_ORG_NAME;
1050110501
case NID_organizationalUnitName: return ASN_ORGUNIT_NAME;
1050210502
case NID_emailAddress: return ASN_EMAIL_NAME;
10503+
case NID_pkcs9_contentType: return ASN_CONTENT_TYPE;
1050310504
case NID_serialNumber: return ASN_SERIAL_NUMBER;
1050410505
case NID_userId: return ASN_USER_ID;
1050510506
case NID_businessCategory: return ASN_BUS_CAT;
@@ -12631,6 +12632,10 @@ static int get_dn_attr_by_nid(int n, const char** buf)
1263112632
str = "DC";
1263212633
len = 2;
1263312634
break;
12635+
case NID_pkcs9_contentType:
12636+
str = "contentType";
12637+
len = 11;
12638+
break;
1263412639
default:
1263512640
WOLFSSL_MSG("Attribute type not found");
1263612641
str = NULL;

tests/api.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39717,6 +39717,7 @@ static int test_wolfSSL_X509_NAME_ENTRY(void)
3971739717

3971839718
ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
3971939719
ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
39720+
ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
3972039721
#ifdef DEBUG_WOLFSSL
3972139722
if (subject != NULL) {
3972239723
fprintf(stderr, "\n\t%s\n", subject);
@@ -57149,7 +57150,8 @@ static int test_ECDH_compute_key(void)
5714957150
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
5715057151
defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
5715157152
!defined(NO_ASN_TIME)
57152-
static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey)
57153+
static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
57154+
int expectedDerSz)
5715357155
{
5715457156
EXPECT_DECLS;
5715557157
X509* x509 = NULL;
@@ -57158,6 +57160,7 @@ static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey)
5715857160
time_t epoch_off = 0;
5715957161
ASN1_INTEGER* asn1_serial_number;
5716057162
long not_before, not_after;
57163+
int derSz;
5716157164

5716257165
ExpectNotNull(x509 = X509_new());
5716357166

@@ -57175,6 +57178,8 @@ static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey)
5717557178

5717657179
ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
5717757180
(unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
57181+
ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
57182+
MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
5717857183

5717957184
ExpectIntNE(X509_set_subject_name(x509, name), 0);
5718057185
ExpectIntNE(X509_set_issuer_name(x509, name), 0);
@@ -57188,6 +57193,9 @@ static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey)
5718857193

5718957194
ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
5719057195

57196+
ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
57197+
ExpectIntGE(derSz, expectedDerSz);
57198+
5719157199
BN_free(serial_number);
5719257200
X509_NAME_free(name);
5719357201
X509_free(x509);
@@ -57205,6 +57213,7 @@ static int test_openssl_generate_key_and_cert(void)
5720557213
EC_KEY* ec_key = NULL;
5720657214
#endif
5720757215
#if !defined(NO_RSA)
57216+
int expectedDerSz;
5720857217
int key_length = 2048;
5720957218
BIGNUM* exponent = NULL;
5721057219
RSA* rsa = NULL;
@@ -57243,11 +57252,13 @@ static int test_openssl_generate_key_and_cert(void)
5724357252

5724457253
#if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
5724557254
defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
57246-
ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey),
57247-
TEST_SUCCESS);
57255+
expectedDerSz = 743;
57256+
ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
57257+
expectedDerSz), TEST_SUCCESS);
5724857258
#endif
5724957259
}
5725057260

57261+
(void)expectedDerSz;
5725157262
EVP_PKEY_free(pkey);
5725257263
pkey = NULL;
5725357264
BN_free(exponent);
@@ -57269,7 +57280,9 @@ static int test_openssl_generate_key_and_cert(void)
5726957280

5727057281
#if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
5727157282
defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
57272-
ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey), TEST_SUCCESS);
57283+
expectedDerSz = 345;
57284+
ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
57285+
TEST_SUCCESS);
5727357286
#endif
5727457287

5727557288
EVP_PKEY_free(pkey);

wolfcrypt/src/asn.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13194,6 +13194,18 @@ static int GetRDN(DecodedCert* cert, char* full, word32* idx, int* nid,
1319413194
*nid = NID_favouriteDrink;
1319513195
#endif
1319613196
}
13197+
#ifdef WOLFSSL_CERT_REQ
13198+
else if (oidSz == sizeof(attrPkcs9ContentTypeOid) &&
13199+
XMEMCMP(oid, attrPkcs9ContentTypeOid, oidSz) == 0) {
13200+
/* Set the pkcs9_contentType, type string, length and NID. */
13201+
id = ASN_CONTENT_TYPE;
13202+
typeStr = WOLFSSL_CONTENT_TYPE;
13203+
typeStrLen = sizeof(WOLFSSL_CONTENT_TYPE) - 1;
13204+
#ifdef WOLFSSL_X509_NAME_AVAILABLE
13205+
*nid = NID_pkcs9_contentType;
13206+
#endif
13207+
}
13208+
#endif
1319713209
/* Other OIDs that start with the same values. */
1319813210
else if (oidSz == sizeof(dcOid) && XMEMCMP(oid, dcOid, oidSz-1) == 0) {
1319913211
WOLFSSL_MSG("Unknown pilot attribute type");
@@ -13845,7 +13857,6 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1384513857
nid = NID_userId;
1384613858
#endif /* OPENSSL_EXTRA */
1384713859
break;
13848-
1384913860
case ASN_DOMAIN_COMPONENT:
1385013861
copy = WOLFSSL_DOMAIN_COMPONENT;
1385113862
copyLen = sizeof(WOLFSSL_DOMAIN_COMPONENT) - 1;
@@ -13864,7 +13875,15 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1386413875
nid = NID_favouriteDrink;
1386513876
#endif /* OPENSSL_EXTRA */
1386613877
break;
13867-
13878+
case ASN_CONTENT_TYPE:
13879+
copy = WOLFSSL_CONTENT_TYPE;
13880+
copyLen = sizeof(WOLFSSL_CONTENT_TYPE) - 1;
13881+
#if (defined(OPENSSL_EXTRA) || \
13882+
defined(OPENSSL_EXTRA_X509_SMALL)) \
13883+
&& !defined(WOLFCRYPT_ONLY)
13884+
nid = NID_pkcs9_contentType;
13885+
#endif /* OPENSSL_EXTRA */
13886+
break;
1386813887
default:
1386913888
WOLFSSL_MSG("Unknown pilot attribute type");
1387013889
#if (defined(OPENSSL_EXTRA) || \
@@ -26457,6 +26476,12 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2645726476
thisLen += cname->custom.oidSz;
2645826477
firstSz = cname->custom.oidSz;
2645926478
break;
26479+
#endif
26480+
#ifdef WOLFSSL_CERT_REQ
26481+
case ASN_CONTENT_TYPE:
26482+
thisLen += (int)sizeof(attrPkcs9ContentTypeOid);
26483+
firstSz = (int)sizeof(attrPkcs9ContentTypeOid);
26484+
break;
2646026485
#endif
2646126486
default:
2646226487
thisLen += DN_OID_SZ;
@@ -26521,6 +26546,15 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2652126546
/* str type */
2652226547
name->encoded[idx++] = nameTag;
2652326548
break;
26549+
#endif
26550+
#ifdef WOLFSSL_CERT_REQ
26551+
case ASN_CONTENT_TYPE:
26552+
XMEMCPY(name->encoded + idx, attrPkcs9ContentTypeOid,
26553+
sizeof(attrPkcs9ContentTypeOid));
26554+
idx += (int)sizeof(attrPkcs9ContentTypeOid);
26555+
/* str type */
26556+
name->encoded[idx++] = nameTag;
26557+
break;
2652426558
#endif
2652526559
default:
2652626560
name->encoded[idx++] = 0x55;
@@ -26593,6 +26627,12 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2659326627
oid = cname->custom.oid;
2659426628
oidSz = cname->custom.oidSz;
2659526629
break;
26630+
#endif
26631+
#ifdef WOLFSSL_CERT_REQ
26632+
case ASN_CONTENT_TYPE:
26633+
oid = attrPkcs9ContentTypeOid;
26634+
oidSz = sizeof(attrPkcs9ContentTypeOid);
26635+
break;
2659626636
#endif
2659726637
default:
2659826638
/* Construct OID using type. */

wolfssl/wolfcrypt/asn.h

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

713-
ASN_EMAIL_NAME = 0x98, /* not actual OID (see attrEmailOid) */
714-
ASN_CUSTOM_NAME = 0x99, /* not actual OID (see CertOidField) */
713+
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) */
715717

716718
/* pilot attribute types
717719
* OID values of 0.9.2342.19200300.100.1.* */
@@ -768,6 +770,7 @@ extern const WOLFSSL_ObjectInfo wolfssl_object_info[];
768770
#define WOLFSSL_USER_ID "/UID="
769771
#define WOLFSSL_DOMAIN_COMPONENT "/DC="
770772
#define WOLFSSL_FAVOURITE_DRINK "/favouriteDrink="
773+
#define WOLFSSL_CONTENT_TYPE "/contentType="
771774

772775
#if defined(WOLFSSL_APACHE_HTTPD)
773776
/* otherName strings */

0 commit comments

Comments
 (0)