Add PKCS7 data OID support and enhance X.509 OID comparison

- Add oidPkcs7Type to Oid_Types enum in asn.h for PKCS7 content type recognition
- Add pkcs7DataOid byte array definition for OID 1.2.840.113549.1.7.1 in asn.c
- Add OID recognition logic in GetOID function to handle PKCS7 data content type
- Add GetEntryByOID function in x509.c for direct OID byte comparison
- Enhance wolfSSL_X509_NAME_get_index_by_OBJ to use OID comparison instead of string comparison
- All changes are properly guarded with #ifdef HAVE_PKCS7 where appropriate
- Maintains backward compatibility with existing APIs

Co-Authored-By: lealem@wolfssl.com <lealem@wolfssl.com>
This commit is contained in:
Devin AI
2025-07-22 17:09:30 +00:00
parent b0fd0296f3
commit 9fe8f44bb2
3 changed files with 50 additions and 13 deletions

View File

@@ -5493,6 +5493,29 @@ static WOLFSSL_X509_NAME_ENTRY* GetEntryByNID(WOLFSSL_X509_NAME* name, int nid,
return ret;
}
static WOLFSSL_X509_NAME_ENTRY* GetEntryByOID(WOLFSSL_X509_NAME* name,
const WOLFSSL_ASN1_OBJECT* obj, int* idx)
{
int i;
WOLFSSL_X509_NAME_ENTRY* ret = NULL;
if (!obj || !obj->obj) {
return NULL;
}
for (i = *idx; i < MAX_NAME_ENTRIES; i++) {
if (name->entry[i].set && name->entry[i].object) {
if (obj->objSz == name->entry[i].object->objSz &&
XMEMCMP(obj->obj, name->entry[i].object->obj, obj->objSz) == 0) {
ret = &name->entry[i];
*idx = i;
break;
}
}
}
return ret;
}
/* Used to get a string from the WOLFSSL_X509_NAME structure that
* corresponds with the NID value passed in. This finds the first entry with
@@ -13212,26 +13235,23 @@ WOLFSSL_ASN1_OBJECT* wolfSSL_X509_NAME_ENTRY_get_object(
int wolfSSL_X509_NAME_get_index_by_OBJ(WOLFSSL_X509_NAME *name,
const WOLFSSL_ASN1_OBJECT *obj,
int idx) {
if (!name || idx >= MAX_NAME_ENTRIES ||
!obj || !obj->obj) {
WOLFSSL_X509_NAME_ENTRY* entry;
if (!name || idx >= MAX_NAME_ENTRIES || !obj) {
return WOLFSSL_FATAL_ERROR;
}
if (idx < 0) {
idx = -1;
idx = 0;
} else {
idx++; /* Start searching from next index */
}
for (idx++; idx < MAX_NAME_ENTRIES; idx++) {
/* Find index of desired name */
if (name->entry[idx].set) {
if (XSTRLEN(obj->sName) ==
XSTRLEN(name->entry[idx].object->sName) &&
XSTRNCMP((const char*) obj->sName,
name->entry[idx].object->sName, obj->objSz - 1) == 0) {
return idx;
}
}
entry = GetEntryByOID(name, obj, &idx);
if (entry != NULL) {
return idx;
}
return WOLFSSL_FATAL_ERROR;
}
#endif

View File

@@ -4468,6 +4468,8 @@ static word32 SetBitString16Bit(word16 val, byte* output)
#ifdef HAVE_PKCS7
/* From RFC 3211 */
static const byte wrapPwriKekOid[] = {42, 134, 72, 134, 247, 13, 1, 9, 16, 3,9};
/* PKCS#7 content types */
static const byte pkcs7DataOid[] = {42, 134, 72, 134, 247, 13, 1, 7, 1};
#endif
/* cmsKeyAgreeType */
@@ -6429,6 +6431,18 @@ const byte* OidFromId(word32 id, word32 type, word32* oidSz)
}
break;
#endif /* WOLFSSL_SUBJ_DIR_ATTR */
#ifdef HAVE_PKCS7
case oidPkcs7Type:
switch (id) {
case DATA:
oid = pkcs7DataOid;
*oidSz = sizeof(pkcs7DataOid);
break;
default:
break;
}
break;
#endif
case oidIgnoreType:
default:
break;

View File

@@ -1229,6 +1229,9 @@ enum Oid_Types {
oidCsrAttrType = 20,
#ifdef WOLFSSL_SUBJ_DIR_ATTR
oidSubjDirAttrType = 21,
#endif
#ifdef HAVE_PKCS7
oidPkcs7Type = 22,
#endif
oidIgnoreType
};