Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: utility/sign_image.c

Issue 2815011: Remove unused files, and tidy the directory structure of the remaining ones. (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « utility/load_kernel_test_old.c ('k') | vkernel/Makefile » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 signing boot firmware images.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 #include "file_keys.h"
13 #include "utility.h"
14 #include "host_key.h"
15 #include "host_signature.h"
16 #include "host_common.h"
17
18 static void usage()
19 {
20 static char* help_mesg =
21 "Usage: sign_image <fw_version> <fw_key_block> <signing_key> "
22 "<kernel_public_key> <firmware_file> <output_file>\n";
23 printf("%s", help_mesg);
24 }
25
26 int SignAndWriteImage(uint64_t fw_version, VbKeyBlockHeader* wrapper_kb,
27 VbPrivateKey* signing_key,
28 VbPublicKey* nested_pubkey,
29 uint8_t* image, uint64_t image_size,
30 FILE* out_file)
31 {
32 VbFirmwarePreambleHeader* fw_preamble = NULL;
33 int rv = 1;
34 do { /* to be able to bail out anywhere */
35 VbSignature* firmware_sig;
36
37 /* sign the firmware first */
38 firmware_sig = CalculateSignature(image, image_size, signing_key);
39
40 /* write the original keyblock */
41 if (fwrite(wrapper_kb, wrapper_kb->key_block_size, 1, out_file) != 1) {
42 debug("failed writing key block\n");
43 break;
44 }
45
46 fw_preamble = CreateFirmwarePreamble(fw_version, nested_pubkey,
47 firmware_sig, signing_key);
48
49 if (!fw_preamble) {
50 debug("failed creating preamble\n");
51 break;
52 }
53
54 /* write the preamble */
55 if (fwrite(fw_preamble, fw_preamble->preamble_size, 1, out_file) != 1) {
56 debug("failed writing fw preamble\n");
57 break;
58 }
59
60 /* write the image */
61 if (fwrite(image, image_size, 1, out_file) != 1) {
62 debug("failed writing image\n");
63 break;
64 }
65 rv = 0;
66 } while(0);
67
68 if (fw_preamble) {
69 Free(fw_preamble);
70 }
71
72 return rv;
73 }
74
75 int main(int argc, char* argv[]) {
76 VbKeyBlockHeader* firmware_kb;
77 VbPublicKey* kernel_pubk;
78 uint8_t* firmware;
79 uint64_t fw_size;
80 uint64_t version;
81 VbPrivateKey* signing_key = NULL;
82 FILE* out_file;
83 int rv;
84
85 if (argc != 7) {
86 usage();
87 exit(1);
88 }
89
90 version = strtoul(argv[1], 0, 0);
91 firmware_kb = KeyBlockRead(argv[2]);
92 kernel_pubk = PublicKeyRead(argv[4]);
93 firmware = BufferFromFile(argv[5], &fw_size);
94 if (firmware_kb) {
95 signing_key = PrivateKeyRead(argv[3], firmware_kb->data_key.algorithm);
96 }
97 if (!firmware_kb || !kernel_pubk || !firmware || ! signing_key) {
98 return 1;
99 }
100
101 out_file = fopen(argv[6], "wb");
102 if (!out_file) {
103 debug("could not open %s for writing\n");
104 return 1;
105 }
106
107 rv = SignAndWriteImage(version, firmware_kb, signing_key,
108 kernel_pubk, firmware, fw_size, out_file);
109
110 fclose(out_file);
111 if (rv) {
112 unlink(argv[6]);
113 }
114 return rv;
115 }
OLDNEW
« no previous file with comments | « utility/load_kernel_test_old.c ('k') | vkernel/Makefile » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698