Skip to content

Commit

Permalink
Merge pull request #8280 from kareem-wolfssl/zd19046
Browse files Browse the repository at this point in the history
Add support for the RFC822 Mailbox attribute.
  • Loading branch information
SparkiDev authored Dec 12, 2024
2 parents dd30126 + d4af181 commit 65fc8f8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17504,6 +17504,8 @@ const WOLFSSL_ObjectInfo wolfssl_object_info[] = {
"emailAddress"},
{ WC_NID_domainComponent, WC_NID_domainComponent, oidCertNameType, "DC",
"domainComponent"},
{ WC_NID_rfc822Mailbox, WC_NID_rfc822Mailbox, oidCertNameType, "rfc822Mailbox",
"rfc822Mailbox"},
{ WC_NID_favouriteDrink, WC_NID_favouriteDrink, oidCertNameType, "favouriteDrink",
"favouriteDrink"},
{ WC_NID_businessCategory, WC_NID_businessCategory, oidCertNameType,
Expand Down
1 change: 1 addition & 0 deletions src/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -11485,6 +11485,7 @@ static int ConvertNIDToWolfSSL(int nid)
case WC_NID_businessCategory: return ASN_BUS_CAT;
case WC_NID_domainComponent: return ASN_DOMAIN_COMPONENT;
case WC_NID_postalCode: return ASN_POSTAL_CODE;
case WC_NID_rfc822Mailbox: return ASN_RFC822_MAILBOX;
case WC_NID_favouriteDrink: return ASN_FAVOURITE_DRINK;
default:
WOLFSSL_MSG("Attribute NID not found");
Expand Down
5 changes: 5 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -69680,13 +69680,17 @@ static int test_wolfSSL_X509_NAME_ENTRY(void)
#ifdef WOLFSSL_CERT_REQ
{
unsigned char srv_pkcs9p[] = "Server";
unsigned char rfc822Mlbx[] = "[email protected]";
unsigned char fvrtDrnk[] = "tequila";
unsigned char* der = NULL;
char* subject = NULL;

ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);

ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_rfc822Mailbox,
MBSTRING_ASC, rfc822Mlbx, -1, -1, 0), SSL_SUCCESS);

ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);

Expand All @@ -69695,6 +69699,7 @@ static int test_wolfSSL_X509_NAME_ENTRY(void)
ExpectNotNull(der);

ExpectNotNull(subject = X509_NAME_oneline(nm, NULL, 0));
ExpectNotNull(XSTRSTR(subject, "[email protected]"));
ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
#ifdef DEBUG_WOLFSSL
Expand Down
39 changes: 39 additions & 0 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4601,6 +4601,7 @@ static const byte dnsSRVOid[] = {43, 6, 1, 5, 5, 7, 8, 7};
/* Pilot attribute types (0.9.2342.19200300.100.1.*) */
#define PLT_ATTR_TYPE_OID_BASE(num) {9, 146, 38, 137, 147, 242, 44, 100, 1, num}
static const byte uidOid[] = PLT_ATTR_TYPE_OID_BASE(1); /* user id */
static const byte rfc822Mlbx[] = PLT_ATTR_TYPE_OID_BASE(3); /* RFC822 mailbox */
static const byte fvrtDrk[] = PLT_ATTR_TYPE_OID_BASE(5);/* favourite drink*/
#endif

Expand Down Expand Up @@ -13887,6 +13888,15 @@ static int GetRDN(DecodedCert* cert, char* full, word32* idx, int* nid,
*nid = WC_NID_domainComponent;
#endif
}
else if (oidSz == sizeof(rfc822Mlbx) && XMEMCMP(oid, rfc822Mlbx, oidSz) == 0) {
/* Set the RFC822 mailbox, type string, length and NID. */
id = ASN_RFC822_MAILBOX;
typeStr = WOLFSSL_RFC822_MAILBOX;
typeStrLen = sizeof(WOLFSSL_RFC822_MAILBOX) - 1;
#ifdef WOLFSSL_X509_NAME_AVAILABLE
*nid = WC_NID_rfc822Mailbox;
#endif
}
else if (oidSz == sizeof(fvrtDrk) && XMEMCMP(oid, fvrtDrk, oidSz) == 0) {
/* Set the favourite drink, type string, length and NID. */
id = ASN_FAVOURITE_DRINK;
Expand Down Expand Up @@ -14591,6 +14601,15 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
nid = WC_NID_domainComponent;
#endif /* OPENSSL_EXTRA */
break;
case ASN_RFC822_MAILBOX:
copy = WOLFSSL_RFC822_MAILBOX;
copyLen = sizeof(WOLFSSL_RFC822_MAILBOX) - 1;
#if (defined(OPENSSL_EXTRA) || \
defined(OPENSSL_EXTRA_X509_SMALL)) \
&& !defined(WOLFCRYPT_ONLY)
nid = WC_NID_rfc822Mailbox;
#endif /* OPENSSL_EXTRA */
break;
case ASN_FAVOURITE_DRINK:
copy = WOLFSSL_FAVOURITE_DRINK;
copyLen = sizeof(WOLFSSL_FAVOURITE_DRINK) - 1;
Expand Down Expand Up @@ -28094,6 +28113,10 @@ static int EncodeName(EncodedName* name, const char* nameStr,
thisLen += (int)sizeof(uidOid);
firstSz = (int)sizeof(uidOid);
break;
case ASN_RFC822_MAILBOX:
thisLen += (int)sizeof(rfc822Mlbx);
firstSz = (int)sizeof(rfc822Mlbx);
break;
case ASN_FAVOURITE_DRINK:
thisLen += (int)sizeof(fvrtDrk);
firstSz = (int)sizeof(fvrtDrk);
Expand Down Expand Up @@ -28159,6 +28182,12 @@ static int EncodeName(EncodedName* name, const char* nameStr,
/* str type */
name->encoded[idx++] = nameTag;
break;
case ASN_RFC822_MAILBOX:
XMEMCPY(name->encoded + idx, rfc822Mlbx, sizeof(rfc822Mlbx));
idx += (int)sizeof(rfc822Mlbx);
/* str type */
name->encoded[idx++] = nameTag;
break;
case ASN_FAVOURITE_DRINK:
XMEMCPY(name->encoded + idx, fvrtDrk, sizeof(fvrtDrk));
idx += (int)sizeof(fvrtDrk);
Expand Down Expand Up @@ -28255,6 +28284,10 @@ static int EncodeName(EncodedName* name, const char* nameStr,
oid = uidOid;
oidSz = sizeof(uidOid);
break;
case ASN_RFC822_MAILBOX:
oid = rfc822Mlbx;
oidSz = sizeof(rfc822Mlbx);
break;
case ASN_FAVOURITE_DRINK:
oid = fvrtDrk;
oidSz = sizeof(fvrtDrk);
Expand Down Expand Up @@ -28578,6 +28611,12 @@ static int SetNameRdnItems(ASNSetData* dataASN, ASNItem* namesASN,
sizeof(uidOid), (byte)GetNameType(name, i),
(const byte*)GetOneCertName(name, i), nameLen[i]);
}
else if (type == ASN_RFC822_MAILBOX) {
/* Copy RFC822 mailbox data into dynamic vars. */
SetRdnItems(namesASN + idx, dataASN + idx, rfc822Mlbx,
sizeof(rfc822Mlbx), (byte)GetNameType(name, i),
(const byte*)GetOneCertName(name, i), nameLen[i]);
}
else if (type == ASN_FAVOURITE_DRINK) {
/* Copy favourite drink data into dynamic vars. */
SetRdnItems(namesASN + idx, dataASN + idx, fvrtDrk,
Expand Down
4 changes: 4 additions & 0 deletions wolfssl/wolfcrypt/asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ enum DN_Tags {
/* pilot attribute types
* OID values of 0.9.2342.19200300.100.1.* */
ASN_FAVOURITE_DRINK = 0x13, /* favouriteDrink */
ASN_RFC822_MAILBOX = 0x14, /* rfc822Mailbox */
ASN_DOMAIN_COMPONENT = 0x19 /* DC */
};

Expand Down Expand Up @@ -780,6 +781,7 @@ extern const WOLFSSL_ObjectInfo wolfssl_object_info[];

#define WOLFSSL_USER_ID "/UID="
#define WOLFSSL_DOMAIN_COMPONENT "/DC="
#define WOLFSSL_RFC822_MAILBOX "/rfc822Mailbox="
#define WOLFSSL_FAVOURITE_DRINK "/favouriteDrink="
#define WOLFSSL_CONTENT_TYPE "/contentType="

Expand Down Expand Up @@ -912,6 +914,7 @@ extern const WOLFSSL_ObjectInfo wolfssl_object_info[];
#define WC_NID_businessCategory ASN_BUS_CAT
#define WC_NID_domainComponent ASN_DOMAIN_COMPONENT
#define WC_NID_postalCode ASN_POSTAL_CODE /* postalCode */
#define WC_NID_rfc822Mailbox 460
#define WC_NID_favouriteDrink 462
#define WC_NID_userId 458
#define WC_NID_registeredAddress 870
Expand Down Expand Up @@ -985,6 +988,7 @@ extern const WOLFSSL_ObjectInfo wolfssl_object_info[];
#define NID_businessCategory WC_NID_businessCategory
#define NID_domainComponent WC_NID_domainComponent
#define NID_postalCode WC_NID_postalCode
#define NID_rfc822Mailbox WC_NID_rfc822Mailbox
#define NID_favouriteDrink WC_NID_favouriteDrink
#define NID_userId WC_NID_userId
#define NID_emailAddress WC_NID_emailAddress
Expand Down

0 comments on commit 65fc8f8

Please sign in to comment.