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

Side by Side Diff: chrome/browser/extensions/extension_creator.cc

Issue 20142007: Catch the sign zip error earlier to prevent invalid private key crash Chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test case for packing extension with invalid private key. Created 7 years, 5 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 | « no previous file | chrome/browser/extensions/extension_service_unittest.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 "chrome/browser/extensions/extension_creator.h" 5 #include "chrome/browser/extensions/extension_creator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 while ((bytes_read = fread(buffer.get(), 1, buffer_size, 221 while ((bytes_read = fread(buffer.get(), 1, buffer_size,
222 zip_handle.get())) > 0) { 222 zip_handle.get())) > 0) {
223 if (!signature_creator->Update(buffer.get(), bytes_read)) { 223 if (!signature_creator->Update(buffer.get(), bytes_read)) {
224 error_message_ = 224 error_message_ =
225 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING); 225 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING);
226 return false; 226 return false;
227 } 227 }
228 } 228 }
229 zip_handle.Close(); 229 zip_handle.Close();
230 230
231 signature_creator->Final(signature); 231 if (!signature_creator->Final(signature)) {
232 error_message_ =
233 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING);
234 return false;
235 }
236
232 return true; 237 return true;
233 } 238 }
234 239
235 bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path, 240 bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path,
236 crypto::RSAPrivateKey* private_key, 241 crypto::RSAPrivateKey* private_key,
237 const std::vector<uint8>& signature, 242 const std::vector<uint8>& signature,
238 const base::FilePath& crx_path) { 243 const base::FilePath& crx_path) {
239 if (base::PathExists(crx_path)) 244 if (base::PathExists(crx_path))
240 base::DeleteFile(crx_path, false); 245 base::DeleteFile(crx_path, false);
241 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb")); 246 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb"));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 SignZip(zip_path, key_pair.get(), &signature) && 325 SignZip(zip_path, key_pair.get(), &signature) &&
321 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { 326 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) {
322 result = true; 327 result = true;
323 } 328 }
324 329
325 base::DeleteFile(zip_path, false); 330 base::DeleteFile(zip_path, false);
326 return result; 331 return result;
327 } 332 }
328 333
329 } // namespace extensions 334 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698