]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c
CryptoPkg: Update PK Cipher Wrappers work with opaque objects.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Pk / CryptX509.c
index 5d6be6fce9e545408529b43c6baff85d059d8e08..7d275977c59724c87149291c673fe7ba4828f705 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   X.509 Certificate Handler Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2017, 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
@@ -73,7 +73,7 @@ X509ConstructCertificate (
   @param           ...        A list of DER-encoded single certificate data followed\r
                               by certificate size. A NULL terminates the list. The\r
                               pairs are the arguments to X509ConstructCertificate().\r
-                                 \r
+\r
   @retval     TRUE            The X509 stack construction succeeded.\r
   @retval     FALSE           The construction operation failed.\r
 \r
@@ -82,7 +82,7 @@ BOOLEAN
 EFIAPI\r
 X509ConstructCertificateStack (\r
   IN OUT  UINT8  **X509Stack,\r
-  ...  \r
+  ...\r
   )\r
 {\r
   UINT8           *Cert;\r
@@ -175,14 +175,14 @@ EFIAPI
 X509Free (\r
   IN  VOID  *X509Cert\r
   )\r
-{ \r
+{\r
   //\r
   // Check input parameters.\r
   //\r
   if (X509Cert == NULL) {\r
     return;\r
   }\r
-  \r
+\r
   //\r
   // Free OpenSSL X509 object.\r
   //\r
@@ -209,7 +209,7 @@ X509StackFree (
   if (X509Stack == NULL) {\r
     return;\r
   }\r
-  \r
+\r
   //\r
   // Free OpenSSL X509 stack object.\r
   //\r
@@ -324,7 +324,7 @@ RsaGetPublicKeyFromX509 (
   BOOLEAN   Status;\r
   EVP_PKEY  *Pkey;\r
   X509      *X509Cert;\r
-  \r
+\r
   //\r
   // Check input parameters.\r
   //\r
@@ -350,14 +350,14 @@ RsaGetPublicKeyFromX509 (
   // Retrieve and check EVP_PKEY data from X509 Certificate.\r
   //\r
   Pkey = X509_get_pubkey (X509Cert);\r
-  if ((Pkey == NULL) || (Pkey->type != EVP_PKEY_RSA)) {\r
+  if ((Pkey == NULL) || (EVP_PKEY_id (Pkey) != EVP_PKEY_RSA)) {\r
     goto _Exit;\r
   }\r
 \r
   //\r
   // Duplicate RSA Context from the retrieved EVP_PKEY.\r
   //\r
-  if ((*RsaContext = RSAPublicKey_dup (Pkey->pkey.rsa)) != NULL) {\r
+  if ((*RsaContext = RSAPublicKey_dup (EVP_PKEY_get0_RSA (Pkey))) != NULL) {\r
     Status = TRUE;\r
   }\r
 \r
@@ -371,7 +371,7 @@ _Exit:
 \r
   if (Pkey != NULL) {\r
     EVP_PKEY_free (Pkey);\r
-  }  \r
+  }\r
 \r
   return Status;\r
 }\r
@@ -405,8 +405,8 @@ X509VerifyCert (
   X509            *X509Cert;\r
   X509            *X509CACert;\r
   X509_STORE      *CertStore;\r
-  X509_STORE_CTX  CertCtx;\r
-  \r
+  X509_STORE_CTX  *CertCtx;\r
+\r
   //\r
   // Check input parameters.\r
   //\r
@@ -418,6 +418,7 @@ X509VerifyCert (
   X509Cert   = NULL;\r
   X509CACert = NULL;\r
   CertStore  = NULL;\r
+  CertCtx    = NULL;\r
 \r
   //\r
   // Register & Initialize necessary digest algorithms for certificate verification.\r
@@ -463,18 +464,29 @@ X509VerifyCert (
     goto _Exit;\r
   }\r
 \r
+  //\r
+  // Allow partial certificate chains, terminated by a non-self-signed but\r
+  // still trusted intermediate certificate. Also disable time checks.\r
+  //\r
+  X509_STORE_set_flags (CertStore,\r
+                        X509_V_FLAG_PARTIAL_CHAIN | X509_V_FLAG_NO_CHECK_TIME);\r
+\r
   //\r
   // Set up X509_STORE_CTX for the subsequent verification operation.\r
   //\r
-  if (!X509_STORE_CTX_init (&CertCtx, CertStore, X509Cert, NULL)) {\r
+  CertCtx = X509_STORE_CTX_new ();\r
+  if (CertCtx == NULL) {\r
+    goto _Exit;\r
+  }\r
+  if (!X509_STORE_CTX_init (CertCtx, CertStore, X509Cert, NULL)) {\r
     goto _Exit;\r
   }\r
 \r
   //\r
   // X509 Certificate Verification.\r
   //\r
-  Status = (BOOLEAN) X509_verify_cert (&CertCtx);\r
-  X509_STORE_CTX_cleanup (&CertCtx);\r
+  Status = (BOOLEAN) X509_verify_cert (CertCtx);\r
+  X509_STORE_CTX_cleanup (CertCtx);\r
 \r
 _Exit:\r
   //\r
@@ -491,7 +503,9 @@ _Exit:
   if (CertStore != NULL) {\r
     X509_STORE_free (CertStore);\r
   }\r
-  \r
+\r
+  X509_STORE_CTX_free (CertCtx);\r
+\r
   return Status;\r
 }\r
 \r
@@ -568,6 +582,6 @@ X509GetTBSCert (
   }\r
 \r
   *TBSCertSize = Length + (Temp - *TBSCert);\r
-  \r
+\r
   return TRUE;\r
 }\r