]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Application/Cryptest/RsaVerify2.c
CryptoPkg: Add new API to retrieve commonName of X.509 certificate
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / RsaVerify2.c
CommitLineData
4a567c96 1/** @file \r
2 Application for RSA Key Retrieving (from PEM and X509) & Signature Validation.\r
3\r
b7d320f8 4Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
4a567c96 5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Cryptest.h"\r
16\r
17//\r
18// X509 Cert Data for RSA Public Key Retrieving and X509 Verification (Generated by OpenSSL utility).\r
19//\r
20GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 TestCert[] = {\r
21 0x30, 0x82, 0x02, 0x76, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x09, 0x00, 0xa9, 0xff, 0x92, 0x73, 0xf6,\r
22 0x74, 0xe0, 0xb0, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05,\r
23 0x05, 0x00, 0x30, 0x7d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,\r
24 0x4e, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x08, 0x53, 0x68, 0x61, 0x6e,\r
25 0x67, 0x68, 0x61, 0x69, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x08, 0x53,\r
26 0x68, 0x61, 0x6e, 0x67, 0x68, 0x61, 0x69, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x0a,\r
27 0x13, 0x05, 0x49, 0x4e, 0x54, 0x45, 0x4c, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b,\r
28 0x13, 0x03, 0x50, 0x53, 0x49, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04,\r
29 0x55, 0x45, 0x46, 0x49, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,\r
30 0x01, 0x09, 0x01, 0x16, 0x0c, 0x75, 0x65, 0x66, 0x69, 0x40, 0x70, 0x73, 0x69, 0x2e, 0x63, 0x6f,\r
31 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x30, 0x31, 0x30, 0x30, 0x38, 0x31, 0x38, 0x32, 0x35, 0x35,\r
32 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x31, 0x30, 0x30, 0x35, 0x31, 0x38, 0x32, 0x35, 0x35, 0x39,\r
33 0x5a, 0x30, 0x81, 0x81, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,\r
34 0x4e, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x08, 0x53, 0x68, 0x61, 0x6e,\r
35 0x67, 0x68, 0x61, 0x69, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x08, 0x53,\r
36 0x68, 0x61, 0x6e, 0x67, 0x68, 0x61, 0x69, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x0a,\r
37 0x13, 0x05, 0x49, 0x4e, 0x54, 0x45, 0x4c, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b,\r
38 0x13, 0x03, 0x50, 0x53, 0x49, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06,\r
39 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,\r
40 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x40, 0x70, 0x73,\r
41 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,\r
42 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81,\r
43 0x81, 0x00, 0xc2, 0xfe, 0xbb, 0xbd, 0x92, 0x60, 0x6c, 0x2b, 0x75, 0x43, 0x6e, 0xd5, 0x91, 0x61,\r
44 0x2a, 0xec, 0x15, 0x84, 0xce, 0x83, 0xc2, 0x51, 0xf6, 0x81, 0x93, 0xe6, 0x38, 0xd4, 0x85, 0xb1,\r
45 0x02, 0x97, 0xb2, 0x7e, 0x74, 0x70, 0x57, 0x09, 0x72, 0xff, 0xb0, 0x7e, 0xd1, 0x9b, 0x34, 0x52,\r
46 0xbb, 0x8e, 0xaf, 0x62, 0x26, 0xad, 0xfa, 0xc5, 0x9e, 0x5c, 0xbc, 0xb9, 0x9e, 0xfe, 0xa0, 0x33,\r
47 0x30, 0x03, 0x9d, 0x3a, 0x09, 0xbb, 0xa5, 0xa9, 0x85, 0x35, 0x73, 0x52, 0xc3, 0xed, 0x10, 0x7f,\r
48 0x83, 0x06, 0xe5, 0x2b, 0x3e, 0x39, 0xd9, 0xdf, 0x34, 0x7e, 0x15, 0x53, 0xbb, 0x82, 0x98, 0xe3,\r
49 0xd8, 0x7e, 0xb3, 0x7e, 0xc0, 0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x7a, 0x5c, 0xf1\r
61 };\r
62\r
63//\r
64// Test CA X509 Certificate for X509 Verification Routine (Generated by OpenSSL utility).\r
65//\r
66GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 TestCACert[] = {\r
67 0x30, 0x82, 0x02, 0x71, 0x30, 0x82, 0x01, 0xda, 0x02, 0x09, 0x00, 0x91, 0x9b, 0x90, 0x19, 0x9c,\r
68 0x81, 0x28, 0x47, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05,\r
69 0x05, 0x00, 0x30, 0x7d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,\r
70 0x4e, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x08, 0x53, 0x68, 0x61, 0x6e,\r
71 0x67, 0x68, 0x61, 0x69, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x08, 0x53,\r
72 0x68, 0x61, 0x6e, 0x67, 0x68, 0x61, 0x69, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x0a,\r
73 0x13, 0x05, 0x49, 0x4e, 0x54, 0x45, 0x4c, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b,\r
74 0x13, 0x03, 0x50, 0x53, 0x49, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04,\r
75 0x55, 0x45, 0x46, 0x49, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \r
76 0x01, 0x09, 0x01, 0x16, 0x0c, 0x75, 0x65, 0x66, 0x69, 0x40, 0x70, 0x73, 0x69, 0x2e, 0x63, 0x6f,\r
77 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x30, 0x31, 0x30, 0x30, 0x38, 0x31, 0x38, 0x31, 0x35, 0x33,\r
78 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x31, 0x30, 0x30, 0x35, 0x31, 0x38, 0x31, 0x35, 0x33, 0x36,\r
79 0x5a, 0x30, 0x7d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4e,\r
80 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x08, 0x53, 0x68, 0x61, 0x6e, 0x67,\r
81 0x68, 0x61, 0x69, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x08, 0x53, 0x68,\r
82 0x61, 0x6e, 0x67, 0x68, 0x61, 0x69, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,\r
83 0x05, 0x49, 0x4e, 0x54, 0x45, 0x4c, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13,\r
84 0x03, 0x50, 0x53, 0x49, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x55,\r
85 0x45, 0x46, 0x49, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,\r
86 0x09, 0x01, 0x16, 0x0c, 0x75, 0x65, 0x66, 0x69, 0x40, 0x70, 0x73, 0x69, 0x2e, 0x63, 0x6f, 0x6d,\r
87 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,\r
88 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xa3, 0x32, 0x20,\r
89 0x1d, 0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d, 0x59, 0x51, 0x34, 0x7a, 0xb4, 0x22, 0x1d, 0x0f, 0x85, 0x9d, 0x80, 0x90, 0x3f,\r
101 0x8e, 0x78, 0x2f, 0xfc, 0x12, 0x9e, 0xf2, 0xaa, 0xc9, 0x5d, 0x4a, 0x82, 0xc5, 0x64, 0xc7, 0x5a,\r
102 0x29, 0xcb, 0xc2, 0x59, 0xde, 0xdf, 0xd8, 0x69, 0x51, 0x7a, 0x78, 0x4b, 0x47, 0x15, 0xcd, 0x52,\r
103 0x66, 0xff, 0xb8, 0xf5, 0x16, 0xde, 0xe4, 0x32, 0xc5, 0x40, 0x42, 0xeb, 0xeb, 0x54, 0x63, 0xf7,\r
104 0x82, 0x44, 0x4b, 0x5d, 0x8f, 0x3a, 0x29, 0xdf, 0xbc, 0xe0, 0x21, 0x3d, 0xc2, 0x4a, 0x19, 0x6e,\r
105 0x7c, 0xed, 0xd3, 0x79, 0xac, 0xb0, 0x37, 0xea, 0xfd, 0x60, 0x7f, 0xbe, 0x5b, 0x0b, 0x69, 0x4a,\r
106 0xe3, 0xac, 0xfa, 0x75, 0x0f\r
107 };\r
108\r
109//\r
110// Password-protected PEM Key data for RSA Private Key Retrieving (encryption key is "client").\r
111// (Generated by OpenSSL utility).\r
112//\r
113GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 TestKeyPem[] = {\r
114 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50,\r
115 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a,\r
116 0x50, 0x72, 0x6f, 0x63, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x34, 0x2c, 0x45, 0x4e, 0x43,\r
117 0x52, 0x59, 0x50, 0x54, 0x45, 0x44, 0x0a, 0x44, 0x45, 0x4b, 0x2d, 0x49, 0x6e, 0x66, 0x6f, 0x3a,\r
118 0x20, 0x44, 0x45, 0x53, 0x2d, 0x45, 0x44, 0x45, 0x33, 0x2d, 0x43, 0x42, 0x43, 0x2c, 0x44, 0x45,\r
119 0x37, 0x32, 0x46, 0x31, 0x31, 0x30, 0x31, 0x31, 0x37, 0x42, 0x33, 0x36, 0x35, 0x36, 0x0a, 0x0a,\r
120 0x38, 0x73, 0x6e, 0x79, 0x32, 0x59, 0x54, 0x79, 0x37, 0x67, 0x52, 0x5a, 0x38, 0x69, 0x73, 0x77,\r
121 0x68, 0x37, 0x66, 0x46, 0x71, 0x49, 0x31, 0x30, 0x61, 0x39, 0x38, 0x6a, 0x2f, 0x76, 0x45, 0x66,\r
122 0x69, 0x65, 0x47, 0x32, 0x43, 0x34, 0x53, 0x2b, 0x48, 0x70, 0x68, 0x33, 0x63, 0x68, 0x7a, 0x45,\r
123 0x2f, 0x63, 0x58, 0x31, 0x2b, 0x6b, 0x6a, 0x6c, 0x46, 0x6b, 0x71, 0x6b, 0x47, 0x4e, 0x65, 0x4d,\r
124 0x0a, 0x70, 0x72, 0x4b, 0x2b, 0x66, 0x48, 0x5a, 0x50, 0x77, 0x6c, 0x30, 0x63, 0x33, 0x79, 0x76,\r
125 0x59, 0x58, 0x45, 0x7a, 0x4c, 0x45, 0x62, 0x50, 0x6f, 0x38, 0x4c, 0x6e, 0x74, 0x38, 0x36, 0x65,\r
126 0x46, 0x53, 0x6f, 0x66, 0x4d, 0x78, 0x70, 0x33, 0x33, 0x64, 0x48, 0x39, 0x5a, 0x68, 0x6f, 0x57,\r
127 0x66, 0x41, 0x43, 0x59, 0x78, 0x47, 0x44, 0x6f, 0x32, 0x30, 0x53, 0x33, 0x79, 0x42, 0x39, 0x67,\r
128 0x38, 0x0a, 0x4d, 0x75, 0x59, 0x63, 0x74, 0x32, 0x38, 0x62, 0x6f, 0x62, 0x30, 0x65, 0x7a, 0x31,\r
129 0x43, 0x38, 0x51, 0x52, 0x78, 0x58, 0x48, 0x31, 0x66, 0x4a, 0x52, 0x5a, 0x52, 0x50, 0x34, 0x38,\r
130 0x50, 0x42, 0x6f, 0x5a, 0x7a, 0x36, 0x73, 0x6a, 0x4b, 0x36, 0x57, 0x51, 0x58, 0x66, 0x67, 0x4d,\r
131 0x32, 0x70, 0x4c, 0x31, 0x42, 0x6f, 0x51, 0x70, 0x4e, 0x4e, 0x4f, 0x6d, 0x61, 0x79, 0x2b, 0x2b,\r
132 0x72, 0x74, 0x0a, 0x6c, 0x7a, 0x32, 0x4f, 0x63, 0x72, 0x6a, 0x67, 0x2f, 0x72, 0x45, 0x61, 0x79,\r
133 0x63, 0x63, 0x43, 0x55, 0x4d, 0x7a, 0x4e, 0x4f, 0x4a, 0x51, 0x74, 0x4f, 0x47, 0x74, 0x34, 0x7a,\r
134 0x4d, 0x4a, 0x53, 0x73, 0x2f, 0x7a, 0x77, 0x77, 0x77, 0x73, 0x5a, 0x43, 0x4b, 0x74, 0x39, 0x33,\r
135 0x37, 0x30, 0x62, 0x76, 0x74, 0x63, 0x36, 0x45, 0x34, 0x75, 0x42, 0x63, 0x75, 0x41, 0x51, 0x72,\r
136 0x37, 0x73, 0x30, 0x0a, 0x44, 0x76, 0x46, 0x64, 0x4d, 0x6d, 0x6f, 0x71, 0x35, 0x57, 0x6d, 0x69,\r
137 0x48, 0x6d, 0x4e, 0x70, 0x67, 0x54, 0x70, 0x65, 0x54, 0x67, 0x77, 0x62, 0x56, 0x64, 0x76, 0x71,\r
138 0x49, 0x4f, 0x71, 0x31, 0x45, 0x6c, 0x6e, 0x30, 0x35, 0x53, 0x70, 0x76, 0x44, 0x7a, 0x4d, 0x56,\r
139 0x76, 0x67, 0x39, 0x78, 0x62, 0x76, 0x64, 0x6f, 0x6e, 0x67, 0x4f, 0x35, 0x77, 0x49, 0x51, 0x70,\r
140 0x69, 0x73, 0x73, 0x47, 0x0a, 0x75, 0x32, 0x69, 0x63, 0x4e, 0x66, 0x48, 0x48, 0x6d, 0x34, 0x76,\r
141 0x48, 0x2b, 0x6d, 0x6e, 0x72, 0x58, 0x45, 0x57, 0x63, 0x69, 0x6c, 0x30, 0x64, 0x61, 0x36, 0x6b,\r
142 0x54, 0x59, 0x66, 0x71, 0x70, 0x6d, 0x46, 0x37, 0x72, 0x52, 0x4d, 0x56, 0x61, 0x6c, 0x69, 0x30,\r
143 0x43, 0x44, 0x4f, 0x59, 0x7a, 0x37, 0x6e, 0x70, 0x51, 0x64, 0x33, 0x38, 0x6a, 0x43, 0x62, 0x78,\r
144 0x65, 0x59, 0x51, 0x65, 0x6d, 0x0a, 0x33, 0x68, 0x73, 0x61, 0x6f, 0x76, 0x58, 0x72, 0x71, 0x71,\r
145 0x4e, 0x34, 0x71, 0x6b, 0x67, 0x50, 0x48, 0x57, 0x68, 0x41, 0x74, 0x39, 0x5a, 0x4d, 0x4e, 0x37,\r
146 0x58, 0x45, 0x62, 0x56, 0x36, 0x42, 0x31, 0x6c, 0x36, 0x77, 0x4a, 0x71, 0x5a, 0x68, 0x68, 0x66,\r
147 0x33, 0x68, 0x79, 0x7a, 0x6f, 0x38, 0x32, 0x38, 0x47, 0x59, 0x45, 0x37, 0x56, 0x58, 0x45, 0x4e,\r
148 0x49, 0x6d, 0x76, 0x73, 0x35, 0x56, 0x0a, 0x69, 0x52, 0x58, 0x31, 0x6d, 0x61, 0x43, 0x30, 0x56,\r
149 0x6b, 0x72, 0x31, 0x46, 0x32, 0x36, 0x55, 0x63, 0x4b, 0x51, 0x67, 0x34, 0x66, 0x53, 0x39, 0x43,\r
150 0x71, 0x48, 0x31, 0x39, 0x7a, 0x4b, 0x36, 0x6d, 0x6d, 0x71, 0x47, 0x75, 0x67, 0x76, 0x66, 0x66,\r
151 0x2f, 0x74, 0x5a, 0x50, 0x72, 0x67, 0x68, 0x61, 0x4f, 0x62, 0x52, 0x2b, 0x77, 0x76, 0x34, 0x46,\r
152 0x65, 0x4f, 0x32, 0x42, 0x45, 0x44, 0x6d, 0x0a, 0x67, 0x4d, 0x33, 0x71, 0x47, 0x51, 0x4a, 0x44,\r
153 0x35, 0x53, 0x65, 0x77, 0x4f, 0x61, 0x62, 0x41, 0x72, 0x4e, 0x37, 0x4c, 0x6f, 0x30, 0x59, 0x2b,\r
154 0x44, 0x6a, 0x79, 0x39, 0x44, 0x43, 0x4b, 0x6f, 0x47, 0x4e, 0x4a, 0x50, 0x53, 0x4f, 0x58, 0x65,\r
155 0x70, 0x57, 0x48, 0x65, 0x6d, 0x6c, 0x76, 0x72, 0x49, 0x63, 0x39, 0x66, 0x4d, 0x2f, 0x37, 0x57,\r
156 0x6a, 0x4b, 0x4d, 0x6b, 0x72, 0x57, 0x50, 0x6a, 0x0a, 0x56, 0x64, 0x73, 0x61, 0x6e, 0x4b, 0x30,\r
157 0x7a, 0x74, 0x4e, 0x2b, 0x43, 0x49, 0x64, 0x66, 0x38, 0x70, 0x33, 0x55, 0x30, 0x30, 0x57, 0x44,\r
158 0x6d, 0x30, 0x2f, 0x62, 0x4d, 0x43, 0x56, 0x6d, 0x6b, 0x36, 0x6a, 0x76, 0x47, 0x66, 0x2f, 0x63,\r
159 0x55, 0x6c, 0x47, 0x38, 0x79, 0x6d, 0x30, 0x2f, 0x49, 0x67, 0x4a, 0x70, 0x71, 0x35, 0x2b, 0x33,\r
160 0x62, 0x78, 0x38, 0x73, 0x63, 0x54, 0x64, 0x55, 0x4f, 0x0a, 0x41, 0x38, 0x30, 0x41, 0x56, 0x68,\r
161 0x61, 0x53, 0x41, 0x71, 0x44, 0x6d, 0x68, 0x49, 0x6c, 0x59, 0x34, 0x54, 0x6f, 0x78, 0x42, 0x68,\r
162 0x63, 0x46, 0x2b, 0x4b, 0x4d, 0x48, 0x57, 0x33, 0x33, 0x5a, 0x45, 0x79, 0x66, 0x4a, 0x4a, 0x54,\r
163 0x71, 0x55, 0x42, 0x71, 0x4a, 0x6a, 0x4f, 0x69, 0x75, 0x41, 0x78, 0x6a, 0x59, 0x70, 0x71, 0x4f,\r
164 0x4e, 0x45, 0x35, 0x56, 0x4b, 0x33, 0x48, 0x68, 0x6c, 0x45, 0x0a, 0x2f, 0x4a, 0x33, 0x6b, 0x57,\r
165 0x79, 0x4f, 0x39, 0x69, 0x4d, 0x62, 0x33, 0x67, 0x73, 0x44, 0x59, 0x36, 0x41, 0x76, 0x41, 0x76,\r
166 0x5a, 0x39, 0x71, 0x6c, 0x5a, 0x6b, 0x30, 0x52, 0x50, 0x67, 0x49, 0x4c, 0x4a, 0x77, 0x6e, 0x33,\r
167 0x6d, 0x77, 0x67, 0x73, 0x63, 0x55, 0x70, 0x41, 0x30, 0x5a, 0x50, 0x6a, 0x61, 0x55, 0x56, 0x6c,\r
168 0x64, 0x71, 0x70, 0x32, 0x69, 0x71, 0x47, 0x78, 0x71, 0x50, 0x36, 0x0a, 0x45, 0x72, 0x65, 0x38,\r
169 0x38, 0x59, 0x75, 0x41, 0x53, 0x55, 0x4a, 0x5a, 0x4a, 0x62, 0x34, 0x72, 0x53, 0x42, 0x4c, 0x68,\r
170 0x45, 0x55, 0x41, 0x76, 0x63, 0x67, 0x38, 0x33, 0x4d, 0x6b, 0x4d, 0x6c, 0x68, 0x74, 0x6b, 0x34,\r
171 0x62, 0x67, 0x34, 0x5a, 0x35, 0x65, 0x73, 0x44, 0x57, 0x66, 0x4d, 0x67, 0x56, 0x65, 0x6a, 0x4e,\r
172 0x4a, 0x51, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53,\r
173 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d,\r
174 0x2d, 0x2d\r
175 };\r
176\r
177//\r
178// Password for private key retrieving from encrypted PEM ("TestKeyPem").\r
179//\r
180GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *PemPass = "client";\r
181\r
182//\r
183// Message Hash for Signing & Verification Validation.\r
184//\r
185GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 MsgHash[] = {\r
186 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,\r
187 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09\r
188 };\r
189\r
b7d320f8 190//\r
191// Payload for PKCS#7 Signing & Verification Validation.\r
192//\r
193GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Payload = "Payload Data for PKCS#7 Signing";\r
194\r
4a567c96 195/**\r
196 Validate UEFI-OpenSSL RSA Key Retrieving & Signature Interfaces.\r
197\r
198 @retval EFI_SUCCESS Validation succeeded.\r
199 @retval EFI_ABORTED Validation failed.\r
200\r
201**/\r
202EFI_STATUS\r
203ValidateCryptRsa2 (\r
204 VOID\r
205 )\r
206{\r
5b7c2245
QL
207 BOOLEAN Status;\r
208 VOID *RsaPrivKey;\r
209 VOID *RsaPubKey;\r
210 UINT8 *Signature;\r
211 UINTN SigSize;\r
212 UINT8 *Subject;\r
213 UINTN SubjectSize;\r
214 RETURN_STATUS ReturnStatus;\r
215 CHAR8 CommonName[64];\r
216 CHAR16 CommonNameUnicode[64];\r
217 UINTN CommonNameSize;\r
4a567c96 218\r
219 Print (L"\nUEFI-OpenSSL RSA Key Retrieving Testing: ");\r
220\r
221 //\r
222 // Retrieve RSA private key from encrypted PEM data.\r
223 //\r
224 Print (L"\n- Retrieve RSA Private Key for PEM ...");\r
225 Status = RsaGetPrivateKeyFromPem (TestKeyPem, sizeof (TestKeyPem), PemPass, &RsaPrivKey);\r
96488aa2 226 if (!Status) {\r
4a567c96 227 Print (L"[Fail]");\r
228 return EFI_ABORTED;\r
229 } else {\r
230 Print (L"[Pass]");\r
231 }\r
232\r
233 //\r
234 // Retrieve RSA public key from X509 Certificate.\r
235 //\r
236 Print (L"\n- Retrieve RSA Public Key from X509 ... ");\r
237 RsaPubKey = NULL;\r
238 Status = RsaGetPublicKeyFromX509 (TestCert, sizeof (TestCert), &RsaPubKey);\r
96488aa2 239 if (!Status) {\r
4a567c96 240 Print (L"[Fail]");\r
241 return EFI_ABORTED;\r
242 } else {\r
243 Print (L"[Pass]");\r
244 }\r
245\r
246 //\r
247 // Generate RSA PKCS#1 Signature.\r
248 //\r
249 Print (L"\n- PKCS#1 Signature ... ");\r
250 SigSize = 0;\r
251 Status = RsaPkcs1Sign (RsaPrivKey, MsgHash, SHA1_DIGEST_SIZE, NULL, &SigSize);\r
252 if (Status || SigSize == 0) {\r
253 Print (L"[Fail]");\r
254 return EFI_ABORTED;\r
255 }\r
256\r
257 Signature = AllocatePool (SigSize);\r
258 Status = RsaPkcs1Sign (RsaPrivKey, MsgHash, SHA1_DIGEST_SIZE, Signature, &SigSize);\r
259 if (!Status) {\r
260 Print (L"[Fail]");\r
261 return EFI_ABORTED;\r
262 } else {\r
263 Print (L"[Pass]");\r
264 }\r
265\r
266 //\r
267 // Verify RSA PKCS#1-encoded Signature.\r
268 //\r
269 Print (L"\n- PKCS#1 Signature Verification ... ");\r
270 Status = RsaPkcs1Verify (RsaPubKey, MsgHash, SHA1_DIGEST_SIZE, Signature, SigSize);\r
271 if (!Status) {\r
272 Print (L"[Fail]");\r
273 return EFI_ABORTED;\r
274 } else {\r
275 Print (L"[Pass]");\r
276 }\r
277\r
278 //\r
279 // X509 Certificate Subject Retrieving.\r
280 //\r
281 Print (L"\n- X509 Certificate Subject Bytes Retrieving ... ");\r
282 SubjectSize = 0;\r
283 Status = X509GetSubjectName (TestCert, sizeof (TestCert), NULL, &SubjectSize);\r
284 Subject = (UINT8 *)AllocatePool (SubjectSize);\r
285 Status = X509GetSubjectName (TestCert, sizeof (TestCert), Subject, &SubjectSize);\r
286 if (!Status) {\r
287 Print (L"[Fail]");\r
288 return EFI_ABORTED;\r
289 } else {\r
290 Print (L"[Pass]");\r
291 }\r
292\r
5b7c2245
QL
293 //\r
294 // Get CommonName from X509 Certificate Subject\r
295 //\r
296 CommonNameSize = 64;\r
297 ZeroMem (CommonName, CommonNameSize);\r
298 ReturnStatus = X509GetCommonName (TestCert, sizeof (TestCert), CommonName, &CommonNameSize);\r
299 if (RETURN_ERROR (ReturnStatus)) {\r
300 Print (L"\n - Retrieving Common Name - [Fail]");\r
301 return EFI_ABORTED;\r
302 } else {\r
303 AsciiStrToUnicodeStrS (CommonName, CommonNameUnicode, CommonNameSize);\r
304 Print (L"\n - Retrieving Common Name = \"%s\" (Size = %d)", CommonNameUnicode, CommonNameSize);\r
305 }\r
306\r
4a567c96 307 //\r
308 // X509 Certificate Verification.\r
309 //\r
310 Print (L"\n- X509 Certificate Verification with Trusted CA ...");\r
311 Status = X509VerifyCert (TestCert, sizeof (TestCert), TestCACert, sizeof (TestCACert));\r
312 if (!Status) {\r
313 Print (L"[Fail]\n");\r
314 return EFI_ABORTED;\r
315 } else {\r
316 Print (L"[Pass]\n");\r
317 }\r
318\r
319 //\r
320 // Release Resources.\r
321 //\r
322 RsaFree (RsaPubKey);\r
323 RsaFree (RsaPrivKey);\r
324 FreePool (Signature);\r
325 FreePool (Subject);\r
326\r
327 return EFI_SUCCESS;\r
328}\r
b7d320f8 329\r
330/**\r
331 Validate UEFI-OpenSSL PKCS#7 Signing & Verification Interfaces.\r
332\r
333 @retval EFI_SUCCESS Validation succeeded.\r
334 @retval EFI_ABORTED Validation failed.\r
335\r
336**/\r
337EFI_STATUS\r
338ValidateCryptPkcs7 (\r
339 VOID\r
340 )\r
341{\r
342 BOOLEAN Status;\r
343 UINT8 *P7SignedData;\r
344 UINTN P7SignedDataSize;\r
345 UINT8 *SignCert;\r
346\r
347 P7SignedData = NULL;\r
348 SignCert = NULL;\r
349\r
350 Print (L"\nUEFI-OpenSSL PKCS#7 Signing & Verification Testing: ");\r
351\r
352 Print (L"\n- Create PKCS#7 signedData ...");\r
353\r
354 //\r
355 // Construct Signer Certificate from RAW data.\r
356 //\r
357 Status = X509ConstructCertificate (TestCert, sizeof (TestCert), (UINT8 **) &SignCert);\r
358 if (!Status || SignCert == NULL) {\r
359 Print (L"[Fail]");\r
360 goto _Exit;\r
361 } else {\r
362 Print (L"[Pass]");\r
363 }\r
364\r
365 //\r
366 // Create PKCS#7 signedData on Payload. \r
367 // Note: Caller should release P7SignedData manually.\r
368 //\r
369 Status = Pkcs7Sign (\r
370 TestKeyPem,\r
371 sizeof (TestKeyPem),\r
372 (CONST UINT8 *) PemPass,\r
373 (UINT8 *) Payload,\r
374 AsciiStrLen (Payload),\r
375 SignCert,\r
376 NULL,\r
377 &P7SignedData,\r
378 &P7SignedDataSize\r
379 );\r
380 if (!Status || P7SignedDataSize == 0) {\r
381 Print (L"[Fail]");\r
382 goto _Exit;\r
383 } else {\r
384 Print (L"[Pass]");\r
385 }\r
386\r
387 Print (L"\n- Verify PKCS#7 signedData ...");\r
388\r
389 Status = Pkcs7Verify (\r
390 P7SignedData,\r
391 P7SignedDataSize,\r
392 TestCACert,\r
393 sizeof (TestCACert),\r
394 (UINT8 *) Payload,\r
395 AsciiStrLen (Payload)\r
396 );\r
397 if (!Status) {\r
398 Print (L"[Fail]");\r
399 } else {\r
400 Print (L"[Pass]");\r
401 }\r
402\r
403_Exit:\r
404 if (P7SignedData != NULL) {\r
405 FreePool (P7SignedData);\r
406 }\r
407 if (SignCert != NULL) {\r
408 X509Free (SignCert);\r
409 }\r
410\r
411 Print (L"\n");\r
412 return EFI_SUCCESS;\r
413}\r