]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add new interfaces to support PKCS7#7 signed data and authenticode signature. Update...
authortye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 16 Aug 2011 06:46:52 +0000 (06:46 +0000)
committertye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 16 Aug 2011 06:46:52 +0000 (06:46 +0000)
Signed-off-by: tye1
Reviewed-by: hhuan13
Reviewed-by: qlong
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12142 6f19259b-4bc3-4df7-8a09-765794883524

18 files changed:
CryptoPkg/Application/Cryptest/AuthenticodeVerify.c
CryptoPkg/Application/Cryptest/Cryptest.c
CryptoPkg/Application/Cryptest/Cryptest.h
CryptoPkg/Application/Cryptest/RsaVerify2.c
CryptoPkg/CryptoPkg.dsc
CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg/Include/OpenSslSupport.h
CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c [new file with mode: 0644]
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptRsa.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c
CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
CryptoPkg/Library/BaseCryptLib/SysCall/RealTimeClock.c
CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c

index 7a4e29447ec716e501d124c9359984e11c893bb0..bc22aa0cde05ffbabc4417e64c979d0db0b3ed2a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file  \r
   Sample Implementation for Microsoft Authenticode Verification.\r
 \r
 /** @file  \r
   Sample Implementation for Microsoft Authenticode Verification.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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
@@ -15,50 +15,28 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Cryptest.h"\r
 \r
 //\r
 #include "Cryptest.h"\r
 \r
 //\r
-// DER encoding of SpcIndirectDataContent (Authenticode-specific Structure)\r
-// Last 20 bytes data should be the SHA-1 digest value of PE/COFF image\r
+// Sample PE/COFF Image Hash Value (Digested by SHA-1).\r
+// This value should be calculated following MSFT's Authenticode Specification\r
 //\r
 //\r
-GLOBAL_REMOVE_IF_UNREFERENCED UINT8 SpcIndirectDataContentwithSha1[] = {\r
-  0x30, 0x33, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x0F, 0x30, 0x25,\r
-  0x03, 0x01, 0x00, 0xA0, 0x20, 0xA2, 0x1E, 0x80, 0x1C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00, \r
-  0x4F, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, \r
-  0x3E, 0x00, 0x3E, 0x00, 0x3E, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, \r
-  0x05, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 PeSha1Hash[] = {\r
+  0x44, 0xFD, 0x4F, 0xA9, 0x17, 0xEE, 0xAC, 0xCF, 0x1F, 0x0B, 0xE3, 0xA1, 0x4D, 0x5B, 0xA6, 0x61, \r
+  0x82, 0x97, 0xC4, 0xB6\r
   };\r
 \r
 //\r
   };\r
 \r
 //\r
-// DER encoding of SpcIndirectDataContent (Authenticode-specific Structure)\r
-// Last 16 bytes data should be the MD5 digest value of PE/COFF image\r
-// NOTE: Authenticode also support MD5 digest. Disable MD5 support here since MD5\r
-//       has been marked as "Deprecated, do not use".\r
+// Sample PE/COFF Image Hash Value (Digested by SHA-256).\r
 //\r
 //\r
-#if 0\r
-GLOBAL_REMOVE_IF_UNREFERENCED UINT8 SpcIndirectDataContentwithMd5[] = {\r
-  0x30, 0x33, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x0F, 0x30, 0x25,\r
-  0x03, 0x01, 0x00, 0xA0, 0x20, 0xA2, 0x1E, 0x80, 0x1C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00,\r
-  0x4F, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x74, 0x00, 0x65, 0x00,\r
-  0x3E, 0x00, 0x3E, 0x00, 0x3E, 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7,\r
-  0x0D, 0x02, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
-  0x00, 0x00, 0x00, 0x00\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 PeSha256Hash[] = {\r
+  0x61, 0x82, 0xB7, 0xF8, 0x8C, 0xFF, 0xC2, 0xEB, 0x79, 0x6E, 0x9D, 0xA9, 0xDD, 0x39, 0x52, 0xDD,\r
+  0x36, 0xDD, 0xF1, 0x43, 0x27, 0x58, 0x8C, 0xA7, 0xCC, 0xAE, 0xDE, 0xDD, 0x3C, 0x02, 0x12, 0x49\r
   };\r
   };\r
-#endif\r
 \r
 //\r
 \r
 //\r
-// Sample PE/COFF Image Hash Value. \r
-// This value should be calculated following MSFT's Authenticode Specification\r
-//\r
-GLOBAL_REMOVE_IF_UNREFERENCED UINT8 PeHash[] = {\r
-  0x44, 0xFD, 0x4F, 0xA9, 0x17, 0xEE, 0xAC, 0xCF, 0x1F, 0x0B, 0xE3, 0xA1, 0x4D, 0x5B, 0xA6, 0x61, \r
-  0x82, 0x97, 0xC4, 0xB6\r
-  };\r
-\r
-//\r
-// Sample Authenticode Data (from MSFT Win7 BootLoader: bootmgfw.efi)\r
+// Sample Authenticode Data with SHA-1 hash algorithm.\r
 // This data should be retrieved from signed PE/COFF image according to SECURITY \r
 // This data should be retrieved from signed PE/COFF image according to SECURITY \r
-// directory in PE/COFF Header\r
+// directory in PE/COFF Header.\r
 //\r
 //\r
-GLOBAL_REMOVE_IF_UNREFERENCED UINT8 Authenticode[] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 AuthenticodeWithSha1[] = {\r
   0x30, 0x82, 0x1C, 0x43, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0,\r
   0x82, 0x1C, 0x34, 0x30, 0x82, 0x1C, 0x30, 0x02, 0x01, 0x01, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x05,\r
   0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x30, 0x68, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01,\r
   0x30, 0x82, 0x1C, 0x43, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0,\r
   0x82, 0x1C, 0x34, 0x30, 0x82, 0x1C, 0x30, 0x02, 0x01, 0x01, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x05,\r
   0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x30, 0x68, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01,\r
@@ -515,11 +493,257 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINT8 Authenticode[] = {
   };\r
 \r
 //\r
   };\r
 \r
 //\r
-// Sample MSFT's root certificate for code signing. \r
+// Sample Authenticode Data with SHA-256 hash algorithm.\r
+// This data should be retrieved from signed PE/COFF image according to SECURITY \r
+// directory in PE/COFF Header.\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 AuthenticodeWithSha256[] = {\r
+  0x30, 0x82, 0x0e, 0xd1, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0,\r
+  0x82, 0x0e, 0xc2, 0x30, 0x82, 0x0e, 0xbe, 0x02, 0x01, 0x01, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x09,\r
+  0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x30, 0x5c, 0x06, 0x0a, 0x2b,\r
+  0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0xa0, 0x4e, 0x30, 0x4c, 0x30, 0x17, 0x06,\r
+  0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x0f, 0x30, 0x09, 0x03, 0x01, 0x00,\r
+  0xa0, 0x04, 0xa2, 0x02, 0x80, 0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,\r
+  0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20, 0x61, 0x82, 0xb7, 0xf8, 0x8c, 0xff, 0xc2,\r
+  0xeb, 0x79, 0x6e, 0x9d, 0xa9, 0xdd, 0x39, 0x52, 0xdd, 0x36, 0xdd, 0xf1, 0x43, 0x27, 0x58, 0x8c,\r
+  0xa7, 0xcc, 0xae, 0xde, 0xdd, 0x3c, 0x02, 0x12, 0x49, 0xa0, 0x82, 0x0c, 0x0a, 0x30, 0x82, 0x05,\r
+  0xe5, 0x30, 0x82, 0x03, 0xcd, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0a, 0x61, 0x03, 0x5f, 0x09,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,\r
+  0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x90, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,\r
+  0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a,\r
+  0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03,\r
+  0x55, 0x04, 0x07, 0x13, 0x07, 0x52, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64, 0x31, 0x1e, 0x30, 0x1c,\r
+  0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x15, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74,\r
+  0x20, 0x43, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x31, 0x3a, 0x30, 0x38,\r
+  0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x31, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74,\r
+  0x20, 0x54, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x65,\r
+  0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72,\r
+  0x69, 0x74, 0x79, 0x20, 0x32, 0x30, 0x31, 0x30, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x30, 0x30, 0x36,\r
+  0x32, 0x31, 0x32, 0x32, 0x35, 0x35, 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x36, 0x32,\r
+  0x31, 0x32, 0x33, 0x30, 0x35, 0x30, 0x31, 0x5a, 0x30, 0x81, 0x81, 0x31, 0x13, 0x30, 0x11, 0x06,\r
+  0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x03, 0x63, 0x6f, 0x6d,\r
+  0x31, 0x19, 0x30, 0x17, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19,\r
+  0x16, 0x09, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x31, 0x14, 0x30, 0x12, 0x06,\r
+  0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x04, 0x63, 0x6f, 0x72,\r
+  0x70, 0x31, 0x17, 0x30, 0x15, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01,\r
+  0x19, 0x16, 0x07, 0x72, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03,\r
+  0x55, 0x04, 0x03, 0x13, 0x17, 0x4d, 0x53, 0x49, 0x54, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43,\r
+  0x6f, 0x64, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x43, 0x41, 0x20, 0x33, 0x30, 0x82, 0x01, 0x22,\r
+  0x30, 0x0d, 0x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x82, 0x37, 0x14, 0x02, 0x04, 0x0c, 0x1e, 0x0a, 0x00, 0x53, 0x00, 0x75,\r
+  0x00, 0x62, 0x00, 0x43, 0x00, 0x41, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03,\r
+  0x02, 0x01, 0x86, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, 0x30,\r
+  0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,\r
+  0x30, 0x16, 0x80, 0x14, 0xa3, 0x01, 0x04, 0x7e, 0x30, 0x88, 0x33, 0xeb, 0xb9, 0x31, 0x9c, 0xca,\r
+  0xeb, 0x85, 0x76, 0x67, 0xfc, 0x65, 0xb4, 0xd1, 0x30, 0x59, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04,\r
+  0x52, 0x30, 0x50, 0x30, 0x4e, 0xa0, 0x4c, 0xa0, 0x4a, 0x86, 0x48, 0x68, 0x74, 0x74, 0x70, 0x3a,\r
+  0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e,\r
+  0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6b, 0x69, 0x2f, 0x63, 0x72, 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x64,\r
+  0x75, 0x63, 0x74, 0x73, 0x2f, 0x4d, 0x69, 0x63, 0x54, 0x65, 0x73, 0x52, 0x6f, 0x6f, 0x43, 0x65,\r
+  0x72, 0x41, 0x75, 0x74, 0x5f, 0x32, 0x30, 0x31, 0x30, 0x2d, 0x30, 0x36, 0x2d, 0x31, 0x37, 0x2e,\r
+  0x63, 0x72, 0x6c, 0x30, 0x5d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04,\r
+  0x51, 0x30, 0x4f, 0x30, 0x4d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86,\r
+  0x41, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x6d, 0x69, 0x63, 0x72,\r
+  0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6b, 0x69, 0x2f, 0x63, 0x65,\r
+  0x72, 0x74, 0x73, 0x2f, 0x4d, 0x69, 0x63, 0x54, 0x65, 0x73, 0x52, 0x6f, 0x6f, 0x43, 0x65, 0x72,\r
+  0x41, 0x75, 0x74, 0x5f, 0x32, 0x30, 0x31, 0x30, 0x2d, 0x30, 0x36, 0x2d, 0x31, 0x37, 0x2e, 0x63,\r
+  0x72, 0x74, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,\r
+  0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x91, 0x2d, 0x11, 0x36, 0xd1, 0x2c, 0x5e, 0x21, 0x77, 0x62,\r
+  0x1a, 0xa1, 0xcf, 0x9a, 0x7e, 0x62, 0x2d, 0xc9, 0x90, 0xb9, 0x0e, 0x3d, 0x71, 0x0d, 0xa0, 0x4a,\r
+  0x48, 0xad, 0xe1, 0xd6, 0xb0, 0x73, 0x4a, 0x51, 0x4b, 0x4c, 0xb2, 0x6b, 0x88, 0x0a, 0x5a, 0xb7,\r
+  0xe9, 0x55, 0x67, 0x43, 0x8b, 0xf1, 0x9d, 0xcc, 0x52, 0x03, 0xaf, 0xac, 0x85, 0xe9, 0xd3, 0x75,\r
+  0xce, 0xe5, 0x6f, 0x8b, 0x3c, 0x80, 0x81, 0xab, 0xd1, 0xd1, 0x73, 0x0d, 0x6b, 0xb0, 0x51, 0xb8,\r
+  0xa2, 0x5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 0xa7, 0x0d, 0x8d, 0x76, 0x30, 0xc6, 0x48, 0xce, 0xdd, 0x8d, 0xfa, 0xbe, 0xda, 0xb4,\r
+  0xeb, 0x3d, 0xd8, 0x0c, 0x3b, 0x15, 0x9a, 0xd1, 0x83, 0x85, 0xe5, 0xe3, 0x92, 0xaa, 0x3b, 0xad,\r
+  0x34, 0x0c, 0x39, 0xf1, 0x7f, 0x75, 0xae, 0xe8, 0x70, 0xb0, 0xfd, 0xf2, 0x8e, 0x29, 0xda, 0xdc,\r
+  0x09, 0x4f, 0x8a, 0x7b, 0x63, 0xbe, 0x1e, 0x8a, 0xc3, 0x58, 0xd1, 0x03, 0xbe, 0x37, 0xe9, 0xed,\r
+  0x32, 0x26, 0xa8, 0x0c, 0xfe, 0xed, 0x12, 0xa7, 0x63, 0x04, 0xb3, 0x92, 0x97, 0xd9, 0x46, 0xa3,\r
+  0x33, 0x33, 0x9c, 0x5b, 0xbc, 0x54, 0x30, 0x82, 0x06, 0x1d, 0x30, 0x82, 0x05, 0x05, 0xa0, 0x03,\r
+  0x02, 0x01, 0x02, 0x02, 0x0a, 0x4e, 0x30, 0xa5, 0xbb, 0x00, 0x00, 0x00, 0x12, 0x7b, 0xf2, 0x30,\r
+  0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81,\r
+  0x81, 0x31, 0x13, 0x30, 0x11, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01,\r
+  0x19, 0x16, 0x03, 0x63, 0x6f, 0x6d, 0x31, 0x19, 0x30, 0x17, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89,\r
+  0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x09, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66,\r
+  0x74, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01,\r
+  0x19, 0x16, 0x04, 0x63, 0x6f, 0x72, 0x70, 0x31, 0x17, 0x30, 0x15, 0x06, 0x0a, 0x09, 0x92, 0x26,\r
+  0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x07, 0x72, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64,\r
+  0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x17, 0x4d, 0x53, 0x49, 0x54, 0x20,\r
+  0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x43, 0x41,\r
+  0x20, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x31, 0x30, 0x34, 0x32, 0x31, 0x30, 0x33, 0x33, 0x33,\r
+  0x34, 0x39, 0x5a, 0x17, 0x0d, 0x31, 0x33, 0x30, 0x34, 0x32, 0x30, 0x30, 0x33, 0x33, 0x33, 0x34,\r
+  0x39, 0x5a, 0x30, 0x70, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,\r
+  0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x57, 0x61, 0x73, 0x68,\r
+  0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13,\r
+  0x07, 0x52, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04,\r
+  0x0a, 0x13, 0x15, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x43, 0x6f, 0x72,\r
+  0x70, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04,\r
+  0x03, 0x13, 0x11, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x57, 0x69, 0x6e,\r
+  0x64, 0x6f, 0x77, 0x73, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,\r
+  0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a,\r
+  0x02, 0x82, 0x01, 0x01, 0x00, 0xca, 0x9f, 0xcb, 0x8c, 0x5e, 0x61, 0x19, 0xb5, 0x37, 0x72, 0xd1,\r
+  0xe2, 0x88, 0x1f, 0x37, 0x56, 0xce, 0xa8, 0x88, 0x05, 0x3e, 0xe8, 0xa6, 0x8d, 0xfd, 0x0b, 0x30,\r
+  0x63, 0x54, 0x89, 0x1d, 0xda, 0x11, 0x70, 0x5a, 0x06, 0x00, 0x86, 0xd7, 0x7f, 0xe6, 0x21, 0x70,\r
+  0x41, 0x81, 0x26, 0x4b, 0x6e, 0xc7, 0x02, 0xe2, 0xbf, 0x61, 0x45, 0x04, 0x2f, 0x45, 0xbc, 0xd2,\r
+  0x0d, 0xf6, 0xac, 0xda, 0x91, 0x6d, 0xc6, 0x60, 0xad, 0xb3, 0x0b, 0x32, 0xe5, 0x13, 0x95, 0x96,\r
+  0x02, 0x4e, 0x10, 0xad, 0x2e, 0x6c, 0xb0, 0xc7, 0x65, 0x6d, 0xea, 0x89, 0x91, 0x67, 0x73, 0x5d,\r
+  0x05, 0x12, 0x9f, 0x95, 0x74, 0x6a, 0x6d, 0xb0, 0x6a, 0xd8, 0x94, 0x9b, 0xb0, 0x70, 0x79, 0xb0,\r
+  0x85, 0x42, 0xe7, 0xd7, 0x19, 0xc4, 0x33, 0xfd, 0xac, 0x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, 0x15, 0x08, 0x83, 0xcf,\r
+  0x89, 0x4d, 0xad, 0xf2, 0x02, 0x85, 0xa1, 0x9f, 0x0c, 0x82, 0xfa, 0xca, 0x7d, 0x81, 0xe1, 0xfb,\r
+  0x74, 0x81, 0x4f, 0x84, 0x9a, 0xf1, 0x69, 0x85, 0xa1, 0xad, 0x1d, 0x02, 0x01, 0x64, 0x02, 0x01,\r
+  0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x29,\r
+  0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x0a, 0x04, 0x1c, 0x30, 0x1a, 0x30,\r
+  0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x03, 0x06, 0x30, 0x0a, 0x06,\r
+  0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x03, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x25,\r
+  0x04, 0x18, 0x30, 0x16, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x03, 0x06,\r
+  0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x03, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d,\r
+  0x0e, 0x04, 0x16, 0x04, 0x14, 0xc9, 0x5a, 0xb3, 0x11, 0x02, 0x66, 0x71, 0x8c, 0x5b, 0x06, 0x80,\r
+  0x8a, 0x6d, 0x4f, 0x5b, 0xf2, 0xb5, 0x67, 0x45, 0xb5, 0x30, 0x30, 0x06, 0x03, 0x55, 0x1d, 0x11,\r
+  0x04, 0x29, 0x30, 0x27, 0xa0, 0x25, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x14,\r
+  0x02, 0x03, 0xa0, 0x17, 0x0c, 0x15, 0x77, 0x69, 0x6e, 0x63, 0x62, 0x6c, 0x64, 0x40, 0x6d, 0x69,\r
+  0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1f, 0x06, 0x03, 0x55,\r
+  0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x4e, 0xfe, 0x61, 0x39, 0x6f, 0xca, 0xc5, 0x64,\r
+  0xe0, 0x20, 0xb6, 0xda, 0xc1, 0xb9, 0x52, 0x0e, 0xca, 0xdf, 0x8e, 0xfe, 0x30, 0x81, 0xe8, 0x06,\r
+  0x03, 0x55, 0x1d, 0x1f, 0x04, 0x81, 0xe0, 0x30, 0x81, 0xdd, 0x30, 0x81, 0xda, 0xa0, 0x81, 0xd7,\r
+  0xa0, 0x81, 0xd4, 0x86, 0x36, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x6f, 0x72, 0x70,\r
+  0x70, 0x6b, 0x69, 0x2f, 0x63, 0x72, 0x6c, 0x2f, 0x4d, 0x53, 0x49, 0x54, 0x25, 0x32, 0x30, 0x54,\r
+  0x65, 0x73, 0x74, 0x25, 0x32, 0x30, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x25, 0x32,\r
+  0x30, 0x43, 0x41, 0x25, 0x32, 0x30, 0x33, 0x2e, 0x63, 0x72, 0x6c, 0x86, 0x4d, 0x68, 0x74, 0x74,\r
+  0x70, 0x3a, 0x2f, 0x2f, 0x6d, 0x73, 0x63, 0x72, 0x6c, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73,\r
+  0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6b, 0x69, 0x2f, 0x6d, 0x73, 0x63, 0x6f,\r
+  0x72, 0x70, 0x2f, 0x63, 0x72, 0x6c, 0x2f, 0x4d, 0x53, 0x49, 0x54, 0x25, 0x32, 0x30, 0x54, 0x65,\r
+  0x73, 0x74, 0x25, 0x32, 0x30, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x25, 0x32, 0x30,\r
+  0x43, 0x41, 0x25, 0x32, 0x30, 0x33, 0x2e, 0x63, 0x72, 0x6c, 0x86, 0x4b, 0x68, 0x74, 0x74, 0x70,\r
+  0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74,\r
+  0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6b, 0x69, 0x2f, 0x6d, 0x73, 0x63, 0x6f, 0x72, 0x70, 0x2f,\r
+  0x63, 0x72, 0x6c, 0x2f, 0x4d, 0x53, 0x49, 0x54, 0x25, 0x32, 0x30, 0x54, 0x65, 0x73, 0x74, 0x25,\r
+  0x32, 0x30, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x25, 0x32, 0x30, 0x43, 0x41, 0x25,\r
+  0x32, 0x30, 0x33, 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x81, 0xa9, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,\r
+  0x05, 0x07, 0x01, 0x01, 0x04, 0x81, 0x9c, 0x30, 0x81, 0x99, 0x30, 0x42, 0x06, 0x08, 0x2b, 0x06,\r
+  0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x36, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63,\r
+  0x6f, 0x72, 0x70, 0x70, 0x6b, 0x69, 0x2f, 0x61, 0x69, 0x61, 0x2f, 0x4d, 0x53, 0x49, 0x54, 0x25,\r
+  0x32, 0x30, 0x54, 0x65, 0x73, 0x74, 0x25, 0x32, 0x30, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x69, 0x67,\r
+  0x6e, 0x25, 0x32, 0x30, 0x43, 0x41, 0x25, 0x32, 0x30, 0x33, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x53,\r
+  0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x47, 0x68, 0x74, 0x74, 0x70,\r
+  0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74,\r
+  0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6b, 0x69, 0x2f, 0x6d, 0x73, 0x63, 0x6f, 0x72, 0x70, 0x2f,\r
+  0x4d, 0x53, 0x49, 0x54, 0x25, 0x32, 0x30, 0x54, 0x65, 0x73, 0x74, 0x25, 0x32, 0x30, 0x43, 0x6f,\r
+  0x64, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x25, 0x32, 0x30, 0x43, 0x41, 0x25, 0x32, 0x30, 0x33, 0x2e,\r
+  0x63, 0x72, 0x74, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,\r
+  0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x97, 0x6d, 0x52, 0x46, 0x65, 0x08, 0x60, 0x01, 0x12,\r
+  0x7a, 0x26, 0xaa, 0xd9, 0xc3, 0x15, 0xec, 0xc6, 0xae, 0x0b, 0x75, 0xe4, 0xd5, 0xe0, 0x31, 0xf6,\r
+  0xda, 0xc0, 0xb1, 0x1b, 0x7b, 0x8a, 0x07, 0xda, 0x2f, 0x82, 0x4a, 0x21, 0x89, 0xe6, 0x61, 0x97,\r
+  0xe4, 0x3a, 0x38, 0xd8, 0x0a, 0x26, 0x4e, 0x83, 0x54, 0xbf, 0x32, 0xe3, 0x64, 0x36, 0x61, 0x40,\r
+  0x75, 0x55, 0xf1, 0xaa, 0x34, 0xb2, 0xd3, 0x45, 0x8d, 0x79, 0x9a, 0x93, 0x0b, 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b0, 0x5b, 0xfd, 0xd9,\r
+  0xfa, 0x08, 0x17, 0xc8, 0x3c, 0x61, 0xf1, 0x31, 0x82, 0x02, 0x3a, 0x30, 0x82, 0x02, 0x36, 0x02,\r
+  0x01, 0x01, 0x30, 0x81, 0x90, 0x30, 0x81, 0x81, 0x31, 0x13, 0x30, 0x11, 0x06, 0x0a, 0x09, 0x92,\r
+  0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x03, 0x63, 0x6f, 0x6d, 0x31, 0x19, 0x30,\r
+  0x17, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x09, 0x6d,\r
+  0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x09, 0x92,\r
+  0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x04, 0x63, 0x6f, 0x72, 0x70, 0x31, 0x17,\r
+  0x30, 0x15, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x07,\r
+  0x72, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x03,\r
+  0x13, 0x17, 0x4d, 0x53, 0x49, 0x54, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x6f, 0x64, 0x65,\r
+  0x53, 0x69, 0x67, 0x6e, 0x20, 0x43, 0x41, 0x20, 0x33, 0x02, 0x0a, 0x4e, 0x30, 0xa5, 0xbb, 0x00,\r
+  0x00, 0x00, 0x12, 0x7b, 0xf2, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04,\r
+  0x02, 0x01, 0x05, 0x00, 0xa0, 0x7c, 0x30, 0x10, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,\r
+  0x37, 0x02, 0x01, 0x0c, 0x31, 0x02, 0x30, 0x00, 0x30, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,\r
+  0xf7, 0x0d, 0x01, 0x09, 0x03, 0x31, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37,\r
+  0x02, 0x01, 0x04, 0x30, 0x1c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01,\r
+  0x0b, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01,\r
+  0x15, 0x30, 0x2f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04, 0x31, 0x22,\r
+  0x04, 0x20, 0x25, 0x60, 0x6e, 0xc8, 0x66, 0x72, 0x73, 0xb0, 0x71, 0x7b, 0x82, 0x09, 0x8c, 0x27,\r
+  0xe8, 0xb1, 0x4a, 0x36, 0x1c, 0x81, 0x36, 0xb4, 0x1b, 0x44, 0xdf, 0x09, 0x82, 0x8b, 0xf9, 0xb6,\r
+  0x1c, 0x65, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,\r
+  0x00, 0x04, 0x82, 0x01, 0x00, 0x01, 0xb7, 0x8e, 0x46, 0x9b, 0xb4, 0x18, 0xcd, 0xf6, 0x39, 0x8f,\r
+  0x82, 0x79, 0xbc, 0x96, 0x55, 0x7e, 0xd7, 0x84, 0x8f, 0x18, 0x37, 0x48, 0x4e, 0x8f, 0x25, 0x6f,\r
+  0x1a, 0x6c, 0x60, 0xe9, 0xc1, 0x5f, 0x65, 0xec, 0xb0, 0x4b, 0x35, 0x98, 0x8a, 0x31, 0x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63,\r
+  0x22, 0xb6, 0x17, 0x3f, 0x4f, 0x33, 0xed, 0xa6, 0xd9, 0x0f, 0x74, 0xfa, 0x97, 0x8d, 0x98, 0x55,\r
+  0x42, 0x14, 0x76, 0xd4, 0x89, 0x07, 0xf2, 0x30, 0x5a, 0x27, 0x96, 0x1b, 0x92, 0x70, 0x5a, 0x83,\r
+  0x89, 0x0f, 0xdb, 0x47, 0x7a, 0x00, 0x00, 0x00, 0x0a\r
+  };\r
+\r
+//\r
+// Sample root certificate for code signing. \r
 // A trusted certificate with self-signing, will be used to construct the certificate chains for \r
 // authority checking.\r
 //\r
 // A trusted certificate with self-signing, will be used to construct the certificate chains for \r
 // authority checking.\r
 //\r
-GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MsftRootCert[] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 TestRootCert1[] = {\r
   0x30, 0x82, 0x05, 0x99, 0x30, 0x82, 0x03, 0x81, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x79,\r
   0xAD, 0x16, 0xA1, 0x4A, 0xA0, 0xA5, 0xAD, 0x4C, 0x73, 0x58, 0xF4, 0x07, 0x13, 0x2E, 0x65, 0x30,\r
   0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x5F,\r
   0x30, 0x82, 0x05, 0x99, 0x30, 0x82, 0x03, 0x81, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x79,\r
   0xAD, 0x16, 0xA1, 0x4A, 0xA0, 0xA5, 0xAD, 0x4C, 0x73, 0x58, 0xF4, 0x07, 0x13, 0x2E, 0x65, 0x30,\r
   0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x5F,\r
@@ -612,49 +836,194 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MsftRootCert[] = {
   0x6B, 0x9D, 0x4A, 0xFD, 0xD1, 0xA1, 0x9D, 0x99, 0x43, 0x77, 0x3F, 0xB0, 0xDA\r
 };\r
 \r
   0x6B, 0x9D, 0x4A, 0xFD, 0xD1, 0xA1, 0x9D, 0x99, 0x43, 0x77, 0x3F, 0xB0, 0xDA\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 TestRootCert2[] = {\r
+  0x30, 0x82, 0x05, 0xfd, 0x30, 0x82, 0x03, 0xe5, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x74,\r
+  0x45, 0xc8, 0x78, 0x4e, 0x0c, 0xc9, 0x96, 0x4a, 0xb4, 0x2f, 0xbc, 0xda, 0x29, 0xe1, 0xbc, 0x30,\r
+  0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81,\r
+  0x90, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13,\r
+  0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,\r
+  0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x52, 0x65,\r
+  0x64, 0x6d, 0x6f, 0x6e, 0x64, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x15,\r
+  0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x43, 0x6f, 0x72, 0x70, 0x6f, 0x72,\r
+  0x61, 0x74, 0x69, 0x6f, 0x6e, 0x31, 0x3a, 0x30, 0x38, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x31,\r
+  0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x54, 0x65, 0x73, 0x74, 0x69, 0x6e,\r
+  0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61,\r
+  0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x20, 0x32, 0x30, 0x31,\r
+  0x30, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x30, 0x30, 0x36, 0x31, 0x37, 0x32, 0x30, 0x35, 0x38, 0x30,\r
+  0x32, 0x5a, 0x17, 0x0d, 0x33, 0x35, 0x30, 0x36, 0x31, 0x37, 0x32, 0x31, 0x30, 0x34, 0x31, 0x31,\r
+  0x5a, 0x30, 0x81, 0x90, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,\r
+  0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x57, 0x61, 0x73, 0x68,\r
+  0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13,\r
+  0x07, 0x52, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04,\r
+  0x0a, 0x13, 0x15, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x43, 0x6f, 0x72,\r
+  0x70, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x31, 0x3a, 0x30, 0x38, 0x06, 0x03, 0x55, 0x04,\r
+  0x03, 0x13, 0x31, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x54, 0x65, 0x73,\r
+  0x74, 0x69, 0x6e, 0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66,\r
+  0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x20,\r
+  0x32, 0x30, 0x31, 0x30, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,\r
+  0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a,\r
+  0x02, 0x82, 0x02, 0x01, 0x00, 0x95, 0xe3, 0xa8, 0xc1, 0xb9, 0x9c, 0x26, 0x54, 0xb0, 0x99, 0xef,\r
+  0x26, 0x1f, 0xac, 0x1e, 0xc7, 0x30, 0x80, 0xbb, 0xf5, 0x3f, 0xf2, 0xe4, 0xbb, 0xf8, 0xfe, 0x06,\r
+  0x6a, 0x0a, 0xa6, 0x88, 0xbc, 0xb4, 0x8c, 0x45, 0xe0, 0x70, 0x55, 0x19, 0x88, 0xb4, 0x05, 0xcb,\r
+  0xb5, 0xc1, 0xa1, 0xfa, 0xd4, 0x7c, 0xc2, 0x42, 0x53, 0x07, 0x9c, 0x54, 0x56, 0xa8, 0x97, 0xe0,\r
+  0x94, 0x69, 0xbe, 0x13, 0x24, 0xef, 0xe5, 0x8a, 0x29, 0x9c, 0xa6, 0xd0, 0x2b, 0x2f, 0x8a, 0xa6,\r
+  0xe8, 0x79, 0x44, 0x2e, 0x8b, 0xea, 0xc9, 0xbe, 0xb8, 0x54, 0x86, 0x53, 0xbe, 0x07, 0x24, 0x34,\r
+  0x54, 0x15, 0x22, 0x20, 0x01, 0x7b, 0x8a, 0x46, 0xfb, 0xd2, 0x91, 0x07, 0x95, 0x09, 0xb0, 0x56,\r
+  0x11, 0xcc, 0x76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 0x62, 0x0b, 0xe8, 0x53, 0xb6, 0x4e, 0xe3, 0xe8, 0x2a, 0x73, 0x59, 0xe2,\r
+  0x13, 0xb8, 0xf8, 0x5a, 0x7e, 0xc6, 0xe2, 0x0a, 0xdd, 0x4a, 0x43, 0xcc, 0xc3, 0x77, 0x3b, 0x7a,\r
+  0x31, 0x04, 0x0a, 0xc1, 0x84, 0x96, 0x3a, 0x63, 0x6e, 0x1a, 0x3e, 0x0a, 0x0c, 0x25, 0xb8, 0x7e,\r
+  0xb5, 0x52, 0x0c, 0xb9, 0xab, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x51, 0x30, 0x4f, 0x30, 0x0b,\r
+  0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x0f, 0x06, 0x03, 0x55,\r
+  0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03,\r
+  0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa3, 0x01, 0x04, 0x7e, 0x30, 0x88, 0x33, 0xeb, 0xb9,\r
+  0x31, 0x9c, 0xca, 0xeb, 0x85, 0x76, 0x67, 0xfc, 0x65, 0xb4, 0xd1, 0x30, 0x10, 0x06, 0x09, 0x2b,\r
+  0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x01, 0x04, 0x03, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06,\r
+  0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01,\r
+  0x00, 0x49, 0x8b, 0xc1, 0xfc, 0x4f, 0xe8, 0xe4, 0x2d, 0x67, 0x92, 0x9a, 0x76, 0x05, 0xba, 0xd1,\r
+  0xbc, 0x98, 0xe4, 0x2b, 0xba, 0x1f, 0x66, 0x5f, 0x66, 0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c2, 0xcd, 0xc8, 0xbe, 0xf5, 0x67, 0xf7, 0xae,\r
+  0x05, 0xce, 0x16, 0xfe, 0x90, 0xc9, 0x4a, 0x98, 0x1b, 0x24, 0x69, 0x78, 0x90, 0xf9, 0x34, 0x8e,\r
+  0x37, 0xe8, 0x6e, 0x1d, 0xdc, 0xcf, 0x4f, 0xe7, 0xd2, 0x64, 0x40, 0x1d, 0xc4, 0x30, 0xba, 0xd5,\r
+  0x08, 0x88, 0x67, 0x4b, 0x0f, 0xb8, 0xe5, 0x59, 0xe9, 0x18, 0xd8, 0x0c, 0x60, 0x68, 0xae, 0x7f,\r
+  0xea, 0x91, 0x55, 0xbe, 0xeb, 0xf1, 0xa7, 0x8e, 0xd8, 0x5d, 0x50, 0x3e, 0xbf, 0xd5, 0x69, 0x57,\r
+  0x95, 0x8f, 0xa7, 0xff, 0xe4, 0x09, 0x3f, 0x08, 0x80, 0x97, 0x32, 0x42, 0xb8, 0x82, 0x43, 0x82,\r
+  0x6f, 0x8b, 0x0b, 0x93, 0xda, 0x19, 0xbf, 0x63, 0x4e, 0x5f, 0x9f, 0xed, 0x2c, 0x22, 0xb6, 0x20,\r
+  0x5f, 0x70, 0x44, 0xfa, 0x89, 0x59, 0x93, 0xb0, 0x7b, 0x12, 0x0f, 0x5e, 0x62, 0x62, 0x51, 0x11,\r
+  0xbd, 0xba, 0x5a, 0xd0, 0xce, 0xa1, 0xb6, 0xef, 0x80, 0x20, 0xe6, 0x73, 0x4b, 0x11, 0x06, 0x56,\r
+  0xe2, 0x0a\r
+  };\r
+\r
+//\r
+// OID ASN.1 Value for Hash Algorithms\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 HashOidValue[] = {\r
+  0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05,         // OBJ_md5\r
+  0x2B, 0x0E, 0x03, 0x02, 0x1A,                           // OBJ_sha1\r
+  0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04,   // OBJ_sha224\r
+  0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,   // OBJ_sha256\r
+  0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,   // OBJ_sha384\r
+  0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,   // OBJ_sha512\r
+  };\r
 \r
 /**\r
 \r
 /**\r
-  Validate MSFT Authenticode using PKCS#7 Verification Interfaces.\r
+  Validate MSFT Authenticode Signature.\r
 \r
 \r
-  @return  EFI_SUCCESS  Validation succeeds. \r
+  @retval  TRUE  Validation succeeded.\r
+  @retval  FALSE Validation failed.\r
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-AuthenticodeVerify (\r
+VerifyAuthenticode (\r
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-  UINT8    *SpcIndirectDataContent;\r
-  UINTN    Size;\r
   BOOLEAN  Status;\r
 \r
   BOOLEAN  Status;\r
 \r
+  Status = FALSE;\r
+  Print (L"\n- PE/COFF Authenticode (Digested by SHA-1) Verification   ... ");\r
+    \r
   //\r
   //\r
-  // Construct SpcIndirectDataContent with the SHA-1 digest calculated from PE/COFF image\r
-  //\r
-  Size = sizeof (SpcIndirectDataContentwithSha1);\r
-  SpcIndirectDataContent = (UINT8 *)AllocatePool (Size);\r
-  CopyMem (SpcIndirectDataContent, SpcIndirectDataContentwithSha1, Size);\r
-  CopyMem (SpcIndirectDataContent + Size - SHA1_DIGEST_SIZE, PeHash, SHA1_DIGEST_SIZE);\r
+  // Sample Code: Demonstrate how to check the Hash algorithm in PE/COFF Authenticode.\r
+  //    According to PKCS#7 Definition: \r
+  //        SignedData ::= SEQUENCE {\r
+  //            version Version,\r
+  //            digestAlgorithms DigestAlgorithmIdentifiers,\r
+  //            contentInfo ContentInfo,\r
+  //            .... }\r
+  //    The DigestAlgorithmIdentifiers can be used to determine the hash algorithm in PE/COFF hashing\r
+  //    This field has the fixed offset (+32) in final Authenticode ASN.1 data.\r
+  //    \r
+  if (CompareMem (AuthenticodeWithSha1 + 32, &HashOidValue[8], 5) == 0) {\r
+    //\r
+    // Verify Authenticode signature. \r
+    // The PeHash value should be calculated following MSFT's Authenticode Specification.\r
+    //\r
+    Status = AuthenticodeVerify (\r
+               AuthenticodeWithSha1,\r
+               sizeof (AuthenticodeWithSha1),\r
+               TestRootCert1,\r
+               sizeof (TestRootCert1),\r
+               PeSha1Hash,\r
+               SHA1_DIGEST_SIZE\r
+               );\r
+    if (Status) {\r
+      Print (L"[Pass]");\r
+    } else {\r
+      Print (L"[Fail]");\r
+    }       \r
+  } else {\r
+    Print (L"[Invalid Hash]");\r
+  }\r
 \r
 \r
-  //\r
-  // Verify Authenticode struct. SpcIndirectDataContent will be regarded as opaque data for\r
-  // PKCS#7 signed data verification.\r
-  //\r
-  Status = Pkcs7Verify (\r
-             Authenticode,\r
-             sizeof (Authenticode),\r
-             MsftRootCert,\r
-             sizeof (MsftRootCert),\r
-             SpcIndirectDataContent,\r
-             Size\r
-             );\r
-  FreePool (SpcIndirectDataContent);\r
+\r
+  Print (L"\n- PE/COFF Authenticode (Digested by SHA-256) Verification ... ");\r
+\r
+  if (CompareMem (AuthenticodeWithSha256 + 32, &HashOidValue[22], 9) == 0) {\r
+    Status = AuthenticodeVerify (\r
+               AuthenticodeWithSha256,\r
+               sizeof (AuthenticodeWithSha256),\r
+               TestRootCert2,\r
+               sizeof (TestRootCert2),\r
+               PeSha256Hash,\r
+               SHA256_DIGEST_SIZE\r
+               );\r
+    if (Status) {\r
+      Print (L"[Pass]");\r
+    } else {\r
+      Print (L"[Fail]");\r
+    }       \r
+  } else {\r
+    Print (L"[Invalid Hash]");\r
+  }\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
-  Validate UEFI-OpenSSL PKCS#7 Verification Interfaces.\r
+  Validate UEFI-OpenSSL Authenticode Verification Interfaces.\r
 \r
   @retval  EFI_SUCCESS  Validation succeeded.\r
   @retval  EFI_ABORTED  Validation failed.\r
 \r
   @retval  EFI_SUCCESS  Validation succeeded.\r
   @retval  EFI_ABORTED  Validation failed.\r
@@ -665,17 +1034,17 @@ ValidateAuthenticode (
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-  Print (L"\nUEFI-OpenSSL PKCS#7-Signed-Data Testing: ");\r
+  BOOLEAN Status;\r
 \r
 \r
-  Print (L"\n- Authenticode (PKCS#7 Signed Data) Verification ... ");\r
+  Print (L"\nUEFI-OpenSSL Authenticode Testing: ");\r
 \r
 \r
-  if (AuthenticodeVerify ()) {\r
-    Print (L"[Pass]");\r
-  } else {\r
-    Print (L"[Fail]");\r
-  }   \r
+  Status = VerifyAuthenticode ();\r
 \r
   Print (L"\n");\r
 \r
 \r
   Print (L"\n");\r
 \r
-  return EFI_SUCCESS;\r
+  if (Status) {\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_ABORTED;\r
+  }\r
 }\r
 }\r
index db8c89aa51d6507e97109eeb1d322161ff6010d6..44aaabadea6a177e6112c8b39f935ba43980566e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file  \r
   Application for Cryptographic Primitives Validation.\r
 \r
 /** @file  \r
   Application for Cryptographic Primitives Validation.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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
@@ -63,6 +63,11 @@ CryptestMain (
     return Status;\r
   }\r
 \r
     return Status;\r
   }\r
 \r
+  Status = ValidateCryptPkcs7 ();\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   Status = ValidateAuthenticode ();\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   Status = ValidateAuthenticode ();\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
index cc68cd3ce531eec392705bcd370d8b719aae2997..216d0a29dfe4905eb5131d2e6982a8763397d82b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file  \r
   Application for Cryptographic Primitives Validation.\r
 \r
 /** @file  \r
   Application for Cryptographic Primitives Validation.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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
@@ -85,7 +85,19 @@ ValidateCryptRsa2 (
   );\r
 \r
 /**\r
   );\r
 \r
 /**\r
-  Validate UEFI-OpenSSL PKCS#7 Verification Interfaces.\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
+/**\r
+  Validate UEFI-OpenSSL Authenticode Verification Interfaces.\r
 \r
   @retval  EFI_SUCCESS  Validation succeeded.\r
   @retval  EFI_ABORTED  Validation failed.\r
 \r
   @retval  EFI_SUCCESS  Validation succeeded.\r
   @retval  EFI_ABORTED  Validation failed.\r
index b6fdfb5c38e1e052ce14eaf063c4004667be1fac..98b5aad9009808fd74d3d932889731bcbf4bd5e7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file  \r
   Application for RSA Key Retrieving (from PEM and X509) & Signature Validation.\r
 \r
 /** @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
 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
   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
 /**\r
   Validate UEFI-OpenSSL RSA Key Retrieving & Signature Interfaces.\r
 \r
@@ -303,3 +308,88 @@ ValidateCryptRsa2 (
 \r
   return EFI_SUCCESS;\r
 }\r
 \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
index e5d263f84ededc153266c695d09a7028e69b077b..2ea3b00fa2925f1ff71d5d1b76beb2750d0f99f0 100644 (file)
@@ -23,7 +23,7 @@
   PLATFORM_VERSION               = 0.91\r
   DSC_SPECIFICATION              = 0x00010005\r
   OUTPUT_DIRECTORY               = Build/CryptoPkg\r
   PLATFORM_VERSION               = 0.91\r
   DSC_SPECIFICATION              = 0x00010005\r
   OUTPUT_DIRECTORY               = Build/CryptoPkg\r
-  SUPPORTED_ARCHITECTURES        = IA32|X64|IPF|EBC|ARM\r
+  SUPPORTED_ARCHITECTURES        = IA32|X64|IPF|ARM\r
   BUILD_TARGETS                  = DEBUG|RELEASE\r
   SKUID_IDENTIFIER               = DEFAULT\r
 \r
   BUILD_TARGETS                  = DEBUG|RELEASE\r
   SKUID_IDENTIFIER               = DEFAULT\r
 \r
@@ -68,6 +68,9 @@
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf\r
 \r
+[LibraryClasses.common.DXE_SMM_DRIVER]\r
+  BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf\r
+\r
 [LibraryClasses.common.DXE_SAL_DRIVER]\r
   BaseCryptLib|CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/BaseCryptLibRuntimeCryptProtocol.inf\r
 \r
 [LibraryClasses.common.DXE_SAL_DRIVER]\r
   BaseCryptLib|CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/BaseCryptLibRuntimeCryptProtocol.inf\r
 \r
index 5fbedd943923907c01f240beeb13d21f9e9da7a1..0745e9316d4f8d73e0fda25c16f89eed0f4dce73 100644 (file)
@@ -4,7 +4,7 @@
   primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r
   functionality enabling.\r
 \r
   primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r
   functionality enabling.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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
@@ -1346,7 +1346,7 @@ RsaCheckKey (
 \r
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
 \r
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
-  If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-224, SHA-512 or SHA-384 digest, then ASSERT().\r
+  If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then ASSERT().\r
   If SigSize is large enough but Signature is NULL, then ASSERT().\r
 \r
   @param[in]      RsaContext   Pointer to RSA context for signature generation.\r
   If SigSize is large enough but Signature is NULL, then ASSERT().\r
 \r
   @param[in]      RsaContext   Pointer to RSA context for signature generation.\r
@@ -1354,7 +1354,7 @@ RsaCheckKey (
   @param[in]      HashSize     Size of the message hash in bytes.\r
   @param[out]     Signature    Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
   @param[in, out] SigSize      On input, the size of Signature buffer in bytes.\r
   @param[in]      HashSize     Size of the message hash in bytes.\r
   @param[out]     Signature    Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
   @param[in, out] SigSize      On input, the size of Signature buffer in bytes.\r
-                              On output, the size of data returned in Signature buffer in bytes.\r
+                               On output, the size of data returned in Signature buffer in bytes.\r
 \r
   @retval  TRUE   Signature successfully generated in PKCS1-v1_5.\r
   @retval  FALSE  Signature generation failed.\r
 \r
   @retval  TRUE   Signature successfully generated in PKCS1-v1_5.\r
   @retval  FALSE  Signature generation failed.\r
@@ -1378,7 +1378,7 @@ RsaPkcs1Sign (
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
   If Signature is NULL, then ASSERT().\r
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
   If Signature is NULL, then ASSERT().\r
-  If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-224, SHA-512 or SHA-384 digest, then ASSERT().\r
+  If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then ASSERT().\r
 \r
   @param[in]  RsaContext   Pointer to RSA context for signature verification.\r
   @param[in]  MessageHash  Pointer to octet message hash to be checked.\r
 \r
   @param[in]  RsaContext   Pointer to RSA context for signature verification.\r
   @param[in]  MessageHash  Pointer to octet message hash to be checked.\r
@@ -1501,6 +1501,116 @@ X509VerifyCert (
   IN  UINTN        CACertSize\r
   );\r
 \r
   IN  UINTN        CACertSize\r
   );\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
+\r
+  @param[in]  Cert            Pointer to the DER-encoded certificate data.\r
+  @param[in]  CertSize        The size of certificate data in bytes.\r
+  @param[out] SingleX509Cert  The generated X509 object.\r
+\r
+  @retval     TRUE            The X509 object generation succeeded.\r
+  @retval     FALSE           The operation failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+X509ConstructCertificate (\r
+  IN   CONST UINT8  *Cert,\r
+  IN   UINTN        CertSize,\r
+  OUT  UINT8        **SingleX509Cert\r
+  );\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
+\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
+                              inserted X509 certificate.\r
+  @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
+  @retval     TRUE            The X509 stack construction succeeded.\r
+  @retval     FALSE           The construction operation failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+X509ConstructCertificateStack (\r
+  IN OUT  UINT8  **X509Stack,\r
+  ...  \r
+  );\r
+\r
+/**\r
+  Release the specified X509 object.\r
+\r
+  If X509Cert is NULL, then ASSERT().\r
+\r
+  @param[in]  X509Cert  Pointer to the X509 object to be released.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+X509Free (\r
+  IN  VOID  *X509Cert\r
+  );\r
+\r
+/**\r
+  Release the specified X509 stack object.\r
+\r
+  If X509Stack is NULL, then ASSERT().\r
+\r
+  @param[in]  X509Stack  Pointer to the X509 stack object to be released.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+X509StackFree (\r
+  IN  VOID  *X509Stack\r
+  );\r
+\r
+/**\r
+  Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
+  Syntax Standard, version 1.5". This interface is only intended to be used for\r
+  application to perform PKCS#7 functionality validation.\r
+\r
+  @param[in]  PrivateKey       Pointer to the PEM-formatted private key data for\r
+                               data signing.\r
+  @param[in]  PrivateKeySize   Size of the PEM private key data in bytes.\r
+  @param[in]  KeyPassword      NULL-terminated passphrase used for encrypted PEM\r
+                               key data.\r
+  @param[in]  InData           Pointer to the content to be signed.\r
+  @param[in]  InDataSize       Size of InData in bytes.\r
+  @param[in]  SignCert         Pointer to signer's DER-encoded certificate to sign with.\r
+  @param[in]  OtherCerts       Pointer to an optional additional set of certificates to\r
+                               include in the PKCS#7 signedData (e.g. any intermediate\r
+                               CAs in the chain).\r
+  @param[out] SignedData       Pointer to output PKCS#7 signedData.\r
+  @param[out] SignedDataSize   Size of SignedData in bytes.\r
+\r
+  @retval     TRUE             PKCS#7 data signing succeeded.\r
+  @retval     FALSE            PKCS#7 data signing failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Pkcs7Sign (\r
+  IN   CONST UINT8  *PrivateKey,\r
+  IN   UINTN        PrivateKeySize,\r
+  IN   CONST UINT8  *KeyPassword,\r
+  IN   UINT8        *InData,\r
+  IN   UINTN        InDataSize,\r
+  IN   UINT8        *SignCert,\r
+  IN   UINT8        *OtherCerts      OPTIONAL,\r
+  OUT  UINT8        **SignedData,\r
+  OUT  UINTN        *SignedDataSize\r
+  );\r
+\r
 /**\r
   Verifies the validility of a PKCS#7 signed data as described in "PKCS #7: Cryptographic\r
   Message Syntax Standard".\r
 /**\r
   Verifies the validility of a PKCS#7 signed data as described in "PKCS #7: Cryptographic\r
   Message Syntax Standard".\r
@@ -1530,6 +1640,39 @@ Pkcs7Verify (
   IN  UINTN        DataSize\r
   );\r
 \r
   IN  UINTN        DataSize\r
   );\r
 \r
+/**\r
+  Verifies the validility of a PE/COFF Authenticode Signature as described in "Windows\r
+  Authenticode Portable Executable Signature Format".\r
+\r
+  If AuthData is NULL, then ASSERT().\r
+  If ImageHash is NULL, then ASSERT().\r
+\r
+  @param[in]  AuthData     Pointer to the Authenticode Signature retrieved from signed\r
+                           PE/COFF image to be verified.\r
+  @param[in]  DataSize     Size of the Authenticode Signature in bytes.\r
+  @param[in]  TrustedCert  Pointer to a trusted/root certificate encoded in DER, which\r
+                           is used for certificate chain verification.\r
+  @param[in]  CertSize     Size of the trusted certificate in bytes.\r
+  @param[in]  ImageHash    Pointer to the original image file hash value. The procudure\r
+                           for calculating the image hash value is described in Authenticode\r
+                           specification.\r
+  @param[in]  HashSize     Size of Image hash value in bytes.\r
+\r
+  @retval  TRUE   The specified Authenticode Signature is valid.\r
+  @retval  FALSE  Invalid Authenticode Signature.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AuthenticodeVerify (\r
+  IN  CONST UINT8  *AuthData,\r
+  IN  UINTN        DataSize,\r
+  IN  CONST UINT8  *TrustedCert,\r
+  IN  UINTN        CertSize,\r
+  IN  CONST UINT8  *ImageHash,\r
+  IN  UINTN        HashSize\r
+  );\r
+\r
 //=====================================================================================\r
 //    DH Key Exchange Primitive\r
 //=====================================================================================\r
 //=====================================================================================\r
 //    DH Key Exchange Primitive\r
 //=====================================================================================\r
index dc25fd7b7222fc34eb5d44234c134cf929532710..33eda7dd50e1457c58bf8fb0be59b897a276e485 100644 (file)
@@ -41,8 +41,6 @@ typedef VOID  *FILE;
 #define va_end(Marker)                ((void)0)\r
 #endif\r
 \r
 #define va_end(Marker)                ((void)0)\r
 #endif\r
 \r
-\r
-\r
 //\r
 // #defines from EFI Application Toolkit required to buiild Open SSL\r
 //\r
 //\r
 // #defines from EFI Application Toolkit required to buiild Open SSL\r
 //\r
@@ -241,7 +239,6 @@ extern FILE  *stdout;
 #define abort()                           ASSERT (FALSE)\r
 #define assert(expression)\r
 #define localtime(timer)                  NULL\r
 #define abort()                           ASSERT (FALSE)\r
 #define assert(expression)\r
 #define localtime(timer)                  NULL\r
-#define gmtime(timer)                     NULL\r
 #define gmtime_r(timer,result)            (result = NULL)\r
 \r
 #endif\r
 #define gmtime_r(timer,result)            (result = NULL)\r
 \r
 #endif\r
index 26ec8c1e799c74c1a6092a86773f90f6c1fa7314..c21ee01c4b853d82620ece12b5b61d34549f6676 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Cryptographic Library Instance for DXE_DRIVER.\r
 #\r
 ## @file\r
 #  Cryptographic Library Instance for DXE_DRIVER.\r
 #\r
-#  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2009 - 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
 #  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
@@ -23,7 +23,7 @@
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF ARM\r
 #\r
 \r
 [Sources]\r
 #\r
 \r
 [Sources]\r
@@ -42,6 +42,7 @@
   Pk/CryptPkcs7.c\r
   Pk/CryptDh.c\r
   Pk/CryptX509.c\r
   Pk/CryptPkcs7.c\r
   Pk/CryptDh.c\r
   Pk/CryptX509.c\r
+  Pk/CryptAuthenticode.c\r
   Pem/CryptPem.c\r
 \r
   SysCall/CrtWrapper.c\r
   Pem/CryptPem.c\r
 \r
   SysCall/CrtWrapper.c\r
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c
new file mode 100644 (file)
index 0000000..5f93e4a
--- /dev/null
@@ -0,0 +1,143 @@
+/** @file\r
+  Authenticode Portable Executable Signature Verification over OpenSSL.\r
+\r
+Copyright (c) 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
+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
+\r
+**/\r
+\r
+#include "InternalCryptLib.h"\r
+\r
+#include <openssl/objects.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/pkcs7.h>\r
+\r
+\r
+/**\r
+  Verifies the validility of a PE/COFF Authenticode Signature as described in "Windows\r
+  Authenticode Portable Executable Signature Format".\r
+\r
+  If AuthData is NULL, then ASSERT().\r
+  If ImageHash is NULL, then ASSERT().\r
+\r
+  @param[in]  AuthData     Pointer to the Authenticode Signature retrieved from signed\r
+                           PE/COFF image to be verified.\r
+  @param[in]  DataSize     Size of the Authenticode Signature in bytes.\r
+  @param[in]  TrustedCert  Pointer to a trusted/root certificate encoded in DER, which\r
+                           is used for certificate chain verification.\r
+  @param[in]  CertSize     Size of the trusted certificate in bytes.\r
+  @param[in]  ImageHash    Pointer to the original image file hash value. The procudure\r
+                           for calculating the image hash value is described in Authenticode\r
+                           specification.\r
+  @param[in]  HashSize     Size of Image hash value in bytes.\r
+\r
+  @retval  TRUE   The specified Authenticode Signature is valid.\r
+  @retval  FALSE  Invalid Authenticode Signature.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AuthenticodeVerify (\r
+  IN  CONST UINT8  *AuthData,\r
+  IN  UINTN        DataSize,\r
+  IN  CONST UINT8  *TrustedCert,\r
+  IN  UINTN        CertSize,\r
+  IN  CONST UINT8  *ImageHash,\r
+  IN  UINTN        HashSize\r
+  )\r
+{\r
+  BOOLEAN      Status;\r
+  PKCS7        *Pkcs7;\r
+  CONST UINT8  *OrigAuthData;\r
+  UINT8        *SpcIndirectDataContent;\r
+  UINT8        Asn1Byte;\r
+  UINTN        ContentSize;\r
+\r
+  //\r
+  // ASSERT if Authenticode Signature Data or PE Image Hash is NULL\r
+  //\r
+  ASSERT (AuthData  != NULL);\r
+  ASSERT (ImageHash != NULL);\r
+\r
+  Status       = FALSE;\r
+  Pkcs7        = NULL;\r
+  OrigAuthData = AuthData;\r
+\r
+  //\r
+  // Retrieve & Parse PKCS#7 Data (DER encoding) from Authenticode Signature\r
+  //\r
+  Pkcs7 = d2i_PKCS7 (NULL, &AuthData, (int)DataSize);\r
+  if (Pkcs7 == NULL) {\r
+    goto _Exit;\r
+  }\r
+\r
+  //\r
+  // Check if it's PKCS#7 Signed Data (for Authenticode Scenario)\r
+  //\r
+  if (!PKCS7_type_is_signed (Pkcs7)) {\r
+    goto _Exit;\r
+  }\r
+\r
+  //\r
+  // NOTE: OpenSSL PKCS7 Decoder didn't work for Authenticode-format signed data due to\r
+  //       some authenticode-specific structure. Use opaque ASN.1 string to retrieve\r
+  //       PKCS#7 ContentInfo here.\r
+  //\r
+  SpcIndirectDataContent = (UINT8 *)(Pkcs7->d.sign->contents->d.other->value.asn1_string->data);\r
+\r
+  //\r
+  // Retrieve the SEQUENCE data size from ASN.1-encoded SpcIndirectDataContent.\r
+  //\r
+  Asn1Byte = *(SpcIndirectDataContent + 1);\r
+  if ((Asn1Byte & 0x80) == 0) {\r
+    //\r
+    // Short Form of Length Encoding\r
+    //\r
+    ContentSize = (UINTN) (Asn1Byte & 0x7F);\r
+    //\r
+    // Skip the SEQUENCE Tag;\r
+    //\r
+    SpcIndirectDataContent += 2;\r
+  } else {\r
+    //\r
+    // Long Form of Length Encoding (Assume Only two bytes here)\r
+    //\r
+    ContentSize  = (UINTN) (*(SpcIndirectDataContent + 2));\r
+    ContentSize = (ContentSize << 8) + (UINTN)(*(SpcIndirectDataContent + 3));\r
+    //\r
+    // Skip the SEQUENCE Tag;\r
+    //\r
+    SpcIndirectDataContent += 4;\r
+  }\r
+\r
+  //\r
+  // Compare the original file hash value to the digest retrieve from SpcIndirectDataContent\r
+  // defined in Authenticode\r
+  // NOTE: Need to double-check HashLength here!\r
+  //\r
+  if (CompareMem (SpcIndirectDataContent + ContentSize - HashSize, ImageHash, HashSize) != 0) {\r
+    //\r
+    // Un-matched PE/COFF Hash Value\r
+    //\r
+    goto _Exit;\r
+  }\r
+\r
+  //\r
+  // Verifies the PKCS#7 Signed Data in PE/COFF Authenticode Signature\r
+  //\r
+  Status = (BOOLEAN) Pkcs7Verify (OrigAuthData, DataSize, TrustedCert, CertSize, SpcIndirectDataContent, ContentSize);\r
+\r
+_Exit:\r
+  //\r
+  // Release Resources\r
+  //\r
+  PKCS7_free (Pkcs7);\r
+\r
+  return Status;\r
+}\r
index ca0dd4f286480b3c15818d4a02abb4b0164c3294..816ae53ea9ea3f9387e327c16fe53c79b342f23f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PKCS#7 SignedData Verification Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   PKCS#7 SignedData Verification Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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,6 +19,235 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <openssl/pkcs7.h>\r
 \r
 \r
 #include <openssl/pkcs7.h>\r
 \r
 \r
+/**\r
+  Verification callback function to override any existing callbacks in OpenSSL\r
+  for intermediate certificate supports.\r
+\r
+  @param[in]  Status   Original status before calling this callback.\r
+  @param[in]  Context  X509 store context.\r
+\r
+  @retval     1        Current X509 certificate is verified successfully.\r
+  @retval     0        Verification failed.\r
+\r
+**/\r
+STATIC int X509VerifyCb (int Status, X509_STORE_CTX *Context)\r
+{\r
+  X509_OBJECT  *Obj;\r
+  int          Error;\r
+  int          Index;\r
+  int          Count;\r
+\r
+  Obj   = NULL;\r
+  Error = X509_STORE_CTX_get_error (Context);\r
+\r
+  //\r
+  // X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT and X509_V_ERR_UNABLE_TO_GET_ISSUER_\r
+  // CERT_LOCALLY mean a X509 certificate is not self signed and its issuer\r
+  // can not be found in X509_verify_cert of X509_vfy.c.\r
+  // In order to support intermediate certificate node, we override the\r
+  // errors if the certification is obtained from X509 store, i.e. it is\r
+  // a trusted ceritifcate node that is enrolled by user.\r
+  // Besides,X509_V_ERR_CERT_UNTRUSTED and X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE\r
+  // are also ignored to enable such feature.\r
+  //\r
+  if ((Error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT) ||\r
+      (Error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) {\r
+    Obj = (X509_OBJECT *) OPENSSL_malloc (sizeof (X509_OBJECT));\r
+    if (Obj == NULL) {\r
+      return 0;\r
+    }\r
+\r
+    Obj->type      = X509_LU_X509;\r
+    Obj->data.x509 = Context->current_cert;\r
+\r
+    CRYPTO_w_lock (CRYPTO_LOCK_X509_STORE);\r
+\r
+    if (X509_OBJECT_retrieve_match (Context->ctx->objs, Obj)) {\r
+      Status = 1;\r
+    } else {\r
+      //\r
+      // If any certificate in the chain is enrolled as trusted certificate,\r
+      // pass the certificate verification.\r
+      //\r
+      if (Error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) {\r
+        Count = sk_X509_num (Context->chain);\r
+        for (Index = 0; Index < Count; Index++) {\r
+          Obj->data.x509 = sk_X509_value (Context->chain, Index);\r
+          if (X509_OBJECT_retrieve_match (Context->ctx->objs, Obj)) {\r
+            Status = 1;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    CRYPTO_w_unlock (CRYPTO_LOCK_X509_STORE);\r
+  }\r
+\r
+  if ((Error == X509_V_ERR_CERT_UNTRUSTED) ||\r
+      (Error == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE)) {\r
+    Status = 1;\r
+  }\r
+\r
+  if (Obj != NULL) {\r
+    OPENSSL_free (Obj);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
+  Syntax Standard, version 1.5". This interface is only intended to be used for\r
+  application to perform PKCS#7 functionality validation.\r
+\r
+  @param[in]  PrivateKey       Pointer to the PEM-formatted private key data for\r
+                               data signing.\r
+  @param[in]  PrivateKeySize   Size of the PEM private key data in bytes.\r
+  @param[in]  KeyPassword      NULL-terminated passphrase used for encrypted PEM\r
+                               key data.\r
+  @param[in]  InData           Pointer to the content to be signed.\r
+  @param[in]  InDataSize       Size of InData in bytes.\r
+  @param[in]  SignCert         Pointer to signer's DER-encoded certificate to sign with.\r
+  @param[in]  OtherCerts       Pointer to an optional additional set of certificates to\r
+                               include in the PKCS#7 signedData (e.g. any intermediate\r
+                               CAs in the chain).\r
+  @param[out] SignedData       Pointer to output PKCS#7 signedData.\r
+  @param[out] SignedDataSize   Size of SignedData in bytes.\r
+\r
+  @retval     TRUE             PKCS#7 data signing succeeded.\r
+  @retval     FALSE            PKCS#7 data signing failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Pkcs7Sign (\r
+  IN   CONST UINT8  *PrivateKey,\r
+  IN   UINTN        PrivateKeySize,\r
+  IN   CONST UINT8  *KeyPassword,\r
+  IN   UINT8        *InData,\r
+  IN   UINTN        InDataSize,\r
+  IN   UINT8        *SignCert,\r
+  IN   UINT8        *OtherCerts      OPTIONAL,\r
+  OUT  UINT8        **SignedData,\r
+  OUT  UINTN        *SignedDataSize\r
+  )\r
+{\r
+  BOOLEAN   Status;\r
+  EVP_PKEY  *Key;\r
+  BIO       *DataBio;\r
+  PKCS7     *Pkcs7;\r
+  UINT8     *RsaContext;\r
+  UINT8     *P7Data;\r
+\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if ((PrivateKey == NULL) || (KeyPassword == NULL) || (InData == NULL)) {\r
+    return FALSE;\r
+  }\r
+  \r
+  if ((SignCert == NULL) || (SignedData == NULL) || (SignedDataSize == NULL)) {\r
+    return FALSE;\r
+  }\r
+\r
+  RsaContext = NULL;\r
+  Key        = NULL;\r
+  Pkcs7      = NULL;\r
+  DataBio    = NULL;\r
+  Status     = FALSE;\r
+\r
+  //\r
+  // Retrieve RSA private key from PEM data.\r
+  //\r
+  Status = RsaGetPrivateKeyFromPem (\r
+             PrivateKey,\r
+             PrivateKeySize,\r
+             (CONST CHAR8 *) KeyPassword,\r
+             (VOID **) &RsaContext\r
+             );\r
+  if (!Status) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Register & Initialize necessary digest algorithms and PRNG for PKCS#7 Handling\r
+  //\r
+  EVP_add_digest (EVP_md5());\r
+  EVP_add_digest (EVP_sha1());\r
+  EVP_add_digest (EVP_sha256());\r
+  RandomSeed (NULL, 0);\r
+\r
+  //\r
+  // Construct OpenSSL EVP_PKEY for private key.\r
+  //\r
+  Key = EVP_PKEY_new ();\r
+  if (Key == NULL) {\r
+    goto _Exit;\r
+  }\r
+  Key->save_type = EVP_PKEY_RSA;\r
+  Key->type      = EVP_PKEY_type (EVP_PKEY_RSA);\r
+  Key->pkey.rsa  = (RSA *) RsaContext;\r
+\r
+  //\r
+  // Convert the data to be signed to BIO format. \r
+  //\r
+  DataBio = BIO_new (BIO_s_mem ());\r
+  BIO_write (DataBio, InData, (int) InDataSize);\r
+\r
+  //\r
+  // Create the PKCS#7 signedData structure.\r
+  //\r
+  Pkcs7 = PKCS7_sign (\r
+            (X509 *) SignCert,\r
+            Key,\r
+            (STACK_OF(X509) *) OtherCerts,\r
+            DataBio,\r
+            PKCS7_BINARY\r
+            );\r
+  if (Pkcs7 == NULL) {\r
+    goto _Exit;\r
+  }\r
+\r
+  //\r
+  // Convert PKCS#7 signedData structure into DER-encoded buffer.\r
+  //\r
+  *SignedDataSize = i2d_PKCS7 (Pkcs7, NULL);\r
+  if (*SignedDataSize == 0) {\r
+    goto _Exit;\r
+  }\r
+  *SignedData     = OPENSSL_malloc (*SignedDataSize);\r
+  P7Data          = *SignedData;\r
+  *SignedDataSize = i2d_PKCS7 (Pkcs7, (unsigned char **) &P7Data);\r
+\r
+  Status = TRUE;\r
+\r
+_Exit:\r
+  //\r
+  // Release Resources\r
+  //\r
+  if (RsaContext != NULL) {\r
+    RsaFree (RsaContext);\r
+    if (Key != NULL) {\r
+      Key->pkey.rsa = NULL;\r
+    }\r
+  }\r
+\r
+  if (Key != NULL) {\r
+    EVP_PKEY_free (Key);\r
+  }\r
+\r
+  if (DataBio != NULL) {\r
+    BIO_free (DataBio);\r
+  }\r
+\r
+  if (Pkcs7 != NULL) {\r
+    PKCS7_free (Pkcs7);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   Verifies the validility of a PKCS#7 signed data as described in "PKCS #7: Cryptographic\r
   Message Syntax Standard".\r
 /**\r
   Verifies the validility of a PKCS#7 signed data as described in "PKCS #7: Cryptographic\r
   Message Syntax Standard".\r
@@ -49,7 +278,6 @@ Pkcs7Verify (
   )\r
 {\r
   PKCS7       *Pkcs7;\r
   )\r
 {\r
   PKCS7       *Pkcs7;\r
-  UINT8       *Content;\r
   BIO         *CertBio;\r
   BIO         *DataBio;\r
   BOOLEAN     Status;\r
   BIO         *CertBio;\r
   BIO         *DataBio;\r
   BOOLEAN     Status;\r
@@ -73,6 +301,7 @@ Pkcs7Verify (
   //\r
   EVP_add_digest (EVP_md5());\r
   EVP_add_digest (EVP_sha1());\r
   //\r
   EVP_add_digest (EVP_md5());\r
   EVP_add_digest (EVP_sha1());\r
+  EVP_add_digest_alias (SN_sha1WithRSAEncryption, SN_sha1WithRSA);\r
   EVP_add_digest (EVP_sha256());\r
 \r
   //\r
   EVP_add_digest (EVP_sha256());\r
 \r
   //\r
@@ -90,23 +319,6 @@ Pkcs7Verify (
     goto _Exit;\r
   }\r
 \r
     goto _Exit;\r
   }\r
 \r
-  //\r
-  // Check PKCS#7 embedded signed content with InData.\r
-  //\r
-  if (InData != NULL) {\r
-    //\r
-    // NOTE: PKCS7_dataDecode() didn't work for Authenticode-format signed data due to\r
-    //       some authenticode-specific structure. Use opaque ASN.1 string to retrieve\r
-    //       PKCS#7 ContentInfo here.\r
-    //\r
-    Content = (UINT8 *)(Pkcs7->d.sign->contents->d.other->value.asn1_string->data);\r
-\r
-    // Ignore two bytes for DER encoding of ASN.1 "SEQUENCE"\r
-    if (CompareMem (Content + 2, InData, DataLength) != 0) {\r
-      goto _Exit;\r
-    }\r
-  }\r
-\r
   //\r
   // Read DER-encoded root certificate and Construct X509 Certificate\r
   //\r
   //\r
   // Read DER-encoded root certificate and Construct X509 Certificate\r
   //\r
@@ -131,6 +343,12 @@ Pkcs7Verify (
     goto _Exit;\r
   }\r
 \r
     goto _Exit;\r
   }\r
 \r
+  //\r
+  // Register customized X509 verification callback function to support\r
+  // trusted intermediate certificate anchor.\r
+  //\r
+  CertStore->verify_cb = X509VerifyCb;\r
+\r
   //\r
   // For generic PKCS#7 handling, InData may be NULL if the content is present\r
   // in PKCS#7 structure. So ignore NULL checking here.\r
   //\r
   // For generic PKCS#7 handling, InData may be NULL if the content is present\r
   // in PKCS#7 structure. So ignore NULL checking here.\r
@@ -141,7 +359,7 @@ Pkcs7Verify (
   //\r
   // Verifies the PKCS#7 signedData structure\r
   //\r
   //\r
   // Verifies the PKCS#7 signedData structure\r
   //\r
-  Status = (BOOLEAN) PKCS7_verify (Pkcs7, NULL, CertStore, DataBio, NULL, 0);\r
+  Status = (BOOLEAN) PKCS7_verify (Pkcs7, NULL, CertStore, DataBio, NULL, PKCS7_BINARY);\r
 \r
 _Exit:\r
   //\r
 \r
 _Exit:\r
   //\r
index 2e84a2f43f540a5c84570d2dc7499dabb3f49093..0b561c35807eb732882ba8098b04aea504ebb62f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   RSA Asymmetric Cipher Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   RSA Asymmetric Cipher Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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
@@ -545,7 +545,7 @@ DigestInfoEncoding (
 \r
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
 \r
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
-  If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-224, SHA-512 or SHA-384 digest, then ASSERT().\r
+  If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then ASSERT().\r
   If SigSize is large enough but Signature is NULL, then ASSERT().\r
 \r
   @param[in]       RsaContext   Pointer to RSA context for signature generation.\r
   If SigSize is large enough but Signature is NULL, then ASSERT().\r
 \r
   @param[in]       RsaContext   Pointer to RSA context for signature generation.\r
@@ -615,7 +615,7 @@ RsaPkcs1Sign (
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
   If Signature is NULL, then ASSERT().\r
   If RsaContext is NULL, then ASSERT().\r
   If MessageHash is NULL, then ASSERT().\r
   If Signature is NULL, then ASSERT().\r
-  If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-224, SHA-512 or SHA-384 digest, then ASSERT().\r
+  If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then ASSERT().\r
 \r
   @param[in]  RsaContext   Pointer to RSA context for signature verification.\r
   @param[in]  MessageHash  Pointer to octet message hash to be checked.\r
 \r
   @param[in]  RsaContext   Pointer to RSA context for signature verification.\r
   @param[in]  MessageHash  Pointer to octet message hash to be checked.\r
index 6d687c64b6674e59201021c3ff6ac8e12c7060d5..7557399aa4e7a6a0e7ca4c9572c951522af68aab 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, 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
 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
@@ -15,6 +15,202 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "InternalCryptLib.h"\r
 #include <openssl/x509.h>\r
 \r
 #include "InternalCryptLib.h"\r
 #include <openssl/x509.h>\r
 \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
+\r
+  @param[in]  Cert            Pointer to the DER-encoded certificate data.\r
+  @param[in]  CertSize        The size of certificate data in bytes.\r
+  @param[out] SingleX509Cert  The generated X509 object.\r
+\r
+  @retval     TRUE            The X509 object generation succeeded.\r
+  @retval     FALSE           The operation failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+X509ConstructCertificate (\r
+  IN   CONST UINT8  *Cert,\r
+  IN   UINTN        CertSize,\r
+  OUT  UINT8        **SingleX509Cert\r
+  )\r
+{\r
+  BIO      *CertBio;\r
+  X509     *X509Cert;\r
+  BOOLEAN  Status;\r
+\r
+  //\r
+  // ASSERT if Cert is NULL or SingleX509Cert is NULL.\r
+  //\r
+  ASSERT (Cert != NULL);\r
+  ASSERT (SingleX509Cert != NULL);\r
+\r
+  Status = FALSE;\r
+\r
+  //\r
+  // Read DER-encoded X509 Certificate and Construct X509 object.\r
+  //\r
+  CertBio = BIO_new (BIO_s_mem ());\r
+  BIO_write (CertBio, Cert, (int) CertSize);\r
+  if (CertBio == NULL) {\r
+    goto _Exit;\r
+  }\r
+  X509Cert = d2i_X509_bio (CertBio, NULL);\r
+  if (X509Cert == NULL) {\r
+    goto _Exit;\r
+  }\r
+\r
+  *SingleX509Cert = (UINT8 *) X509Cert;\r
+  Status = TRUE;\r
+\r
+_Exit:\r
+  //\r
+  // Release Resources.\r
+  //\r
+  BIO_free (CertBio);\r
+\r
+  return Status;\r
+}\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
+\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
+                              inserted X509 certificate.\r
+  @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
+  @retval     TRUE            The X509 stack construction succeeded.\r
+  @retval     FALSE           The construction operation failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+X509ConstructCertificateStack (\r
+  IN OUT  UINT8  **X509Stack,\r
+  ...  \r
+  )\r
+{\r
+  UINT8           *Cert;\r
+  UINTN           CertSize;\r
+  X509            *X509Cert;\r
+  STACK_OF(X509)  *CertStack;\r
+  BOOLEAN         Status;\r
+  VA_LIST         Args;\r
+  UINTN           Index;\r
+\r
+  //\r
+  // ASSERT if input X509Stack is NULL.\r
+  //\r
+  ASSERT (X509Stack != NULL);\r
+\r
+  Status = FALSE;\r
+\r
+  //\r
+  // Initialize X509 stack object.\r
+  //\r
+  CertStack = (STACK_OF(X509) *) (*X509Stack);\r
+  if (CertStack == NULL) {\r
+    CertStack = sk_X509_new_null ();\r
+    if (CertStack == NULL) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  VA_START (Args, X509Stack);\r
+\r
+  for (Index = 0; ; Index++) {\r
+    //\r
+    // If Cert is NULL, then it is the end of the list.\r
+    //\r
+    Cert = VA_ARG (Args, UINT8 *);\r
+    if (Cert == NULL) {\r
+      break;\r
+    }\r
+\r
+    CertSize = VA_ARG (Args, UINTN);\r
+\r
+    //\r
+    // Construct X509 Object from the given DER-encoded certificate data.\r
+    //\r
+    Status = X509ConstructCertificate (\r
+               (CONST UINT8 *) Cert,\r
+               CertSize,\r
+               (UINT8 **) &X509Cert\r
+               );\r
+    if (!Status) {\r
+      X509_free (X509Cert);\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Insert the new X509 object into X509 stack object.\r
+    //\r
+    sk_X509_push (CertStack, X509Cert);\r
+  }\r
+\r
+  VA_END (Args);\r
+\r
+  if (!Status) {\r
+    sk_X509_pop_free (CertStack, X509_free);\r
+  } else {\r
+    *X509Stack = (UINT8 *) CertStack;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Release the specified X509 object.\r
+\r
+  If X509Cert is NULL, then ASSERT().\r
+\r
+  @param[in]  X509Cert  Pointer to the X509 object to be released.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+X509Free (\r
+  IN  VOID  *X509Cert\r
+  )\r
+{\r
+  ASSERT (X509Cert != NULL);\r
+\r
+  //\r
+  // Free OpenSSL X509 object.\r
+  //\r
+  X509_free ((X509 *) X509Cert);\r
+}\r
+\r
+/**\r
+  Release the specified X509 stack object.\r
+\r
+  If X509Stack is NULL, then ASSERT().\r
+\r
+  @param[in]  X509Stack  Pointer to the X509 stack object to be released.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+X509StackFree (\r
+  IN  VOID  *X509Stack\r
+  )\r
+{\r
+  ASSERT (X509Stack != NULL);\r
+\r
+  //\r
+  // Free OpenSSL X509 stack object.\r
+  //\r
+  sk_X509_pop_free ((STACK_OF(X509) *) X509Stack, X509_free);\r
+}\r
+\r
 /**\r
   Retrieve the subject bytes from one X.509 certificate.\r
 \r
 /**\r
   Retrieve the subject bytes from one X.509 certificate.\r
 \r
@@ -42,7 +238,6 @@ X509GetSubjectName (
   )\r
 {\r
   BOOLEAN    Status;\r
   )\r
 {\r
   BOOLEAN    Status;\r
-  BIO        *CertBio;\r
   X509       *X509Cert;\r
   X509_NAME  *X509Name;\r
 \r
   X509       *X509Cert;\r
   X509_NAME  *X509Name;\r
 \r
@@ -58,13 +253,8 @@ X509GetSubjectName (
   //\r
   // Read DER-encoded X509 Certificate and Construct X509 object.\r
   //\r
   //\r
   // Read DER-encoded X509 Certificate and Construct X509 object.\r
   //\r
-  CertBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (CertBio, Cert, (int)CertSize);\r
-  if (CertBio == NULL) {\r
-    goto _Exit;\r
-  }\r
-  X509Cert = d2i_X509_bio (CertBio, NULL);\r
-  if (Cert == NULL) {\r
+  Status = X509ConstructCertificate (Cert, CertSize, (UINT8 **) &X509Cert);\r
+  if ((X509Cert == NULL) || (!Status)) {\r
     goto _Exit;\r
   }\r
 \r
     goto _Exit;\r
   }\r
 \r
@@ -86,7 +276,6 @@ _Exit:
   //\r
   // Release Resources.\r
   //\r
   //\r
   // Release Resources.\r
   //\r
-  BIO_free (CertBio);\r
   X509_free (X509Cert);\r
 \r
   return Status;\r
   X509_free (X509Cert);\r
 \r
   return Status;\r
@@ -118,7 +307,6 @@ RsaGetPublicKeyFromX509 (
 {\r
   BOOLEAN   Status;\r
   EVP_PKEY  *Pkey;\r
 {\r
   BOOLEAN   Status;\r
   EVP_PKEY  *Pkey;\r
-  BIO       *CertBio;\r
   X509      *X509Cert;\r
 \r
   //\r
   X509      *X509Cert;\r
 \r
   //\r
@@ -129,19 +317,13 @@ RsaGetPublicKeyFromX509 (
 \r
   Status   = FALSE;\r
   Pkey     = NULL;\r
 \r
   Status   = FALSE;\r
   Pkey     = NULL;\r
-  CertBio  = NULL;\r
   X509Cert = NULL;\r
 \r
   //\r
   // Read DER-encoded X509 Certificate and Construct X509 object.\r
   //\r
   X509Cert = NULL;\r
 \r
   //\r
   // Read DER-encoded X509 Certificate and Construct X509 object.\r
   //\r
-  CertBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (CertBio, Cert, (int)CertSize);\r
-  if (CertBio == NULL) {\r
-    goto _Exit;\r
-  }\r
-  X509Cert = d2i_X509_bio (CertBio, NULL);\r
-  if (X509Cert == NULL) {\r
+  Status = X509ConstructCertificate (Cert, CertSize, (UINT8 **) &X509Cert);\r
+  if ((X509Cert == NULL) || (!Status)) {\r
     goto _Exit;\r
   }\r
 \r
     goto _Exit;\r
   }\r
 \r
@@ -164,7 +346,6 @@ _Exit:
   //\r
   // Release Resources.\r
   //\r
   //\r
   // Release Resources.\r
   //\r
-  BIO_free (CertBio);\r
   X509_free (X509Cert);\r
   EVP_PKEY_free (Pkey);\r
 \r
   X509_free (X509Cert);\r
   EVP_PKEY_free (Pkey);\r
 \r
@@ -197,8 +378,6 @@ X509VerifyCert (
   )\r
 {\r
   BOOLEAN         Status;\r
   )\r
 {\r
   BOOLEAN         Status;\r
-  BIO             *BioCert;\r
-  BIO             *BioCACert;\r
   X509            *X509Cert;\r
   X509            *X509CACert;\r
   X509_STORE      *CertStore;\r
   X509            *X509Cert;\r
   X509            *X509CACert;\r
   X509_STORE      *CertStore;\r
@@ -211,8 +390,6 @@ X509VerifyCert (
   ASSERT (CACert != NULL);\r
 \r
   Status     = FALSE;\r
   ASSERT (CACert != NULL);\r
 \r
   Status     = FALSE;\r
-  BioCert    = NULL;\r
-  BioCACert  = NULL;\r
   X509Cert   = NULL;\r
   X509CACert = NULL;\r
   CertStore  = NULL;\r
   X509Cert   = NULL;\r
   X509CACert = NULL;\r
   CertStore  = NULL;\r
@@ -227,26 +404,16 @@ X509VerifyCert (
   //\r
   // Read DER-encoded certificate to be verified and Construct X509 object.\r
   //\r
   //\r
   // Read DER-encoded certificate to be verified and Construct X509 object.\r
   //\r
-  BioCert = BIO_new (BIO_s_mem ());\r
-  BIO_write (BioCert, Cert, (int)CertSize);\r
-  if (BioCert == NULL) {\r
-    goto _Exit;\r
-  }\r
-  X509Cert = d2i_X509_bio (BioCert, NULL);\r
-  if (X509Cert == NULL) {\r
+  Status = X509ConstructCertificate (Cert, CertSize, (UINT8 **) &X509Cert);\r
+  if ((X509Cert == NULL) || (!Status)) {\r
     goto _Exit;\r
   }\r
 \r
   //\r
   // Read DER-encoded root certificate and Construct X509 object.\r
   //\r
     goto _Exit;\r
   }\r
 \r
   //\r
   // Read DER-encoded root certificate and Construct X509 object.\r
   //\r
-  BioCACert = BIO_new (BIO_s_mem());\r
-  BIO_write (BioCACert, CACert, (int)CACertSize);\r
-  if (BioCert == NULL) {\r
-    goto _Exit;\r
-  }\r
-  X509CACert = d2i_X509_bio (BioCACert, NULL);\r
-  if (CACert == NULL) {\r
+  Status = X509ConstructCertificate (CACert, CACertSize, (UINT8 **) &X509CACert);\r
+  if ((X509CACert == NULL) || (!Status)) {\r
     goto _Exit;\r
   }\r
 \r
     goto _Exit;\r
   }\r
 \r
@@ -277,8 +444,6 @@ _Exit:
   //\r
   // Release Resources.\r
   //\r
   //\r
   // Release Resources.\r
   //\r
-  BIO_free (BioCert);\r
-  BIO_free (BioCACert);\r
   X509_free (X509Cert);\r
   X509_free (X509CACert);\r
   X509_STORE_free (CertStore);\r
   X509_free (X509Cert);\r
   X509_free (X509CACert);\r
   X509_STORE_free (CertStore);\r
index 81a37ec5aad22608d725f9e8bfb62c7604b4dd71..e025e6a07eea94b9811fdd47ca3f5b6069bfcfa1 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Cryptographic Library Instance for DXE_RUNTIME_DRIVER\r
 #\r
 ## @file\r
 #  Cryptographic Library Instance for DXE_RUNTIME_DRIVER\r
 #\r
-#  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2009 - 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
 #  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
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF ARM\r
 #\r
 \r
 [Sources]\r
   Hash/CryptMd5.c\r
   Hash/CryptSha1.c\r
   Hash/CryptSha256.c\r
 #\r
 \r
 [Sources]\r
   Hash/CryptMd5.c\r
   Hash/CryptSha1.c\r
   Hash/CryptSha256.c\r
+  Rand/CryptRand.c\r
   Pk/CryptRsa.c\r
   Pk/CryptRsa.c\r
-  \r
+  Pk/CryptPkcs7.c\r
+  Pem/CryptPem.c\r
+\r
   SysCall/CrtWrapper.c\r
   SysCall/TimerWrapper.c\r
   SysCall/RuntimeMemAllocation.c\r
   SysCall/CrtWrapper.c\r
   SysCall/TimerWrapper.c\r
   SysCall/RuntimeMemAllocation.c\r
index d5f1166f0fc9203ebf0857b644d706f5ff23e109..916b727d9493ab743065069c4ec1769bc17f5f5b 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Cryptographic Library Instance for SMM driver.\r
 #\r
 ## @file\r
 #  Cryptographic Library Instance for SMM driver.\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
 #  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
@@ -18,6 +18,7 @@
   FILE_GUID                      = 028080a3-8958-4a62-a1a8-0fa1da162007\r
   MODULE_TYPE                    = DXE_SMM_DRIVER\r
   VERSION_STRING                 = 1.0\r
   FILE_GUID                      = 028080a3-8958-4a62-a1a8-0fa1da162007\r
   MODULE_TYPE                    = DXE_SMM_DRIVER\r
   VERSION_STRING                 = 1.0\r
+  PI_SPECIFICATION_VERSION       = 0x0001000A\r
   LIBRARY_CLASS                  = BaseCryptLib|DXE_SMM_DRIVER SMM_CORE\r
 \r
 #\r
   LIBRARY_CLASS                  = BaseCryptLib|DXE_SMM_DRIVER SMM_CORE\r
 \r
 #\r
   Hash/CryptMd5.c\r
   Hash/CryptSha1.c\r
   Hash/CryptSha256.c\r
   Hash/CryptMd5.c\r
   Hash/CryptSha1.c\r
   Hash/CryptSha256.c\r
+  Rand/CryptRand.c\r
   Pk/CryptRsa.c\r
   Pk/CryptPkcs7.c\r
   Pk/CryptRsa.c\r
   Pk/CryptPkcs7.c\r
+  Pem/CryptPem.c\r
 \r
   SysCall/CrtWrapper.c\r
   SysCall/RealTimeClock.c\r
 \r
   SysCall/CrtWrapper.c\r
   SysCall/RealTimeClock.c\r
index 7b3dda70e0941242e5b53af89d9bb878aaeca6df..fb446b677044c35764c9e86bf1c7e8782ced1901 100644 (file)
@@ -18,7 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 int errno = 0;\r
 \r
 FILE  *stderr = NULL;\r
 int errno = 0;\r
 \r
 FILE  *stderr = NULL;\r
-FILE  *stdin = NULL;\r
+FILE  *stdin  = NULL;\r
 FILE  *stdout = NULL;\r
 \r
 typedef\r
 FILE  *stdout = NULL;\r
 \r
 typedef\r
@@ -244,7 +244,10 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
   ASSERT (base    != NULL);\r
   ASSERT (compare != NULL);\r
 \r
   ASSERT (base    != NULL);\r
   ASSERT (compare != NULL);\r
 \r
-  Buffer = AllocatePool (width);\r
+  //\r
+  // Use CRT-style malloc to cover BS and RT memory allocation.\r
+  //\r
+  Buffer = malloc (width);\r
   ASSERT (Buffer != NULL);\r
 \r
   //\r
   ASSERT (Buffer != NULL);\r
 \r
   //\r
@@ -252,7 +255,7 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
   //\r
   QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r
 \r
   //\r
   QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r
 \r
-  FreePool (Buffer);\r
+  free (Buffer);\r
   return;\r
 }\r
 \r
   return;\r
 }\r
 \r
index 84617b493fdafe9a850d42dd71e361c5f566ed62..7601c544b582f3fd822b453db06ad8a4fe766edb 100644 (file)
@@ -2,7 +2,7 @@
   C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
   for OpenSSL-based Cryptographic Library (used in SMM).\r
 \r
   C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
   for OpenSSL-based Cryptographic Library (used in SMM).\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
 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
@@ -74,6 +74,7 @@ typedef union {
 //\r
 \r
 #define IsLeap(y)   (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
 //\r
 \r
 #define IsLeap(y)   (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
+#define SECSPERMIN  (60)\r
 #define SECSPERHOUR (60 * 60)\r
 #define SECSPERDAY  (24 * SECSPERHOUR)\r
 \r
 #define SECSPERHOUR (60 * 60)\r
 #define SECSPERDAY  (24 * SECSPERHOUR)\r
 \r
@@ -220,3 +221,66 @@ time_t time (time_t *timer)
 \r
   return *timer;\r
 }\r
 \r
   return *timer;\r
 }\r
+\r
+//\r
+// Convert a time value from type time_t to struct tm.\r
+//\r
+struct tm * gmtime (const time_t *timer)\r
+{\r
+  struct tm      *GmTime;\r
+  UINT16         DayNo;\r
+  UINT16         DayRemainder;\r
+  time_t         Year;\r
+  time_t         YearNo;\r
+  UINT16         TotalDays;\r
+  UINT16         MonthNo;\r
+\r
+  if (timer == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  GmTime = malloc (sizeof (struct tm));\r
+  if (GmTime == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  ZeroMem ((VOID *) GmTime, (UINTN) sizeof (struct tm));\r
+\r
+  DayNo        = (UINT16) (*timer / SECSPERDAY);\r
+  DayRemainder = (UINT16) (*timer % SECSPERDAY);\r
+\r
+  GmTime->tm_sec = (int) (DayRemainder % SECSPERMIN);\r
+  GmTime->tm_min = (int) ((DayRemainder % SECSPERHOUR) / SECSPERMIN);\r
+  GmTime->tm_hour = (int) (DayRemainder / SECSPERHOUR);\r
+  GmTime->tm_wday = (int) ((DayNo + 4) % 7);\r
+\r
+  for (Year = 1970, YearNo = 0; DayNo > 0; Year++) {  \r
+    TotalDays = (UINT16) (IsLeap (Year) ? 366 : 365);\r
+    if (DayNo >= TotalDays) {\r
+      DayNo = (UINT16) (DayNo - TotalDays);\r
+      YearNo++;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+\r
+  GmTime->tm_year = (int) (YearNo + (1970 - 1900));\r
+  GmTime->tm_yday = (int) DayNo;\r
+\r
+  for (MonthNo = 12; MonthNo > 1; MonthNo--) {\r
+    if (DayNo > CumulativeDays[IsLeap(Year)][MonthNo]) {\r
+      DayNo = (UINT16) (DayNo - (UINT16) (CumulativeDays[IsLeap(Year)][MonthNo]));\r
+      break;\r
+    }\r
+  }\r
+\r
+  GmTime->tm_mon  = (int) MonthNo;\r
+  GmTime->tm_mday = (int) DayNo;\r
+\r
+  GmTime->tm_isdst  = 0;\r
+  GmTime->tm_gmtoff = 0;\r
+  GmTime->tm_zone   = NULL;\r
+\r
+  return GmTime;\r
+}\r
+\r
index f615ae8f903c3efabff99831b6bf3eb17dd047ee..0761e46e15f3df1c34f4c47d1a4c18e179742ad6 100644 (file)
@@ -2,7 +2,7 @@
   Light-weight Memory Management Routines for OpenSSL-based Crypto\r
   Library at Runtime Phase.\r
 \r
   Light-weight Memory Management Routines for OpenSSL-based Crypto\r
   Library at Runtime Phase.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
 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
@@ -38,7 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define RT_PAGE_FREE                0x00000000\r
 #define RT_PAGE_USED                0x00000001\r
 \r
 #define RT_PAGE_FREE                0x00000000\r
 #define RT_PAGE_USED                0x00000001\r
 \r
-#define MIN_REQUIRED_BLOCKS         24\r
+#define MIN_REQUIRED_BLOCKS         600\r
 \r
 //\r
 // Memory Page Table\r
 \r
 //\r
 // Memory Page Table\r
index 20928e1595ae418f52ab586c8470f79340300e07..805e6b4e206bbbec1a6114a42b33238c6cc0aad7 100644 (file)
@@ -2,7 +2,7 @@
   C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
   for OpenSSL-based Cryptographic Library (used in DXE & RUNTIME).\r
 \r
   C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
   for OpenSSL-based Cryptographic Library (used in DXE & RUNTIME).\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
 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
@@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 \r
 #define IsLeap(y)   (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
 //\r
 \r
 #define IsLeap(y)   (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
+#define SECSPERMIN  (60)\r
 #define SECSPERHOUR (60 * 60)\r
 #define SECSPERDAY  (24 * SECSPERHOUR)\r
 \r
 #define SECSPERHOUR (60 * 60)\r
 #define SECSPERDAY  (24 * SECSPERHOUR)\r
 \r
@@ -100,3 +101,65 @@ time_t time (time_t *timer)
 \r
   return *timer;\r
 }\r
 \r
   return *timer;\r
 }\r
+\r
+//\r
+// Convert a time value from type time_t to struct tm.\r
+//\r
+struct tm * gmtime (const time_t *timer)\r
+{\r
+  struct tm  *GmTime;\r
+  UINT16     DayNo;\r
+  UINT16     DayRemainder;\r
+  time_t     Year;\r
+  time_t     YearNo;\r
+  UINT16     TotalDays;\r
+  UINT16     MonthNo;\r
+\r
+  if (timer == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  GmTime = malloc (sizeof (struct tm));\r
+  if (GmTime == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  ZeroMem ((VOID *) GmTime, (UINTN) sizeof (struct tm));\r
+\r
+  DayNo        = (UINT16) (*timer / SECSPERDAY);\r
+  DayRemainder = (UINT16) (*timer % SECSPERDAY);\r
+\r
+  GmTime->tm_sec  = (int) (DayRemainder % SECSPERMIN);\r
+  GmTime->tm_min  = (int) ((DayRemainder % SECSPERHOUR) / SECSPERMIN);\r
+  GmTime->tm_hour = (int) (DayRemainder / SECSPERHOUR);\r
+  GmTime->tm_wday = (int) ((DayNo + 4) % 7);\r
+\r
+  for (Year = 1970, YearNo = 0; DayNo > 0; Year++) {\r
+    TotalDays = (UINT16) (IsLeap (Year) ? 366 : 365);\r
+    if (DayNo >= TotalDays) {\r
+      DayNo = (UINT16) (DayNo - TotalDays);\r
+      YearNo++;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+\r
+  GmTime->tm_year = (int) (YearNo + (1970 - 1900));\r
+  GmTime->tm_yday = (int) DayNo;\r
+\r
+  for (MonthNo = 12; MonthNo > 1; MonthNo--) {\r
+    if (DayNo > CumulativeDays[IsLeap(Year)][MonthNo]) {\r
+      DayNo = (UINT16) (DayNo - (UINT16) (CumulativeDays[IsLeap(Year)][MonthNo]));\r
+      break;\r
+    }\r
+  }\r
+\r
+  GmTime->tm_mon  = (int) MonthNo;\r
+  GmTime->tm_mday = (int) DayNo;\r
+\r
+  GmTime->tm_isdst  = 0;\r
+  GmTime->tm_gmtoff = 0;\r
+  GmTime->tm_zone   = NULL;\r
+\r
+  return GmTime;\r
+}\r