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