| OLD | NEW |
| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 return true; | 208 return true; |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool ExtensionCreator::SignZip(const base::FilePath& zip_path, | 211 bool ExtensionCreator::SignZip(const base::FilePath& zip_path, |
| 212 crypto::RSAPrivateKey* private_key, | 212 crypto::RSAPrivateKey* private_key, |
| 213 std::vector<uint8>* signature) { | 213 std::vector<uint8>* signature) { |
| 214 scoped_ptr<crypto::SignatureCreator> signature_creator( | 214 scoped_ptr<crypto::SignatureCreator> signature_creator( |
| 215 crypto::SignatureCreator::Create(private_key)); | 215 crypto::SignatureCreator::Create(private_key)); |
| 216 ScopedStdioHandle zip_handle(file_util::OpenFile(zip_path, "rb")); | 216 ScopedStdioHandle zip_handle(base::OpenFile(zip_path, "rb")); |
| 217 size_t buffer_size = 1 << 16; | 217 size_t buffer_size = 1 << 16; |
| 218 scoped_ptr<uint8[]> buffer(new uint8[buffer_size]); | 218 scoped_ptr<uint8[]> buffer(new uint8[buffer_size]); |
| 219 int bytes_read = -1; | 219 int bytes_read = -1; |
| 220 while ((bytes_read = fread(buffer.get(), 1, buffer_size, | 220 while ((bytes_read = fread(buffer.get(), 1, buffer_size, |
| 221 zip_handle.get())) > 0) { | 221 zip_handle.get())) > 0) { |
| 222 if (!signature_creator->Update(buffer.get(), bytes_read)) { | 222 if (!signature_creator->Update(buffer.get(), bytes_read)) { |
| 223 error_message_ = | 223 error_message_ = |
| 224 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING); | 224 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING); |
| 225 return false; | 225 return false; |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 zip_handle.Close(); | 228 zip_handle.Close(); |
| 229 | 229 |
| 230 if (!signature_creator->Final(signature)) { | 230 if (!signature_creator->Final(signature)) { |
| 231 error_message_ = | 231 error_message_ = |
| 232 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING); | 232 l10n_util::GetStringUTF8(IDS_EXTENSION_ERROR_WHILE_SIGNING); |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 | 237 |
| 238 bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path, | 238 bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path, |
| 239 crypto::RSAPrivateKey* private_key, | 239 crypto::RSAPrivateKey* private_key, |
| 240 const std::vector<uint8>& signature, | 240 const std::vector<uint8>& signature, |
| 241 const base::FilePath& crx_path) { | 241 const base::FilePath& crx_path) { |
| 242 if (base::PathExists(crx_path)) | 242 if (base::PathExists(crx_path)) |
| 243 base::DeleteFile(crx_path, false); | 243 base::DeleteFile(crx_path, false); |
| 244 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb")); | 244 ScopedStdioHandle crx_handle(base::OpenFile(crx_path, "wb")); |
| 245 if (!crx_handle.get()) { | 245 if (!crx_handle.get()) { |
| 246 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); | 246 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); |
| 247 return false; | 247 return false; |
| 248 } | 248 } |
| 249 | 249 |
| 250 std::vector<uint8> public_key; | 250 std::vector<uint8> public_key; |
| 251 CHECK(private_key->ExportPublicKey(&public_key)); | 251 CHECK(private_key->ExportPublicKey(&public_key)); |
| 252 | 252 |
| 253 CrxFile::Error error; | 253 CrxFile::Error error; |
| 254 scoped_ptr<CrxFile> crx( | 254 scoped_ptr<CrxFile> crx( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 266 PLOG(ERROR) << "fwrite failed to write public_key.front"; | 266 PLOG(ERROR) << "fwrite failed to write public_key.front"; |
| 267 } | 267 } |
| 268 if (fwrite(&signature.front(), sizeof(uint8), signature.size(), | 268 if (fwrite(&signature.front(), sizeof(uint8), signature.size(), |
| 269 crx_handle.get()) != signature.size()) { | 269 crx_handle.get()) != signature.size()) { |
| 270 PLOG(ERROR) << "fwrite failed to write signature.front"; | 270 PLOG(ERROR) << "fwrite failed to write signature.front"; |
| 271 } | 271 } |
| 272 | 272 |
| 273 size_t buffer_size = 1 << 16; | 273 size_t buffer_size = 1 << 16; |
| 274 scoped_ptr<uint8[]> buffer(new uint8[buffer_size]); | 274 scoped_ptr<uint8[]> buffer(new uint8[buffer_size]); |
| 275 size_t bytes_read = 0; | 275 size_t bytes_read = 0; |
| 276 ScopedStdioHandle zip_handle(file_util::OpenFile(zip_path, "rb")); | 276 ScopedStdioHandle zip_handle(base::OpenFile(zip_path, "rb")); |
| 277 while ((bytes_read = fread(buffer.get(), 1, buffer_size, | 277 while ((bytes_read = fread(buffer.get(), 1, buffer_size, |
| 278 zip_handle.get())) > 0) { | 278 zip_handle.get())) > 0) { |
| 279 if (fwrite(buffer.get(), sizeof(char), bytes_read, crx_handle.get()) != | 279 if (fwrite(buffer.get(), sizeof(char), bytes_read, crx_handle.get()) != |
| 280 bytes_read) { | 280 bytes_read) { |
| 281 PLOG(ERROR) << "fwrite failed to write buffer"; | 281 PLOG(ERROR) << "fwrite failed to write buffer"; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 return true; | 285 return true; |
| 286 } | 286 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 SignZip(zip_path, key_pair.get(), &signature) && | 323 SignZip(zip_path, key_pair.get(), &signature) && |
| 324 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 324 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
| 325 result = true; | 325 result = true; |
| 326 } | 326 } |
| 327 | 327 |
| 328 base::DeleteFile(zip_path, false); | 328 base::DeleteFile(zip_path, false); |
| 329 return result; | 329 return result; |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace extensions | 332 } // namespace extensions |
| OLD | NEW |