]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg/BaseCryptLib.h: Add new API VerifyEKUsInPkcs7Signature
[mirror_edk2.git] / CryptoPkg / Include / Library / BaseCryptLib.h
index dc6aaf0635c2e90d84b118344475241d4caf950e..f9191f6e96d33d2e0c0a2d666e79fa992ca93f9c 100644 (file)
@@ -5,13 +5,7 @@
   functionality enabling.\r
 \r
 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -2192,7 +2186,7 @@ X509GetSubjectName (
                                    If Certificate is invalid.\r
   @retval RETURN_NOT_FOUND         If no CommonName entry exists.\r
   @retval RETURN_BUFFER_TOO_SMALL  If the CommonName is NULL. The required buffer size\r
-                                   (including the final null) is returned in the \r
+                                   (including the final null) is returned in the\r
                                    CommonNameSize parameter.\r
   @retval RETURN_UNSUPPORTED       The operation is not supported.\r
 \r
@@ -2206,6 +2200,41 @@ X509GetCommonName (
   IN OUT  UINTN        *CommonNameSize\r
   );\r
 \r
+/**\r
+  Retrieve the organization name (O) string from one X.509 certificate.\r
+\r
+  @param[in]      Cert             Pointer to the DER-encoded X509 certificate.\r
+  @param[in]      CertSize         Size of the X509 certificate in bytes.\r
+  @param[out]     NameBuffer       Buffer to contain the retrieved certificate organization\r
+                                   name string. At most NameBufferSize bytes will be\r
+                                   written and the string will be null terminated. May be\r
+                                   NULL in order to determine the size buffer needed.\r
+  @param[in,out]  NameBufferSize   The size in bytes of the Name buffer on input,\r
+                                   and the size of buffer returned Name on output.\r
+                                   If NameBuffer is NULL then the amount of space needed\r
+                                   in buffer (including the final null) is returned.\r
+\r
+  @retval RETURN_SUCCESS           The certificate Organization Name retrieved successfully.\r
+  @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
+                                   If NameBufferSize is NULL.\r
+                                   If NameBuffer is not NULL and *CommonNameSize is 0.\r
+                                   If Certificate is invalid.\r
+  @retval RETURN_NOT_FOUND         If no Organization Name entry exists.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If the NameBuffer is NULL. The required buffer size\r
+                                   (including the final null) is returned in the\r
+                                   CommonNameSize parameter.\r
+  @retval RETURN_UNSUPPORTED       The operation is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+X509GetOrganizationName (\r
+  IN      CONST UINT8   *Cert,\r
+  IN      UINTN         CertSize,\r
+  OUT     CHAR8         *NameBuffer,  OPTIONAL\r
+  IN OUT  UINTN         *NameBufferSize\r
+  );\r
+\r
 /**\r
   Verify one X509 certificate was issued by the trusted CA.\r
 \r
@@ -2564,6 +2593,48 @@ Pkcs7Verify (
   IN  UINTN        DataLength\r
   );\r
 \r
+/**\r
+  This function receives a PKCS7 formatted signature, and then verifies that\r
+  the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
+  leaf signing certificate.\r
+  Note that this function does not validate the certificate chain.\r
+\r
+  Applications for custom EKU's are quite flexible. For example, a policy EKU\r
+  may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
+  certificate issued might also contain this EKU, thus constraining the\r
+  sub-ordinate certificate.  Other applications might allow a certificate\r
+  embedded in a device to specify that other Object Identifiers (OIDs) are\r
+  present which contains binary data specifying custom capabilities that\r
+  the device is able to do.\r
+\r
+  @param[in]  Pkcs7Signature       The PKCS#7 signed information content block. An array\r
+                                   containing the content block with both the signature,\r
+                                   the signer's certificate, and any necessary intermediate\r
+                                   certificates.\r
+  @param[in]  Pkcs7SignatureSize   Number of bytes in Pkcs7Signature.\r
+  @param[in]  RequiredEKUs         Array of null-terminated strings listing OIDs of\r
+                                   required EKUs that must be present in the signature.\r
+  @param[in]  RequiredEKUsSize     Number of elements in the RequiredEKUs string array.\r
+  @param[in]  RequireAllPresent    If this is TRUE, then all of the specified EKU's\r
+                                   must be present in the leaf signer.  If it is\r
+                                   FALSE, then we will succeed if we find any\r
+                                   of the specified EKU's.\r
+\r
+  @retval EFI_SUCCESS              The required EKUs were found in the signature.\r
+  @retval EFI_INVALID_PARAMETER    A parameter was invalid.\r
+  @retval EFI_NOT_FOUND            One or more EKU's were not found in the signature.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+VerifyEKUsInPkcs7Signature (\r
+  IN  CONST UINT8   *Pkcs7Signature,\r
+  IN  CONST UINT32  SignatureSize,\r
+  IN  CONST CHAR8   *RequiredEKUs[],\r
+  IN  CONST UINT32  RequiredEKUsSize,\r
+  IN  BOOLEAN       RequireAllPresent\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