OLD | NEW |
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 * Splicing tests for the firmware image verification library. | 5 * Splicing tests for the firmware image verification library. |
6 */ | 6 */ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
11 #include "file_keys.h" | 11 #include "file_keys.h" |
12 #include "firmware_image.h" | 12 #include "firmware_image.h" |
13 #include "padding.h" | 13 #include "padding.h" |
14 #include "rsa_utility.h" | 14 #include "rsa_utility.h" |
15 #include "test_common.h" | 15 #include "test_common.h" |
16 #include "utility.h" | 16 #include "utility.h" |
17 | 17 |
| 18 #define ROOT_KEY_BASE_NAME "testkeys/key_rsa8192" |
| 19 #define FIRMWARE_KEY_BASE_NAME "testkeys/key_rsa1024" |
| 20 |
| 21 const char* kRootKeyPublicFile = ROOT_KEY_BASE_NAME ".keyb"; |
| 22 const char* kRootKeyFile = ROOT_KEY_BASE_NAME ".pem"; |
| 23 const char* kFirmwareKeyPublicFile = FIRMWARE_KEY_BASE_NAME ".keyb"; |
| 24 const char* kFirmwareKeyFile = FIRMWARE_KEY_BASE_NAME ".pem"; |
| 25 |
18 void VerifyFirmwareSplicingTest() | 26 void VerifyFirmwareSplicingTest() |
19 { | 27 { |
20 uint64_t len; | 28 uint64_t len; |
21 FirmwareImage* image1 = NULL; | 29 FirmwareImage* image1 = NULL; |
22 FirmwareImage* image2 = NULL; | 30 FirmwareImage* image2 = NULL; |
23 uint8_t* firmware_blob = NULL; | 31 uint8_t* firmware_blob = NULL; |
24 uint8_t* firmware_sign_key_buf = NULL; | 32 uint8_t* firmware_sign_key_buf = NULL; |
25 RSAPublicKey* root_key = RSAPublicKeyFromFile("testkeys/key_rsa8192.keyb"); | 33 RSAPublicKey* root_key = RSAPublicKeyFromFile(kRootKeyPublicFile); |
26 uint8_t* root_key_blob = BufferFromFile("testkeys/key_rsa8192.keyb", | 34 uint8_t* root_key_blob = BufferFromFile(kRootKeyPublicFile, &len); |
27 &len); | 35 firmware_sign_key_buf= BufferFromFile(kFirmwareKeyPublicFile, &len); |
28 firmware_sign_key_buf= BufferFromFile("testkeys/key_rsa1024.keyb", &len); | |
29 image1 = GenerateTestFirmwareImage(0, /* RSA1024/SHA1 */ | 36 image1 = GenerateTestFirmwareImage(0, /* RSA1024/SHA1 */ |
30 firmware_sign_key_buf, | 37 firmware_sign_key_buf, |
31 1, /* Firmware Key Version. */ | 38 1, /* Firmware Key Version. */ |
32 1, /* Firmware Version */ | 39 1, /* Firmware Version */ |
33 1000, | 40 1000, |
34 "testkeys/key_rsa8192.pem", | 41 kRootKeyFile, |
35 "testkeys/key_rsa1024.pem", | 42 kFirmwareKeyFile, |
36 (uint8_t) 'F'); /* Firmware data fill. */ | 43 'F'); /* Firmware data fill. */ |
37 image2 = GenerateTestFirmwareImage(0, /* RSA1024/SHA1 */ | 44 image2 = GenerateTestFirmwareImage(0, /* RSA1024/SHA1 */ |
38 firmware_sign_key_buf, | 45 firmware_sign_key_buf, |
39 1, /* Firmware Key Version. */ | 46 1, /* Firmware Key Version. */ |
40 2, /* Firmware Version */ | 47 2, /* Firmware Version */ |
41 1000, | 48 1000, |
42 "testkeys/key_rsa8192.pem", | 49 kRootKeyFile, |
43 "testkeys/key_rsa1024.pem", | 50 kFirmwareKeyFile, |
44 (uint8_t) 'G'); /* Firmware data fill. */ | 51 'G'); /* Different Firmware data fill. */ |
45 /* Verify that the originals verify. */ | 52 /* Verify that the originals verify. */ |
46 TEST_EQ(VerifyFirmwareImage(root_key, image1), | 53 TEST_EQ(VerifyFirmwareImage(root_key, image1), |
47 VERIFY_FIRMWARE_SUCCESS, | 54 VERIFY_FIRMWARE_SUCCESS, |
48 "FirmwareImage firmware_data Original"); | 55 "FirmwareImage firmware_data Original"); |
49 TEST_EQ(VerifyFirmwareImage(root_key, image2), | 56 TEST_EQ(VerifyFirmwareImage(root_key, image2), |
50 VERIFY_FIRMWARE_SUCCESS, | 57 VERIFY_FIRMWARE_SUCCESS, |
51 "FirmwareImage firmware_data Original"); | 58 "FirmwareImage firmware_data Original"); |
52 | 59 |
53 /* Splice firmware_data + firmware signature from [image1] | 60 /* Splice firmware_data + firmware signature from [image1] |
54 * and put it into [image2]. */ | 61 * and put it into [image2]. */ |
(...skipping 12 matching lines...) Expand all Loading... |
67 } | 74 } |
68 | 75 |
69 int main(int argc, char* argv[]) | 76 int main(int argc, char* argv[]) |
70 { | 77 { |
71 int error_code = 0; | 78 int error_code = 0; |
72 VerifyFirmwareSplicingTest(); | 79 VerifyFirmwareSplicingTest(); |
73 if (!gTestSuccess) | 80 if (!gTestSuccess) |
74 error_code = 255; | 81 error_code = 255; |
75 return error_code; | 82 return error_code; |
76 } | 83 } |
OLD | NEW |