| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/crx_file/crx_file.h" | 5 #include "components/crx_file/crx_file.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Helper function to finish computing a hash and return an error if the | 55 // Helper function to finish computing a hash and return an error if the |
| 56 // result of the hash didn't meet an expected base64-encoded value. | 56 // result of the hash didn't meet an expected base64-encoded value. |
| 57 CrxFile::ValidateError FinalizeHash(const std::string& extension_id, | 57 CrxFile::ValidateError FinalizeHash(const std::string& extension_id, |
| 58 crypto::SecureHash* hash, | 58 crypto::SecureHash* hash, |
| 59 const std::string& expected_hash) { | 59 const std::string& expected_hash) { |
| 60 CHECK(hash != nullptr); | 60 CHECK(hash != nullptr); |
| 61 uint8 output[crypto::kSHA256Length] = {}; | 61 uint8 output[crypto::kSHA256Length] = {}; |
| 62 hash->Finish(output, sizeof(output)); | 62 hash->Finish(output, sizeof(output)); |
| 63 std::string hash_base64 = | 63 std::string hash_base64 = |
| 64 base::StringToLowerASCII(base::HexEncode(output, sizeof(output))); | 64 base::ToLowerASCII(base::HexEncode(output, sizeof(output))); |
| 65 if (hash_base64 != expected_hash) { | 65 if (hash_base64 != expected_hash) { |
| 66 LOG(ERROR) << "Hash check failed for extension: " << extension_id | 66 LOG(ERROR) << "Hash check failed for extension: " << extension_id |
| 67 << ", expected " << expected_hash << ", got " << hash_base64; | 67 << ", expected " << expected_hash << ", got " << hash_base64; |
| 68 return CrxFile::ValidateError::CRX_HASH_VERIFICATION_FAILED; | 68 return CrxFile::ValidateError::CRX_HASH_VERIFICATION_FAILED; |
| 69 } else { | 69 } else { |
| 70 return CrxFile::ValidateError::NONE; | 70 return CrxFile::ValidateError::NONE; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 else if (header.signature_size > kMaxSignatureSize) | 212 else if (header.signature_size > kMaxSignatureSize) |
| 213 *error = kInvalidSignatureTooLarge; | 213 *error = kInvalidSignatureTooLarge; |
| 214 else if (header.signature_size == 0) | 214 else if (header.signature_size == 0) |
| 215 *error = kInvalidSignatureTooSmall; | 215 *error = kInvalidSignatureTooSmall; |
| 216 else | 216 else |
| 217 valid = true; | 217 valid = true; |
| 218 return valid; | 218 return valid; |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace crx_file | 221 } // namespace crx_file |
| OLD | NEW |