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 // Utility for manipulating verified boot kernel images. | 5 // Utility for manipulating verified boot kernel images. |
6 // | 6 // |
7 | 7 |
8 #include "kernel_utility.h" | 8 #include "kernel_utility.h" |
9 | 9 |
10 #include <errno.h> | |
11 #include <getopt.h> | 10 #include <getopt.h> |
12 #include <stdio.h> | 11 #include <stdio.h> |
13 #include <stdint.h> // Needed for UINT16_MAX. | 12 #include <stdint.h> // Needed for UINT16_MAX. |
14 #include <stdlib.h> | 13 #include <stdlib.h> |
15 #include <unistd.h> | 14 #include <unistd.h> |
16 | 15 |
17 #include <iostream> | 16 #include <iostream> |
18 | 17 |
19 extern "C" { | 18 extern "C" { |
20 #include "cryptolib.h" | 19 #include "cryptolib.h" |
21 #include "file_keys.h" | 20 #include "file_keys.h" |
22 #include "kernel_image.h" | 21 #include "kernel_image.h" |
23 #include "utility.h" | 22 #include "utility.h" |
24 } | 23 } |
25 | 24 |
26 extern int errno; | |
27 using std::cerr; | 25 using std::cerr; |
28 | 26 |
29 namespace vboot_reference { | 27 namespace vboot_reference { |
30 | 28 |
31 KernelUtility::KernelUtility(): image_(NULL), | 29 KernelUtility::KernelUtility(): image_(NULL), |
32 firmware_key_pub_(NULL), | 30 firmware_key_pub_(NULL), |
33 header_version_(1), | 31 header_version_(1), |
34 firmware_sign_algorithm_(-1), | 32 firmware_sign_algorithm_(-1), |
35 kernel_sign_algorithm_(-1), | 33 kernel_sign_algorithm_(-1), |
36 kernel_key_version_(-1), | 34 kernel_key_version_(-1), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 case OPT_FIRMWARE_SIGN_ALGORITHM: | 151 case OPT_FIRMWARE_SIGN_ALGORITHM: |
154 firmware_sign_algorithm_ = strtol(optarg, &e, 0); | 152 firmware_sign_algorithm_ = strtol(optarg, &e, 0); |
155 if (!*optarg || (e && *e)) { | 153 if (!*optarg || (e && *e)) { |
156 cerr << "Invalid argument to --" | 154 cerr << "Invalid argument to --" |
157 << long_options[option_index].name | 155 << long_options[option_index].name |
158 << ": " << optarg << "\n"; | 156 << ": " << optarg << "\n"; |
159 return false; | 157 return false; |
160 } | 158 } |
161 break; | 159 break; |
162 case OPT_KERNEL_SIGN_ALGORITHM: | 160 case OPT_KERNEL_SIGN_ALGORITHM: |
163 errno = 0; | |
164 kernel_sign_algorithm_ = strtol(optarg, &e, 0); | 161 kernel_sign_algorithm_ = strtol(optarg, &e, 0); |
165 if (!*optarg || (e && *e)) { | 162 if (!*optarg || (e && *e)) { |
166 cerr << "Invalid argument to --" | 163 cerr << "Invalid argument to --" |
167 << long_options[option_index].name | 164 << long_options[option_index].name |
168 << ": " << optarg << "\n"; | 165 << ": " << optarg << "\n"; |
169 return false; | 166 return false; |
170 } | 167 } |
171 break; | 168 break; |
172 case OPT_KERNEL_KEY_VERSION: | 169 case OPT_KERNEL_KEY_VERSION: |
173 errno = 0; | |
174 kernel_key_version_ = strtol(optarg, &e, 0); | 170 kernel_key_version_ = strtol(optarg, &e, 0); |
175 if (!*optarg || (e && *e)) { | 171 if (!*optarg || (e && *e)) { |
176 cerr << "Invalid argument to --" | 172 cerr << "Invalid argument to --" |
177 << long_options[option_index].name | 173 << long_options[option_index].name |
178 << ": " << optarg << "\n"; | 174 << ": " << optarg << "\n"; |
179 return false; | 175 return false; |
180 } | 176 } |
181 break; | 177 break; |
182 case OPT_KERNEL_VERSION: | 178 case OPT_KERNEL_VERSION: |
183 errno = 0; | |
184 kernel_version_ = strtol(optarg, &e, 0); | 179 kernel_version_ = strtol(optarg, &e, 0); |
185 if (!*optarg || (e && *e)) { | 180 if (!*optarg || (e && *e)) { |
186 cerr << "Invalid argument to --" | 181 cerr << "Invalid argument to --" |
187 << long_options[option_index].name | 182 << long_options[option_index].name |
188 << ": " << optarg << "\n"; | 183 << ": " << optarg << "\n"; |
189 return false; | 184 return false; |
190 } | 185 } |
191 break; | 186 break; |
192 case OPT_IN: | 187 case OPT_IN: |
193 in_file_ = optarg; | 188 in_file_ = optarg; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 } | 415 } |
421 else if (ku.is_verify()) { | 416 else if (ku.is_verify()) { |
422 cerr << "Verification "; | 417 cerr << "Verification "; |
423 if (ku.VerifySignedImage()) | 418 if (ku.VerifySignedImage()) |
424 cerr << "SUCCESS.\n"; | 419 cerr << "SUCCESS.\n"; |
425 else | 420 else |
426 cerr << "FAILURE.\n"; | 421 cerr << "FAILURE.\n"; |
427 } | 422 } |
428 return 0; | 423 return 0; |
429 } | 424 } |
OLD | NEW |