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 * Utility for aiding fuzz testing of kernel image verification code. |
| 6 */ |
| 7 |
| 8 #include <stdio.h> |
| 9 |
| 10 #include "file_keys.h" |
| 11 #include "kernel_image.h" |
| 12 #include "utility.h" |
| 13 |
| 14 int VerifySignedKernel(const char* image_file, |
| 15 const char* firmware_key_file) { |
| 16 int error, error_code = 0; |
| 17 uint64_t len; |
| 18 uint8_t* kernel_blob = BufferFromFile(image_file, &len); |
| 19 uint8_t* firmware_key_blob = BufferFromFile(firmware_key_file, &len); |
| 20 |
| 21 if (!firmware_key_blob) { |
| 22 fprintf(stderr, "Couldn't read pre-processed public firmware key.\n"); |
| 23 error_code = 1; |
| 24 } |
| 25 |
| 26 if (!error_code && !kernel_blob) { |
| 27 fprintf(stderr, "Couldn't read kernel image or malformed image.\n"); |
| 28 error_code = 1; |
| 29 } |
| 30 |
| 31 if (!error_code && (error = VerifyKernel(firmware_key_blob, kernel_blob, |
| 32 0))) { /* Trusted Mode. */ |
| 33 fprintf(stderr, "%s\n", VerifyKernelErrorString(error)); |
| 34 error_code = 1; |
| 35 } |
| 36 Free(firmware_key_blob); |
| 37 Free(kernel_blob); |
| 38 if (error_code) |
| 39 return 0; |
| 40 return 1; |
| 41 } |
| 42 |
| 43 int main(int argc, char* argv[]) { |
| 44 if (argc != 3) { |
| 45 fprintf(stderr, "Usage: %s <image_to_verify> <firmware_keyb>\n", argv[0]); |
| 46 return -1; |
| 47 } |
| 48 if (VerifySignedKernel(argv[1], argv[2])) { |
| 49 fprintf(stderr, "Verification SUCCESS!\n"); |
| 50 return 0; |
| 51 } |
| 52 else { |
| 53 fprintf(stderr, "Verification FAILURE!\n"); |
| 54 return -1; |
| 55 } |
| 56 } |
OLD | NEW |