]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c
1. Remove conducting ASSERT in BaseCryptLib.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Pk / CryptX509.c
index 3a5485e002c7c4e60d1a8539359d2cd87fe458c8..153e7106171eeaa83cce35e4814d6c054645deb6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   X.509 Certificate Handler Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   X.509 Certificate Handler Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2012, 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
 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
@@ -19,8 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /**\r
   Construct a X509 object from DER-encoded certificate data.\r
 \r
 /**\r
   Construct a X509 object from DER-encoded certificate data.\r
 \r
-  If Cert is NULL, then ASSERT().\r
-  If SingleX509Cert is NULL, then ASSERT().\r
+  If Cert is NULL, then return FALSE.\r
+  If SingleX509Cert is NULL, then return FALSE.\r
 \r
   @param[in]  Cert            Pointer to the DER-encoded certificate data.\r
   @param[in]  CertSize        The size of certificate data in bytes.\r
 \r
   @param[in]  Cert            Pointer to the DER-encoded certificate data.\r
   @param[in]  CertSize        The size of certificate data in bytes.\r
@@ -43,11 +43,11 @@ X509ConstructCertificate (
   BOOLEAN  Status;\r
 \r
   //\r
   BOOLEAN  Status;\r
 \r
   //\r
-  // ASSERT if Cert is NULL or SingleX509Cert is NULL.\r
+  // Check input parameters.\r
   //\r
   //\r
-  ASSERT (Cert           != NULL);\r
-  ASSERT (SingleX509Cert != NULL);\r
-  ASSERT (CertSize       <= INT_MAX);\r
+  if (Cert == NULL || SingleX509Cert == NULL || CertSize > INT_MAX) {\r
+    return FALSE;\r
+  }\r
 \r
   Status = FALSE;\r
 \r
 \r
   Status = FALSE;\r
 \r
@@ -79,7 +79,7 @@ _Exit:
 /**\r
   Construct a X509 stack object from a list of DER-encoded certificate data.\r
 \r
 /**\r
   Construct a X509 stack object from a list of DER-encoded certificate data.\r
 \r
-  If X509Stack is NULL, then ASSERT().\r
+  If X509Stack is NULL, then return FALSE.\r
 \r
   @param[in, out]  X509Stack  On input, pointer to an existing X509 stack object.\r
                               On output, pointer to the X509 stack object with new\r
 \r
   @param[in, out]  X509Stack  On input, pointer to an existing X509 stack object.\r
                               On output, pointer to the X509 stack object with new\r
@@ -108,9 +108,11 @@ X509ConstructCertificateStack (
   UINTN           Index;\r
 \r
   //\r
   UINTN           Index;\r
 \r
   //\r
-  // ASSERT if input X509Stack is NULL.\r
+  // Check input parameters.\r
   //\r
   //\r
-  ASSERT (X509Stack != NULL);\r
+  if (X509Stack == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   Status = FALSE;\r
 \r
 \r
   Status = FALSE;\r
 \r
@@ -171,7 +173,7 @@ X509ConstructCertificateStack (
 /**\r
   Release the specified X509 object.\r
 \r
 /**\r
   Release the specified X509 object.\r
 \r
-  If X509Cert is NULL, then ASSERT().\r
+  If X509Cert is NULL, then return FALSE.\r
 \r
   @param[in]  X509Cert  Pointer to the X509 object to be released.\r
 \r
 \r
   @param[in]  X509Cert  Pointer to the X509 object to be released.\r
 \r
@@ -181,9 +183,14 @@ EFIAPI
 X509Free (\r
   IN  VOID  *X509Cert\r
   )\r
 X509Free (\r
   IN  VOID  *X509Cert\r
   )\r
-{\r
-  ASSERT (X509Cert != NULL);\r
-\r
+{ \r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (X509Cert == NULL) {\r
+    return;\r
+  }\r
+  \r
   //\r
   // Free OpenSSL X509 object.\r
   //\r
   //\r
   // Free OpenSSL X509 object.\r
   //\r
@@ -193,7 +200,7 @@ X509Free (
 /**\r
   Release the specified X509 stack object.\r
 \r
 /**\r
   Release the specified X509 stack object.\r
 \r
-  If X509Stack is NULL, then ASSERT().\r
+  If X509Stack is NULL, then return FALSE.\r
 \r
   @param[in]  X509Stack  Pointer to the X509 stack object to be released.\r
 \r
 \r
   @param[in]  X509Stack  Pointer to the X509 stack object to be released.\r
 \r
@@ -204,8 +211,13 @@ X509StackFree (
   IN  VOID  *X509Stack\r
   )\r
 {\r
   IN  VOID  *X509Stack\r
   )\r
 {\r
-  ASSERT (X509Stack != NULL);\r
-\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (X509Stack == NULL) {\r
+    return;\r
+  }\r
+  \r
   //\r
   // Free OpenSSL X509 stack object.\r
   //\r
   //\r
   // Free OpenSSL X509 stack object.\r
   //\r
@@ -221,8 +233,8 @@ X509StackFree (
   @param[in, out] SubjectSize  The size in bytes of the CertSubject buffer on input,\r
                                and the size of buffer returned CertSubject on output.\r
 \r
   @param[in, out] SubjectSize  The size in bytes of the CertSubject buffer on input,\r
                                and the size of buffer returned CertSubject on output.\r
 \r
-  If Cert is NULL, then ASSERT().\r
-  If SubjectSize is NULL, then ASSERT().\r
+  If Cert is NULL, then return FALSE.\r
+  If SubjectSize is NULL, then return FALSE.\r
 \r
   @retval  TRUE   The certificate subject retrieved successfully.\r
   @retval  FALSE  Invalid certificate, or the SubjectSize is too small for the result.\r
 \r
   @retval  TRUE   The certificate subject retrieved successfully.\r
   @retval  FALSE  Invalid certificate, or the SubjectSize is too small for the result.\r
@@ -243,10 +255,11 @@ X509GetSubjectName (
   X509_NAME  *X509Name;\r
 \r
   //\r
   X509_NAME  *X509Name;\r
 \r
   //\r
-  // ASSERT if Cert is NULL or SubjectSize is NULL.\r
+  // Check input parameters.\r
   //\r
   //\r
-  ASSERT (Cert        != NULL);\r
-  ASSERT (SubjectSize != NULL);\r
+  if (Cert == NULL || SubjectSize == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   Status   = FALSE;\r
   X509Cert = NULL;\r
 \r
   Status   = FALSE;\r
   X509Cert = NULL;\r
@@ -291,8 +304,8 @@ _Exit:
                            RSA public key component. Use RsaFree() function to free the\r
                            resource.\r
 \r
                            RSA public key component. Use RsaFree() function to free the\r
                            resource.\r
 \r
-  If Cert is NULL, then ASSERT().\r
-  If RsaContext is NULL, then ASSERT().\r
+  If Cert is NULL, then return FALSE.\r
+  If RsaContext is NULL, then return FALSE.\r
 \r
   @retval  TRUE   RSA Public Key was retrieved successfully.\r
   @retval  FALSE  Fail to retrieve RSA public key from X509 certificate.\r
 \r
   @retval  TRUE   RSA Public Key was retrieved successfully.\r
   @retval  FALSE  Fail to retrieve RSA public key from X509 certificate.\r
@@ -309,12 +322,13 @@ RsaGetPublicKeyFromX509 (
   BOOLEAN   Status;\r
   EVP_PKEY  *Pkey;\r
   X509      *X509Cert;\r
   BOOLEAN   Status;\r
   EVP_PKEY  *Pkey;\r
   X509      *X509Cert;\r
-\r
+  \r
   //\r
   //\r
-  // ASSERT if Cert is NULL or RsaContext is NULL.\r
+  // Check input parameters.\r
   //\r
   //\r
-  ASSERT (Cert       != NULL);\r
-  ASSERT (RsaContext != NULL);\r
+  if (Cert == NULL || RsaContext == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   Status   = FALSE;\r
   Pkey     = NULL;\r
 \r
   Status   = FALSE;\r
   Pkey     = NULL;\r
@@ -361,8 +375,8 @@ _Exit:
   @param[in]      CACert       Pointer to the DER-encoded trusted CA certificate.\r
   @param[in]      CACertSize   Size of the CA Certificate in bytes.\r
 \r
   @param[in]      CACert       Pointer to the DER-encoded trusted CA certificate.\r
   @param[in]      CACertSize   Size of the CA Certificate in bytes.\r
 \r
-  If Cert is NULL, then ASSERT().\r
-  If CACert is NULL, then ASSERT().\r
+  If Cert is NULL, then return FALSE.\r
+  If CACert is NULL, then return FALSE.\r
 \r
   @retval  TRUE   The certificate was issued by the trusted CA.\r
   @retval  FALSE  Invalid certificate or the certificate was not issued by the given\r
 \r
   @retval  TRUE   The certificate was issued by the trusted CA.\r
   @retval  FALSE  Invalid certificate or the certificate was not issued by the given\r
@@ -383,12 +397,13 @@ X509VerifyCert (
   X509            *X509CACert;\r
   X509_STORE      *CertStore;\r
   X509_STORE_CTX  CertCtx;\r
   X509            *X509CACert;\r
   X509_STORE      *CertStore;\r
   X509_STORE_CTX  CertCtx;\r
-\r
+  \r
   //\r
   //\r
-  // ASSERT if Cert is NULL or CACert is NULL.\r
+  // Check input parameters.\r
   //\r
   //\r
-  ASSERT (Cert   != NULL);\r
-  ASSERT (CACert != NULL);\r
+  if (Cert == NULL || CACert == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   Status     = FALSE;\r
   X509Cert   = NULL;\r
 \r
   Status     = FALSE;\r
   X509Cert   = NULL;\r