]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Application/Cryptest/RsaVerify2.c
Add new interfaces to support PKCS7#7 signed data and authenticode signature. Update...
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / RsaVerify2.c
index adac99a9d7182c4d92fb41c667281b2b2d114ec1..98b5aad9009808fd74d3d932889731bcbf4bd5e7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file  \r
   Application for RSA Key Retrieving (from PEM and X509) & Signature Validation.\r
 \r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2011, 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
@@ -187,6 +187,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 MsgHash[] = {
   0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09\r
   };\r
 \r
+//\r
+// Payload for PKCS#7 Signing & Verification Validation.\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Payload = "Payload Data for PKCS#7 Signing";\r
+\r
 /**\r
   Validate UEFI-OpenSSL RSA Key Retrieving & Signature Interfaces.\r
 \r
@@ -214,7 +219,7 @@ ValidateCryptRsa2 (
   //\r
   Print (L"\n- Retrieve RSA Private Key for PEM ...");\r
   Status = RsaGetPrivateKeyFromPem (TestKeyPem, sizeof (TestKeyPem), PemPass, &RsaPrivKey);\r
-  if (Status == FALSE) {\r
+  if (!Status) {\r
     Print (L"[Fail]");\r
     return EFI_ABORTED;\r
   } else {\r
@@ -227,7 +232,7 @@ ValidateCryptRsa2 (
   Print (L"\n- Retrieve RSA Public Key from X509 ... ");\r
   RsaPubKey = NULL;\r
   Status    = RsaGetPublicKeyFromX509 (TestCert, sizeof (TestCert), &RsaPubKey);\r
-  if (Status == FALSE) {\r
+  if (!Status) {\r
     Print (L"[Fail]");\r
     return EFI_ABORTED;\r
   } else {\r
@@ -303,3 +308,88 @@ ValidateCryptRsa2 (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  Validate UEFI-OpenSSL PKCS#7 Signing & Verification Interfaces.\r
+\r
+  @retval  EFI_SUCCESS  Validation succeeded.\r
+  @retval  EFI_ABORTED  Validation failed.\r
+\r
+**/\r
+EFI_STATUS\r
+ValidateCryptPkcs7 (\r
+  VOID\r
+  )\r
+{\r
+  BOOLEAN  Status;\r
+  UINT8    *P7SignedData;\r
+  UINTN    P7SignedDataSize;\r
+  UINT8    *SignCert;\r
+\r
+  P7SignedData = NULL;\r
+  SignCert     = NULL;\r
+\r
+  Print (L"\nUEFI-OpenSSL PKCS#7 Signing & Verification Testing: ");\r
+\r
+  Print (L"\n- Create PKCS#7 signedData ...");\r
+\r
+  //\r
+  // Construct Signer Certificate from RAW data.\r
+  //\r
+  Status = X509ConstructCertificate (TestCert, sizeof (TestCert), (UINT8 **) &SignCert);\r
+  if (!Status || SignCert == NULL) {\r
+    Print (L"[Fail]");\r
+    goto _Exit;\r
+  } else {\r
+    Print (L"[Pass]");\r
+  }\r
+\r
+  //\r
+  // Create PKCS#7 signedData on Payload. \r
+  // Note: Caller should release P7SignedData manually.\r
+  //\r
+  Status = Pkcs7Sign (\r
+             TestKeyPem,\r
+             sizeof (TestKeyPem),\r
+             (CONST UINT8 *) PemPass,\r
+             (UINT8 *) Payload,\r
+             AsciiStrLen (Payload),\r
+             SignCert,\r
+             NULL,\r
+             &P7SignedData,\r
+             &P7SignedDataSize\r
+             );\r
+  if (!Status || P7SignedDataSize == 0) {\r
+    Print (L"[Fail]");\r
+    goto _Exit;\r
+  } else {\r
+    Print (L"[Pass]");\r
+  }\r
+\r
+  Print (L"\n- Verify PKCS#7 signedData ...");\r
+\r
+  Status = Pkcs7Verify (\r
+             P7SignedData,\r
+             P7SignedDataSize,\r
+             TestCACert,\r
+             sizeof (TestCACert),\r
+             (UINT8 *) Payload,\r
+             AsciiStrLen (Payload)\r
+             );\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+  } else {\r
+    Print (L"[Pass]");\r
+  }\r
+\r
+_Exit:\r
+  if (P7SignedData != NULL) {\r
+    FreePool (P7SignedData);\r
+  }\r
+  if (SignCert != NULL) {\r
+    X509Free (SignCert);\r
+  }\r
+\r
+  Print (L"\n");\r
+  return EFI_SUCCESS;\r
+}\r