Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: src/platform/vboot_reference/tests/test_common.c

Issue 1578035: Change VerifyFirmware() to take separate pointers to firmware verification header and firmware data. (Closed)
Patch Set: review fixes Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Common functions used by tests. 5 * Common functions used by tests.
6 */ 6 */
7 7
8 #include "test_common.h" 8 #include "test_common.h"
9 9
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 if (!AddFirmwareSignature(image, firmware_key_file)) { 75 if (!AddFirmwareSignature(image, firmware_key_file)) {
76 debug("Couldn't create firmware and preamble signature.\n"); 76 debug("Couldn't create firmware and preamble signature.\n");
77 FirmwareImageFree(image); 77 FirmwareImageFree(image);
78 return NULL; 78 return NULL;
79 } 79 }
80 return image; 80 return image;
81 } 81 }
82 82
83 uint8_t* GenerateTestFirmwareBlob(int algorithm, 83 uint8_t* GenerateTestVerificationBlob(int algorithm,
84 const uint8_t* firmware_sign_key, 84 const uint8_t* firmware_sign_key,
85 int firmware_key_version, 85 int firmware_key_version,
86 int firmware_version, 86 int firmware_version,
87 uint64_t firmware_len, 87 uint64_t firmware_len,
88 const char* root_key_file, 88 const char* root_key_file,
89 const char* firmware_key_file) { 89 const char* firmware_key_file) {
90 FirmwareImage* image = NULL; 90 FirmwareImage* image = NULL;
91 uint8_t* firmware_blob = NULL; 91 uint8_t* firmware_blob = NULL;
92 uint64_t firmware_blob_len = 0; 92 uint64_t firmware_blob_len = 0;
93 93
94 image = GenerateTestFirmwareImage(algorithm, 94 image = GenerateTestFirmwareImage(algorithm,
95 firmware_sign_key, 95 firmware_sign_key,
96 firmware_key_version, 96 firmware_key_version,
97 firmware_version, 97 firmware_version,
98 firmware_len, 98 firmware_len,
99 root_key_file, 99 root_key_file,
100 firmware_key_file, 100 firmware_key_file,
101 'F'); 101 'F');
102 firmware_blob = GetFirmwareBlob(image, &firmware_blob_len); 102 firmware_blob = GetFirmwareBlob(image, &firmware_blob_len);
103 FirmwareImageFree(image); 103 FirmwareImageFree(image);
104 return firmware_blob; 104 return firmware_blob;
105 } 105 }
106 106
107 uint8_t* GenerateRollbackTestFirmwareBlob(int firmware_key_version, 107 uint8_t* GenerateRollbackTestVerificationBlob(int firmware_key_version,
108 int firmware_version, 108 int firmware_version) {
109 int is_corrupt) {
110 FirmwareImage* image = NULL; 109 FirmwareImage* image = NULL;
111 uint64_t len; 110 uint64_t len;
112 uint8_t* firmware_blob = NULL; 111 uint8_t* verification_blob = NULL;
113 uint8_t* firmware_sign_key = NULL; 112 uint8_t* firmware_sign_key = NULL;
114 113
115 firmware_sign_key = BufferFromFile("testkeys/key_rsa1024.keyb", 114 firmware_sign_key = BufferFromFile("testkeys/key_rsa1024.keyb",
116 &len); 115 &len);
117 if (!firmware_sign_key) 116 if (!firmware_sign_key)
118 return NULL; 117 return NULL;
119 image = GenerateTestFirmwareImage(0, /* RSA1024/SHA1 */ 118 image = GenerateTestFirmwareImage(0, /* RSA1024/SHA1 */
120 firmware_sign_key, 119 firmware_sign_key,
121 firmware_key_version, 120 firmware_key_version,
122 firmware_version, 121 firmware_version,
123 1, /* Firmware length. */ 122 1, /* Firmware length. */
124 "testkeys/key_rsa8192.pem", 123 "testkeys/key_rsa8192.pem",
125 "testkeys/key_rsa1024.pem", 124 "testkeys/key_rsa1024.pem",
126 'F'); 125 'F');
127 if (!image) 126 if (!image)
128 return NULL; 127 return NULL;
129 if (is_corrupt) { 128 verification_blob = GetFirmwareBlob(image, &len);
130 /* Invalidate image. */
131 Memset(image->firmware_data, 'X', image->firmware_len);
132 }
133
134 firmware_blob = GetFirmwareBlob(image, &len);
135 FirmwareImageFree(image); 129 FirmwareImageFree(image);
136 return firmware_blob; 130 return verification_blob;
137 } 131 }
138 132
139 133
140 KernelImage* GenerateTestKernelImage(int firmware_sign_algorithm, 134 KernelImage* GenerateTestKernelImage(int firmware_sign_algorithm,
141 int kernel_sign_algorithm, 135 int kernel_sign_algorithm,
142 const uint8_t* kernel_sign_key, 136 const uint8_t* kernel_sign_key,
143 int kernel_key_version, 137 int kernel_key_version,
144 int kernel_version, 138 int kernel_version,
145 uint64_t kernel_len, 139 uint64_t kernel_len,
146 const char* firmware_key_file, 140 const char* firmware_key_file,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (!image) 236 if (!image)
243 return NULL; 237 return NULL;
244 if (is_corrupt) { 238 if (is_corrupt) {
245 /* Invalidate image. */ 239 /* Invalidate image. */
246 Memset(image->kernel_data, 'X', image->options.kernel_len); 240 Memset(image->kernel_data, 'X', image->options.kernel_len);
247 } 241 }
248 kernel_blob = GetKernelBlob(image, &len); 242 kernel_blob = GetKernelBlob(image, &len);
249 KernelImageFree(image); 243 KernelImageFree(image);
250 return kernel_blob; 244 return kernel_blob;
251 } 245 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/tests/test_common.h ('k') | src/platform/vboot_reference/tests/verify_firmware_fuzz_driver.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698