| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/sandboxed_extension_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "app/gfx/codec/png_codec.h" | 9 #include "app/gfx/codec/png_codec.h" |
| 10 #include "base/base64.h" |
| 10 #include "base/crypto/signature_verifier.h" | 11 #include "base/crypto/signature_verifier.h" |
| 11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/scoped_handle.h" | 14 #include "base/scoped_handle.h" |
| 14 #include "base/task.h" | 15 #include "base/task.h" |
| 15 #include "chrome/browser/chrome_thread.h" | 16 #include "chrome/browser/chrome_thread.h" |
| 16 #include "chrome/browser/extensions/extensions_service.h" | 17 #include "chrome/browser/extensions/extensions_service.h" |
| 17 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/extension_unpacker.h" | 22 #include "chrome/common/extensions/extension_unpacker.h" |
| 22 #include "chrome/common/json_value_serializer.h" | 23 #include "chrome/common/json_value_serializer.h" |
| 23 #include "net/base/base64.h" | |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 | 25 |
| 26 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; | 26 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; |
| 27 | 27 |
| 28 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( | 28 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( |
| 29 const FilePath& crx_path, ResourceDispatcherHost* rdh, | 29 const FilePath& crx_path, ResourceDispatcherHost* rdh, |
| 30 SandboxedExtensionUnpackerClient* client) | 30 SandboxedExtensionUnpackerClient* client) |
| 31 : crx_path_(crx_path), thread_identifier_(ChromeThread::ID_COUNT), | 31 : crx_path_(crx_path), thread_identifier_(ChromeThread::ID_COUNT), |
| 32 rdh_(rdh), client_(client), got_response_(false) { | 32 rdh_(rdh), client_(client), got_response_(false) { |
| 33 } | 33 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 unsigned char buf[1 << 12]; | 224 unsigned char buf[1 << 12]; |
| 225 while ((len = fread(buf, 1, sizeof(buf), file.get())) > 0) | 225 while ((len = fread(buf, 1, sizeof(buf), file.get())) > 0) |
| 226 verifier.VerifyUpdate(buf, len); | 226 verifier.VerifyUpdate(buf, len); |
| 227 | 227 |
| 228 if (!verifier.VerifyFinal()) { | 228 if (!verifier.VerifyFinal()) { |
| 229 ReportFailure("Signature verification failed"); | 229 ReportFailure("Signature verification failed"); |
| 230 return false; | 230 return false; |
| 231 } | 231 } |
| 232 | 232 |
| 233 net::Base64Encode(std::string(reinterpret_cast<char*>(&key.front()), | 233 base::Base64Encode(std::string(reinterpret_cast<char*>(&key.front()), |
| 234 key.size()), &public_key_); | 234 key.size()), &public_key_); |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 | 237 |
| 238 void SandboxedExtensionUnpacker::ReportFailure(const std::string& error) { | 238 void SandboxedExtensionUnpacker::ReportFailure(const std::string& error) { |
| 239 client_->OnUnpackFailure(error); | 239 client_->OnUnpackFailure(error); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void SandboxedExtensionUnpacker::ReportSuccess() { | 242 void SandboxedExtensionUnpacker::ReportSuccess() { |
| 243 // Client takes ownership of temporary directory and extension. | 243 // Client takes ownership of temporary directory and extension. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 if (!file_util::WriteFile(path, | 365 if (!file_util::WriteFile(path, |
| 366 catalog_json.c_str(), | 366 catalog_json.c_str(), |
| 367 catalog_json.size())) { | 367 catalog_json.size())) { |
| 368 ReportFailure("Error saving catalog."); | 368 ReportFailure("Error saving catalog."); |
| 369 return false; | 369 return false; |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 | 372 |
| 373 return true; | 373 return true; |
| 374 } | 374 } |
| OLD | NEW |