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 * Tests if firmware image library deals with very large firmware. This |
| 6 * is a quick and dirty test for detecting integer overflow issues. |
| 7 */ |
| 8 |
| 9 #include <stdio.h> |
| 10 #include <stdlib.h> |
| 11 |
| 12 #include "file_keys.h" |
| 13 #include "kernel_image.h" |
| 14 #include "rsa_utility.h" |
| 15 #include "test_common.h" |
| 16 #include "utility.h" |
| 17 |
| 18 /* Choose a kernel size greater than the range of 32-bits unsigned. */ |
| 19 #define BIG_KERNEL_SIZE ((uint64_t) 0x100000000) |
| 20 |
| 21 #define FIRMWARE_KEY_BASE_NAME "testkeys/key_rsa2048" |
| 22 #define KERNEL_KEY_BASE_NAME "testkeys/key_rsa1024" |
| 23 |
| 24 const char* kFirmwareKeyPublicFile = FIRMWARE_KEY_BASE_NAME ".keyb"; |
| 25 const char* kFirmwareKeyFile = FIRMWARE_KEY_BASE_NAME ".pem"; |
| 26 const char* kKernelKeyPublicFile = KERNEL_KEY_BASE_NAME ".keyb"; |
| 27 const char* kKernelKeyFile = KERNEL_KEY_BASE_NAME ".pem"; |
| 28 |
| 29 int BigKernelTest() { |
| 30 int error_code = 0; |
| 31 uint64_t len; |
| 32 uint8_t* kernel_blob = NULL; |
| 33 RSAPublicKey* firmware_key = RSAPublicKeyFromFile(kFirmwareKeyPublicFile); |
| 34 uint8_t* firmware_key_blob = BufferFromFile(kFirmwareKeyPublicFile, &len); |
| 35 uint8_t* kernel_sign_key_buf = BufferFromFile(kKernelKeyPublicFile, &len); |
| 36 fprintf(stderr, "Generating Big KernelImage..."); |
| 37 KernelImage* image = |
| 38 GenerateTestKernelImage(3, /* RSA2048/SHA1 */ |
| 39 0, /* RSA1024/SHA1 */ |
| 40 kernel_sign_key_buf, |
| 41 1, /* Kernel Key Version. */ |
| 42 1, /* Kernel Version */ |
| 43 BIG_KERNEL_SIZE, |
| 44 kFirmwareKeyFile, |
| 45 kKernelKeyFile, |
| 46 'K'); /* Kernel Data Fill. */ |
| 47 if (!firmware_key || !firmware_key_blob || !kernel_sign_key_buf || !image) { |
| 48 error_code = 1; |
| 49 goto cleanup; |
| 50 } |
| 51 fprintf(stderr, "Done.\n"); |
| 52 TEST_EQ(VerifyKernelImage(firmware_key, image, 0), |
| 53 VERIFY_FIRMWARE_SUCCESS, |
| 54 "Big KernelImage Verification"); |
| 55 kernel_blob = GetKernelBlob(image, &len); |
| 56 TEST_EQ(VerifyKernel(firmware_key_blob, kernel_blob, 0), |
| 57 VERIFY_FIRMWARE_SUCCESS, |
| 58 "Big Kernel Blob Verification"); |
| 59 |
| 60 cleanup: |
| 61 Free(kernel_blob); |
| 62 KernelImageFree(image); |
| 63 Free(kernel_sign_key_buf); |
| 64 Free(firmware_key_blob); |
| 65 RSAPublicKeyFree(firmware_key); |
| 66 return error_code; |
| 67 } |
| 68 |
| 69 int main(int argc, char* argv[1]) |
| 70 { |
| 71 int error_code = 0; |
| 72 error_code = BigKernelTest(); |
| 73 if (!gTestSuccess) |
| 74 error_code = 255; |
| 75 return error_code; |
| 76 } |
OLD | NEW |