]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
CryptoPkg/Pkcs7: Extend support for other OID types
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Pk / CryptPkcs7VerifyBase.c
index 313f459b11f615e9374d0fcb3d1b41af2e8818f9..112c13c226f023355cbb7b28af420ef4ba29033f 100644 (file)
@@ -13,6 +13,67 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <openssl/x509v3.h>\r
 #include <openssl/pkcs7.h>\r
 \r
+/**\r
+  Check the contents of PKCS7 is not data.\r
+\r
+  It is copied from PKCS7_type_is_other() in pk7_doit.c.\r
+\r
+  @param[in] P7 Pointer to the location at which the PKCS7 is located.\r
+\r
+  @retval TRUE  If the type is others.\r
+  @retval FALSE If the type is expected.\r
+**/\r
+STATIC\r
+BOOLEAN\r
+Pkcs7TypeIsOther (\r
+  IN PKCS7 *P7\r
+  )\r
+{\r
+  BOOLEAN Others;\r
+  INTN    Nid = OBJ_obj2nid (P7->type);\r
+\r
+  switch (Nid) {\r
+    case NID_pkcs7_data:\r
+    case NID_pkcs7_signed:\r
+    case NID_pkcs7_enveloped:\r
+    case NID_pkcs7_signedAndEnveloped:\r
+    case NID_pkcs7_encrypted:\r
+      Others = FALSE;\r
+      break;\r
+    default:\r
+      Others = TRUE;\r
+  }\r
+\r
+  return Others;\r
+}\r
+\r
+/**\r
+  Get the ASN.1 string for the PKCS7.\r
+\r
+  It is copied from PKCS7_get_octet_string() in pk7_doit.c.\r
+\r
+  @param[in] P7 Pointer to the location at which the PKCS7 is located.\r
+\r
+  @return ASN1_OCTET_STRING ASN.1 string.\r
+**/\r
+STATIC\r
+ASN1_OCTET_STRING*\r
+Pkcs7GetOctetString (\r
+  IN PKCS7 *P7\r
+  )\r
+{\r
+  if (PKCS7_type_is_data (P7)) {\r
+    return P7->d.data;\r
+  }\r
+\r
+  if (Pkcs7TypeIsOther(P7) && (P7->d.other != NULL) &&\r
+      (P7->d.other->type == V_ASN1_OCTET_STRING)) {\r
+    return P7->d.other->value.octet_string;\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
 /**\r
   Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
   data could be wrapped in a ContentInfo structure.\r
@@ -98,7 +159,11 @@ Pkcs7GetAttachedContent (
     //\r
     // Retrieve the attached content in PKCS7 signedData\r
     //\r
-    OctStr = Pkcs7->d.sign->contents->d.data;\r
+    OctStr = Pkcs7GetOctetString (Pkcs7->d.sign->contents);\r
+    if (OctStr == NULL) {\r
+      goto _Exit;\r
+    }\r
+\r
     if ((OctStr->length > 0) && (OctStr->data != NULL)) {\r
       *ContentSize = OctStr->length;\r
       *Content     = AllocatePool (*ContentSize);\r