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 | 5 |
6 /* Routines for verifying a file's signature. Useful in testing the core | 6 /* Routines for verifying a file's signature. Useful in testing the core |
7 * RSA verification implementation. | 7 * RSA verification implementation. |
8 */ | 8 */ |
9 | 9 |
10 #include <inttypes.h> /* For PRIu64 macro */ | 10 #include <inttypes.h> /* For PRIu64 macro */ |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <string.h> | 13 #include <string.h> |
14 #include <sys/types.h> | 14 #include <sys/types.h> |
15 | 15 |
16 #include "load_kernel_fw.h" | 16 #include "load_kernel_fw.h" |
17 #include "boot_device.h" | 17 #include "boot_device.h" |
| 18 #include "host_common.h" |
18 #include "rollback_index.h" | 19 #include "rollback_index.h" |
19 #include "utility.h" | 20 #include "utility.h" |
20 | 21 |
21 /* ANSI Color coding sequences. */ | 22 /* ANSI Color coding sequences. */ |
22 #define COL_GREEN "\e[1;32m" | 23 #define COL_GREEN "\e[1;32m" |
23 #define COL_RED "\e[0;31m" | 24 #define COL_RED "\e[0;31m" |
24 #define COL_STOP "\e[m" | 25 #define COL_STOP "\e[m" |
25 | 26 |
26 | 27 |
27 #define LBA_BYTES 512 | 28 #define LBA_BYTES 512 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 /* Read command line parameters */ | 89 /* Read command line parameters */ |
89 if (3 > argc) { | 90 if (3 > argc) { |
90 fprintf(stderr, "usage: %s <drive_image> <sign_key>\n", argv[0]); | 91 fprintf(stderr, "usage: %s <drive_image> <sign_key>\n", argv[0]); |
91 return 1; | 92 return 1; |
92 } | 93 } |
93 image_name = argv[1]; | 94 image_name = argv[1]; |
94 keyfile_name = argv[2]; | 95 keyfile_name = argv[2]; |
95 | 96 |
96 /* Read header signing key blob */ | 97 /* Read header signing key blob */ |
97 { | 98 { |
98 FILE* f; | 99 uint64_t key_size; |
99 int key_size; | 100 lkp.header_sign_key_blob = ReadFile(keyfile_name, &key_size); |
100 printf("Reading key from: %s\n", keyfile_name); | 101 if (!lkp.header_sign_key_blob) |
101 f = fopen(keyfile_name, "rb"); | 102 fprintf(stderr, "Unable to read key file %s\n", keyfile_name); |
102 if (!f) { | |
103 fprintf(stderr, "Unable to open key file %s\n", keyfile_name); | |
104 return 1; | 103 return 1; |
105 } | 104 } |
106 fseek(f, 0, SEEK_END); | |
107 key_size = ftell(f); | |
108 rewind(f); | |
109 lkp.header_sign_key_blob = Malloc(key_size); | |
110 printf("Reading %d bytes of key\n", key_size); | |
111 if (fread(lkp.header_sign_key_blob, key_size, 1, f) != 1) { | |
112 fprintf(stderr, "Unable to read key data\n"); | |
113 return 1; | |
114 } | |
115 fclose(f); | |
116 } | |
117 | 105 |
118 /* Get image size */ | 106 /* Get image size */ |
119 printf("Reading from image: %s\n", image_name); | 107 printf("Reading from image: %s\n", image_name); |
120 image_file = fopen(image_name, "rb"); | 108 image_file = fopen(image_name, "rb"); |
121 if (!image_file) { | 109 if (!image_file) { |
122 fprintf(stderr, "Unable to open image file %s\n", image_name); | 110 fprintf(stderr, "Unable to open image file %s\n", image_name); |
123 return 1; | 111 return 1; |
124 } | 112 } |
125 fseek(image_file, 0, SEEK_END); | 113 fseek(image_file, 0, SEEK_END); |
126 lkp.ending_lba = (ftell(image_file) / LBA_BYTES) - 1; | 114 lkp.ending_lba = (ftell(image_file) / LBA_BYTES) - 1; |
(...skipping 17 matching lines...) Expand all Loading... |
144 if (LOAD_KERNEL_SUCCESS == rv) { | 132 if (LOAD_KERNEL_SUCCESS == rv) { |
145 printf("Partition number: %" PRIu64 "\n", lkp.partition_number); | 133 printf("Partition number: %" PRIu64 "\n", lkp.partition_number); |
146 printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address); | 134 printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address); |
147 printf("Bootloader size: %" PRIu64 "\n", lkp.bootloader_size); | 135 printf("Bootloader size: %" PRIu64 "\n", lkp.bootloader_size); |
148 } | 136 } |
149 | 137 |
150 fclose(image_file); | 138 fclose(image_file); |
151 Free(lkp.kernel_buffer); | 139 Free(lkp.kernel_buffer); |
152 return 0; | 140 return 0; |
153 } | 141 } |
OLD | NEW |