blob: 1cb7f1ae501a0749b36fba1e32855621c6f4d8d7 [file] [log] [blame]
Gaurav Shah80d129b2010-03-03 17:58:43 -08001// 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#ifndef VBOOT_REFERENCE_KERNEL_UTILITY_H_
6#define VBOOT_REFERENCE_KERNEL_UTILITY_H_
7
8#include <string>
9
10extern "C" {
11#include "kernel_image.h"
12}
13
14struct RSAPublicKey;
15
16namespace vboot_reference {
17
18// A class for handling verified boot kernel images.
19class KernelUtility {
20 public:
21 KernelUtility();
22 ~KernelUtility();
23
24 // Print usage to stderr.
25 void PrintUsage(void);
26
27 // Parse command line options and populate data members.
28 // Return true on success, false on failure.
29 bool ParseCmdLineOptions(int argc, char* argv[]);
30
Gaurav Shah528a2c12010-03-18 13:10:10 -070031 // Print description of a verified boot kernel image.
32 void DescribeSignedImage();
33
Gaurav Shah80d129b2010-03-03 17:58:43 -080034 // Generate a verified boot image by reading kernel data from in_file_.
35 // Return true on success, false on failure.
36 bool GenerateSignedImage();
37
38 // Verify a previously generated signed firmware image using the key read
39 // from [firmware_key_pub_file_].
40 bool VerifySignedImage();
41
42 // Output the verified boot kernel image to out_file_.
43 void OutputSignedImage();
44
45 bool is_generate() { return is_generate_; }
46 bool is_verify() { return is_verify_; }
Gaurav Shah528a2c12010-03-18 13:10:10 -070047 bool is_describe() { return is_describe_; }
Gaurav Shah80d129b2010-03-03 17:58:43 -080048
49 private:
50
51 // Check if all options were specified and sane.
52 // Return true on success, false on failure.
53 bool CheckOptions();
54
55 KernelImage* image_;
56 RSAPublicKey* firmware_key_pub_; // Root key used for verification.
57 std::string firmware_key_file_; // Private key for signing the kernel key.
58 std::string firmware_key_pub_file_;
59 std::string kernel_key_file_; // Private key for signing the kernel.
60 std::string kernel_key_pub_file_;
61
62 // Fields of a KernelImage. (read from the command line).
63 int header_version_;
64 int firmware_sign_algorithm_;
65 int kernel_sign_algorithm_;
66 int kernel_key_version_;
67 int kernel_version_;
68 kconfig_options options_;
69
70 std::string in_file_;
71 std::string out_file_;
72 bool is_generate_; // Are we generating a new image?
73 bool is_verify_; // Are we just verifying an already signed image?
Gaurav Shah528a2c12010-03-18 13:10:10 -070074 bool is_describe_; // Should we print out description of the image?
Gaurav Shah80d129b2010-03-03 17:58:43 -080075};
76
77} // namespace vboot_reference
78
79#endif // VBOOT_REFERENCE_FIRMWARE_UTILITY_H_