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 #include <unistd.h> | 15 #include <unistd.h> |
16 | 16 |
| 17 #include "load_firmware_fw.h" |
17 #include "load_kernel_fw.h" | 18 #include "load_kernel_fw.h" |
18 #include "boot_device.h" | 19 #include "boot_device.h" |
| 20 #include "gbb_header.h" |
19 #include "host_common.h" | 21 #include "host_common.h" |
20 #include "rollback_index.h" | 22 #include "rollback_index.h" |
21 #include "utility.h" | 23 #include "utility.h" |
| 24 #include "vboot_common.h" |
22 #include "vboot_kernel.h" | 25 #include "vboot_kernel.h" |
23 | 26 |
24 #define LBA_BYTES 512 | 27 #define LBA_BYTES 512 |
25 #define KERNEL_BUFFER_SIZE 0xA00000 | 28 #define KERNEL_BUFFER_SIZE 0xA00000 |
26 | 29 |
27 /* Global variables for stub functions */ | 30 /* Global variables for stub functions */ |
28 static LoadKernelParams lkp; | 31 static LoadKernelParams lkp; |
29 static VbNvContext vnc; | 32 static VbNvContext vnc; |
30 static FILE *image_file = NULL; | 33 static FILE *image_file = NULL; |
31 | 34 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 return 1; | 73 return 1; |
71 } | 74 } |
72 return 0; | 75 return 0; |
73 } | 76 } |
74 | 77 |
75 | 78 |
76 /* Main routine */ | 79 /* Main routine */ |
77 int main(int argc, char* argv[]) { | 80 int main(int argc, char* argv[]) { |
78 | 81 |
79 const char* image_name; | 82 const char* image_name; |
| 83 uint64_t key_size; |
| 84 uint8_t* key_blob = NULL; |
| 85 VbSharedDataHeader* shared; |
| 86 GoogleBinaryBlockHeader* gbb; |
80 int rv, c, argsleft; | 87 int rv, c, argsleft; |
81 int errorcnt = 0; | 88 int errorcnt = 0; |
82 char *e = 0; | 89 char *e = 0; |
83 | 90 |
84 Memset(&lkp, 0, sizeof(LoadKernelParams)); | 91 Memset(&lkp, 0, sizeof(LoadKernelParams)); |
85 lkp.bytes_per_lba = LBA_BYTES; | 92 lkp.bytes_per_lba = LBA_BYTES; |
86 lkp.boot_flags = BOOT_FLAG_RECOVERY; | 93 lkp.boot_flags = BOOT_FLAG_RECOVERY; |
87 Memset(&vnc, 0, sizeof(VbNvContext)); | 94 Memset(&vnc, 0, sizeof(VbNvContext)); |
88 lkp.nv_context = &vnc; | 95 lkp.nv_context = &vnc; |
89 | 96 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 BOOT_FLAG_DEVELOPER); | 136 BOOT_FLAG_DEVELOPER); |
130 fprintf(stderr, " %" PRIu64 " = recovery mode on\n", | 137 fprintf(stderr, " %" PRIu64 " = recovery mode on\n", |
131 BOOT_FLAG_RECOVERY); | 138 BOOT_FLAG_RECOVERY); |
132 return 1; | 139 return 1; |
133 } | 140 } |
134 | 141 |
135 image_name = argv[optind]; | 142 image_name = argv[optind]; |
136 | 143 |
137 /* Read header signing key blob */ | 144 /* Read header signing key blob */ |
138 if (argsleft > 1) { | 145 if (argsleft > 1) { |
139 uint64_t key_size; | 146 key_blob = ReadFile(argv[optind+1], &key_size); |
140 lkp.header_sign_key_blob = ReadFile(argv[optind+1], &key_size); | 147 if (!key_blob) { |
141 if (!lkp.header_sign_key_blob) { | |
142 fprintf(stderr, "Unable to read key file %s\n", argv[optind+1]); | 148 fprintf(stderr, "Unable to read key file %s\n", argv[optind+1]); |
143 return 1; | 149 return 1; |
144 } | 150 } |
| 151 printf("Read %" PRIu64 " bytes of key from %s\n", key_size, argv[optind+1]); |
145 } | 152 } |
146 /* Need to skip the address check, since we're putting it somewhere on the | 153 |
| 154 /* Initialize the GBB */ |
| 155 lkp.gbb_size = sizeof(GoogleBinaryBlockHeader) + key_size; |
| 156 lkp.gbb_data = (void*)Malloc(lkp.gbb_size); |
| 157 gbb = (GoogleBinaryBlockHeader*)lkp.gbb_data; |
| 158 Memset(gbb, 0, lkp.gbb_size); |
| 159 Memcpy(gbb->signature, GBB_SIGNATURE, GBB_SIGNATURE_SIZE); |
| 160 gbb->major_version = GBB_MAJOR_VER; |
| 161 gbb->minor_version = GBB_MINOR_VER; |
| 162 gbb->header_size = sizeof(GoogleBinaryBlockHeader); |
| 163 /* Fill in the given key, if any, for both root and recovery */ |
| 164 if (key_blob) { |
| 165 gbb->rootkey_offset = gbb->header_size; |
| 166 gbb->rootkey_size = key_size; |
| 167 Memcpy((uint8_t*)gbb + gbb->rootkey_offset, key_blob, key_size); |
| 168 |
| 169 gbb->recovery_key_offset = gbb->rootkey_offset; |
| 170 gbb->recovery_key_size = key_size; |
| 171 } |
| 172 |
| 173 /* Initialize the shared data area */ |
| 174 lkp.shared_data_blob = Malloc(LOAD_FIRMWARE_SHARED_DATA_REC_SIZE); |
| 175 lkp.shared_data_size = LOAD_FIRMWARE_SHARED_DATA_REC_SIZE; |
| 176 shared = (VbSharedDataHeader*)lkp.shared_data_blob; |
| 177 if (0 != VbSharedDataInit(shared, lkp.shared_data_size)) { |
| 178 fprintf(stderr, "Unable to init shared data\n"); |
| 179 return 1; |
| 180 } |
| 181 /* Copy in the key blob, if any */ |
| 182 if (key_blob) { |
| 183 if (0 != VbSharedDataSetKernelKey(shared, (VbPublicKey*)key_blob)) { |
| 184 fprintf(stderr, "Unable to set key in shared data\n"); |
| 185 return 1; |
| 186 } |
| 187 } |
| 188 |
| 189 /* Free the key blob, now that we're done with it */ |
| 190 Free(key_blob); |
| 191 |
| 192 /* Needs to skip the address check, since we're putting it somewhere on the |
147 * heap instead of its actual target address in the firmware. */ | 193 * heap instead of its actual target address in the firmware. */ |
148 lkp.boot_flags |= BOOT_FLAG_SKIP_ADDR_CHECK; | 194 lkp.boot_flags |= BOOT_FLAG_SKIP_ADDR_CHECK; |
149 | 195 |
150 /* If the boot flags are for developer mode, non-recovery, add the dev-type | 196 /* If the boot flags are for developer mode, non-recovery, add the dev-type |
151 * firmware bit. LoadKernel() masks off the developer bit if the dev | 197 * firmware bit. LoadKernel() masks off the developer bit if the dev |
152 * firmware bit is absent, to keep normal firmware from verifying dev | 198 * firmware bit is absent, to keep normal firmware from verifying dev |
153 * kernels. */ | 199 * kernels. */ |
154 if ((lkp.boot_flags & BOOT_FLAG_DEVELOPER) | 200 if ((lkp.boot_flags & BOOT_FLAG_DEVELOPER) |
155 && !(lkp.boot_flags & BOOT_FLAG_RECOVERY)) { | 201 && !(lkp.boot_flags & BOOT_FLAG_RECOVERY)) { |
156 lkp.boot_flags |= BOOT_FLAG_DEV_FIRMWARE; | 202 lkp.boot_flags |= BOOT_FLAG_DEV_FIRMWARE; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 lkp.partition_guid[12], | 250 lkp.partition_guid[12], |
205 lkp.partition_guid[13], | 251 lkp.partition_guid[13], |
206 lkp.partition_guid[14], | 252 lkp.partition_guid[14], |
207 lkp.partition_guid[15]); | 253 lkp.partition_guid[15]); |
208 } | 254 } |
209 | 255 |
210 fclose(image_file); | 256 fclose(image_file); |
211 Free(lkp.kernel_buffer); | 257 Free(lkp.kernel_buffer); |
212 return rv != LOAD_KERNEL_SUCCESS; | 258 return rv != LOAD_KERNEL_SUCCESS; |
213 } | 259 } |
OLD | NEW |