| 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 kernel image verification library. | 5 * Splicing tests for the kernel 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 "kernel_image.h" | 12 #include "kernel_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 FIRMWARE_KEY_BASE_NAME "testkeys/key_rsa2048" |
| 19 #define KERNEL_KEY_BASE_NAME "testkeys/key_rsa1024" |
| 20 |
| 21 const char* kFirmwareKeyPublicFile = FIRMWARE_KEY_BASE_NAME ".keyb"; |
| 22 const char* kFirmwareKeyFile = FIRMWARE_KEY_BASE_NAME ".pem"; |
| 23 const char* kKernelKeyPublicFile = KERNEL_KEY_BASE_NAME ".keyb"; |
| 24 const char* kKernelKeyFile = KERNEL_KEY_BASE_NAME ".pem"; |
| 25 |
| 18 void VerifyKernelSplicingTest() | 26 void VerifyKernelSplicingTest() |
| 19 { | 27 { |
| 20 uint64_t len; | 28 uint64_t len; |
| 21 KernelImage* image1 = NULL; | 29 KernelImage* image1 = NULL; |
| 22 KernelImage* image2 = NULL; | 30 KernelImage* image2 = NULL; |
| 23 uint8_t* kernel_blob = NULL; | 31 uint8_t* kernel_blob = NULL; |
| 24 uint8_t* kernel_sign_key_buf = NULL; | 32 uint8_t* kernel_sign_key_buf = NULL; |
| 25 RSAPublicKey* firmware_key = | 33 RSAPublicKey* firmware_key = RSAPublicKeyFromFile(kFirmwareKeyPublicFile); |
| 26 RSAPublicKeyFromFile("testkeys/key_rsa2048.keyb"); | 34 uint8_t* firmware_key_blob = BufferFromFile(kFirmwareKeyPublicFile, &len); |
| 27 uint8_t* firmware_key_blob = BufferFromFile("testkeys/key_rsa2048.keyb", | 35 kernel_sign_key_buf= BufferFromFile(kKernelKeyPublicFile, &len); |
| 28 &len); | |
| 29 kernel_sign_key_buf= BufferFromFile("testkeys/key_rsa1024.keyb", &len); | |
| 30 image1 = GenerateTestKernelImage(3, /* RSA2048/SHA1 */ | 36 image1 = GenerateTestKernelImage(3, /* RSA2048/SHA1 */ |
| 31 0, /* RSA1024/SHA1 */ | 37 0, /* RSA1024/SHA1 */ |
| 32 kernel_sign_key_buf, | 38 kernel_sign_key_buf, |
| 33 1, /* Kernel Key Version. */ | 39 1, /* Kernel Key Version. */ |
| 34 1, /* Kernel Version */ | 40 1, /* Kernel Version */ |
| 35 1000, /* Kernel Size. */ | 41 1000, /* Kernel Size. */ |
| 36 "testkeys/key_rsa2048.pem", | 42 kFirmwareKeyFile, |
| 37 "testkeys/key_rsa1024.pem", | 43 kKernelKeyFile, |
| 38 (uint8_t) 'K'); /* Kernel data fill. */ | 44 'K'); /* Kernel data fill. */ |
| 39 image2 = GenerateTestKernelImage(3, /* RSA2058/SHA1 */ | 45 image2 = GenerateTestKernelImage(3, /* RSA2058/SHA1 */ |
| 40 0, /* RSA1024/SHA1 */ | 46 0, /* RSA1024/SHA1 */ |
| 41 kernel_sign_key_buf, | 47 kernel_sign_key_buf, |
| 42 1, /* Kernel Key Version. */ | 48 1, /* Kernel Key Version. */ |
| 43 2, /* Kernel Version */ | 49 2, /* Kernel Version */ |
| 44 1000, /* Kernel Size */ | 50 1000, /* Kernel Size */ |
| 45 "testkeys/key_rsa2048.pem", | 51 kFirmwareKeyFile, |
| 46 "testkeys/key_rsa1024.pem", | 52 kKernelKeyFile, |
| 47 (uint8_t) 'K'); /* Kernel data fill. */ | 53 'L'); /* Different Kernel data fill. */ |
| 48 /* Make sure the originals verify. */ | 54 /* Make sure the originals verify. */ |
| 49 TEST_EQ(VerifyKernelImage(firmware_key, image1, 0), | 55 TEST_EQ(VerifyKernelImage(firmware_key, image1, 0), |
| 50 VERIFY_KERNEL_SUCCESS, | 56 VERIFY_KERNEL_SUCCESS, |
| 51 "KernelImage kernel_data Original"); | 57 "KernelImage kernel_data Original"); |
| 52 TEST_EQ(VerifyKernelImage(firmware_key, image2, 0), | 58 TEST_EQ(VerifyKernelImage(firmware_key, image2, 0), |
| 53 VERIFY_KERNEL_SUCCESS, | 59 VERIFY_KERNEL_SUCCESS, |
| 54 "KernelImage kernel_data Original"); | 60 "KernelImage kernel_data Original"); |
| 55 | 61 |
| 56 /* Splice kernel_data + kernel signature from [image1] | 62 /* Splice kernel_data + kernel signature from [image1] |
| 57 * and put it into [image2]. */ | 63 * and put it into [image2]. */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 } | 76 } |
| 71 | 77 |
| 72 int main(int argc, char* argv[]) | 78 int main(int argc, char* argv[]) |
| 73 { | 79 { |
| 74 int error_code = 0; | 80 int error_code = 0; |
| 75 VerifyKernelSplicingTest(); | 81 VerifyKernelSplicingTest(); |
| 76 if (!gTestSuccess) | 82 if (!gTestSuccess) |
| 77 error_code = 255; | 83 error_code = 255; |
| 78 return error_code; | 84 return error_code; |
| 79 } | 85 } |
| OLD | NEW |