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

Side by Side Diff: generate_delta_main.cc

Issue 6271003: AU: Support signed payload verification through the delta generator. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « delta_performer_unittest.cc ('k') | omaha_hash_calculator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <sys/types.h> 5 #include <sys/types.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 22 matching lines...) Expand all
33 DEFINE_string(old_image, "", "Path to the old rootfs"); 33 DEFINE_string(old_image, "", "Path to the old rootfs");
34 DEFINE_string(new_image, "", "Path to the new rootfs"); 34 DEFINE_string(new_image, "", "Path to the new rootfs");
35 DEFINE_string(old_kernel, "", "Path to the old kernel partition image"); 35 DEFINE_string(old_kernel, "", "Path to the old kernel partition image");
36 DEFINE_string(new_kernel, "", "Path to the new kernel partition image"); 36 DEFINE_string(new_kernel, "", "Path to the new kernel partition image");
37 DEFINE_string(in_file, "", 37 DEFINE_string(in_file, "",
38 "Path to input delta payload file used to hash/sign payloads " 38 "Path to input delta payload file used to hash/sign payloads "
39 "and apply delta over old_image (for debugging)"); 39 "and apply delta over old_image (for debugging)");
40 DEFINE_string(out_file, "", "Path to output delta payload file"); 40 DEFINE_string(out_file, "", "Path to output delta payload file");
41 DEFINE_string(out_hash_file, "", "Path to output hash file"); 41 DEFINE_string(out_hash_file, "", "Path to output hash file");
42 DEFINE_string(private_key, "", "Path to private key in .pem format"); 42 DEFINE_string(private_key, "", "Path to private key in .pem format");
43 DEFINE_string(public_key, "", "Path to public key in .pem format");
43 DEFINE_string(prefs_dir, "/tmp/update_engine_prefs", 44 DEFINE_string(prefs_dir, "/tmp/update_engine_prefs",
44 "Preferences directory, used with apply_delta"); 45 "Preferences directory, used with apply_delta");
45 DEFINE_int32(signature_size, 0, "Raw signature size used for hash calculation"); 46 DEFINE_int32(signature_size, 0, "Raw signature size used for hash calculation");
46 DEFINE_string(signature_file, "", "Raw signature file to sign payload with"); 47 DEFINE_string(signature_file, "", "Raw signature file to sign payload with");
47 48
48 // This file contains a simple program that takes an old path, a new path, 49 // This file contains a simple program that takes an old path, a new path,
49 // and an output file as arguments and the path to an output file and 50 // and an output file as arguments and the path to an output file and
50 // generates a delta that can be sent to Chrome OS clients. 51 // generates a delta that can be sent to Chrome OS clients.
51 52
52 using std::set; 53 using std::set;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 << "Must pass --out_file to sign payload."; 88 << "Must pass --out_file to sign payload.";
88 LOG_IF(FATAL, FLAGS_signature_file.empty()) 89 LOG_IF(FATAL, FLAGS_signature_file.empty())
89 << "Must pass --signature_file to sign payload."; 90 << "Must pass --signature_file to sign payload.";
90 vector<char> signature; 91 vector<char> signature;
91 CHECK(utils::ReadFile(FLAGS_signature_file, &signature)); 92 CHECK(utils::ReadFile(FLAGS_signature_file, &signature));
92 CHECK(PayloadSigner::AddSignatureToPayload( 93 CHECK(PayloadSigner::AddSignatureToPayload(
93 FLAGS_in_file, signature, FLAGS_out_file)); 94 FLAGS_in_file, signature, FLAGS_out_file));
94 LOG(INFO) << "Done signing payload."; 95 LOG(INFO) << "Done signing payload.";
95 } 96 }
96 97
98 void VerifySignedPayload() {
99 LOG(INFO) << "Verifying signed payload.";
100 LOG_IF(FATAL, FLAGS_in_file.empty())
101 << "Must pass --in_file to verify signed payload.";
102 LOG_IF(FATAL, FLAGS_public_key.empty())
103 << "Must pass --public_key to verify signed payload.";
104 CHECK(PayloadSigner::VerifySignedPayload(FLAGS_in_file, FLAGS_public_key));
105 LOG(INFO) << "Done verifying signed payload.";
106 }
107
97 void ApplyDelta() { 108 void ApplyDelta() {
98 LOG(INFO) << "Applying delta."; 109 LOG(INFO) << "Applying delta.";
99 LOG_IF(FATAL, FLAGS_old_image.empty()) 110 LOG_IF(FATAL, FLAGS_old_image.empty())
100 << "Must pass --old_image to apply delta."; 111 << "Must pass --old_image to apply delta.";
101 Prefs prefs; 112 Prefs prefs;
102 LOG(INFO) << "Setting up preferences under: " << FLAGS_prefs_dir; 113 LOG(INFO) << "Setting up preferences under: " << FLAGS_prefs_dir;
103 LOG_IF(ERROR, !prefs.Init(FilePath(FLAGS_prefs_dir))) 114 LOG_IF(ERROR, !prefs.Init(FilePath(FLAGS_prefs_dir)))
104 << "Failed to initialize preferences."; 115 << "Failed to initialize preferences.";
105 // Get original checksums 116 // Get original checksums
106 LOG(INFO) << "Calculating original checksums"; 117 LOG(INFO) << "Calculating original checksums";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 logging::DONT_LOCK_LOG_FILE, 158 logging::DONT_LOCK_LOG_FILE,
148 logging::APPEND_TO_OLD_LOG_FILE); 159 logging::APPEND_TO_OLD_LOG_FILE);
149 if (FLAGS_signature_size > 0 || !FLAGS_out_hash_file.empty()) { 160 if (FLAGS_signature_size > 0 || !FLAGS_out_hash_file.empty()) {
150 CalculatePayloadHashForSigning(); 161 CalculatePayloadHashForSigning();
151 return 0; 162 return 0;
152 } 163 }
153 if (!FLAGS_signature_file.empty()) { 164 if (!FLAGS_signature_file.empty()) {
154 SignPayload(); 165 SignPayload();
155 return 0; 166 return 0;
156 } 167 }
168 if (!FLAGS_public_key.empty()) {
169 VerifySignedPayload();
170 return 0;
171 }
157 if (!FLAGS_in_file.empty()) { 172 if (!FLAGS_in_file.empty()) {
158 ApplyDelta(); 173 ApplyDelta();
159 return 0; 174 return 0;
160 } 175 }
161 CHECK(!FLAGS_new_image.empty()); 176 CHECK(!FLAGS_new_image.empty());
162 CHECK(!FLAGS_out_file.empty()); 177 CHECK(!FLAGS_out_file.empty());
163 CHECK(!FLAGS_new_kernel.empty()); 178 CHECK(!FLAGS_new_kernel.empty());
164 if (FLAGS_old_image.empty()) { 179 if (FLAGS_old_image.empty()) {
165 LOG(INFO) << "Generating full update"; 180 LOG(INFO) << "Generating full update";
166 } else { 181 } else {
(...skipping 16 matching lines...) Expand all
183 return 0; 198 return 0;
184 } 199 }
185 200
186 } // namespace {} 201 } // namespace {}
187 202
188 } // namespace chromeos_update_engine 203 } // namespace chromeos_update_engine
189 204
190 int main(int argc, char** argv) { 205 int main(int argc, char** argv) {
191 return chromeos_update_engine::Main(argc, argv); 206 return chromeos_update_engine::Main(argc, argv);
192 } 207 }
OLDNEW
« no previous file with comments | « delta_performer_unittest.cc ('k') | omaha_hash_calculator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698