| 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 * Tests for firmware image library. | 5 * Tests for firmware image 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 "cryptolib.h" | 11 #include "cryptolib.h" |
| 12 #include "file_keys.h" | 12 #include "file_keys.h" |
| 13 #include "firmware_image.h" | 13 #include "firmware_image.h" |
| 14 #include "test_common.h" | 14 #include "test_common.h" |
| 15 #include "utility.h" | 15 #include "utility.h" |
| 16 | 16 |
| 17 /* Normal Firmware Blob Verification Tests. */ | 17 /* Normal Firmware Blob Verification Tests. */ |
| 18 void VerifyFirmwareTest(uint8_t* firmware_blob, uint8_t* root_key_blob) { | 18 void VerifyFirmwareTest(uint8_t* verification_header, |
| 19 TEST_EQ(VerifyFirmware(root_key_blob, firmware_blob), | 19 uint8_t* firmware_data, |
| 20 uint8_t* root_key_blob) { |
| 21 TEST_EQ(VerifyFirmware(root_key_blob, |
| 22 verification_header, |
| 23 firmware_data), |
| 20 VERIFY_FIRMWARE_SUCCESS, | 24 VERIFY_FIRMWARE_SUCCESS, |
| 21 "Normal Firmware Blob Verification"); | 25 "Normal Firmware Blob Verification"); |
| 22 } | 26 } |
| 23 | 27 |
| 24 /* Normal FirmwareImage Verification Tests. */ | 28 /* Normal FirmwareImage Verification Tests. */ |
| 25 void VerifyFirmwareImageTest(FirmwareImage* image, | 29 void VerifyFirmwareImageTest(FirmwareImage* image, |
| 26 RSAPublicKey* root_key) { | 30 RSAPublicKey* root_key) { |
| 27 TEST_EQ(VerifyFirmwareImage(root_key, image), | 31 TEST_EQ(VerifyFirmwareImage(root_key, image), |
| 28 VERIFY_FIRMWARE_SUCCESS, | 32 VERIFY_FIRMWARE_SUCCESS, |
| 29 "Normal FirmwareImage Verification"); | 33 "Normal FirmwareImage Verification"); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 firmware_key_file, | 89 firmware_key_file, |
| 86 'F'); | 90 'F'); |
| 87 | 91 |
| 88 if (!root_key_pub || !firmware_sign_key_buf || !image) { | 92 if (!root_key_pub || !firmware_sign_key_buf || !image) { |
| 89 error_code = 1; | 93 error_code = 1; |
| 90 goto failure; | 94 goto failure; |
| 91 } | 95 } |
| 92 firmware_blob = GetFirmwareBlob(image, &firmware_blob_len); | 96 firmware_blob = GetFirmwareBlob(image, &firmware_blob_len); |
| 93 | 97 |
| 94 /* Test Firmware blob verify operations. */ | 98 /* Test Firmware blob verify operations. */ |
| 95 VerifyFirmwareTest(firmware_blob, root_key_blob); | 99 VerifyFirmwareTest(firmware_blob, |
| 100 image->firmware_data, |
| 101 root_key_blob); |
| 96 | 102 |
| 97 /* Test FirmwareImage verify operations. */ | 103 /* Test FirmwareImage verify operations. */ |
| 98 VerifyFirmwareImageTest(image, root_key_pub); | 104 VerifyFirmwareImageTest(image, root_key_pub); |
| 99 VerifyFirmwareImageTamperTest(image, root_key_pub); | 105 VerifyFirmwareImageTamperTest(image, root_key_pub); |
| 100 | 106 |
| 101 if (!gTestSuccess) | 107 if (!gTestSuccess) |
| 102 error_code = 255; | 108 error_code = 255; |
| 103 | 109 |
| 104 failure: | 110 failure: |
| 105 Free(firmware_blob); | 111 Free(firmware_blob); |
| 106 FirmwareImageFree(image); | 112 FirmwareImageFree(image); |
| 107 Free(firmware_sign_key_buf); | 113 Free(firmware_sign_key_buf); |
| 108 Free(root_key_blob); | 114 Free(root_key_blob); |
| 109 RSAPublicKeyFree(root_key_pub); | 115 RSAPublicKeyFree(root_key_pub); |
| 110 | 116 |
| 111 return error_code; | 117 return error_code; |
| 112 } | 118 } |
| OLD | NEW |