| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return ValidateError::CRX_PUBLIC_KEY_INVALID; | 153 return ValidateError::CRX_PUBLIC_KEY_INVALID; |
| 154 | 154 |
| 155 std::vector<uint8_t> signature(header.signature_size); | 155 std::vector<uint8_t> signature(header.signature_size); |
| 156 len = ReadAndHash(&signature.front(), sizeof(uint8_t), header.signature_size, | 156 len = ReadAndHash(&signature.front(), sizeof(uint8_t), header.signature_size, |
| 157 file.get(), hash.get()); | 157 file.get(), hash.get()); |
| 158 if (len < header.signature_size) | 158 if (len < header.signature_size) |
| 159 return ValidateError::CRX_SIGNATURE_INVALID; | 159 return ValidateError::CRX_SIGNATURE_INVALID; |
| 160 | 160 |
| 161 crypto::SignatureVerifier verifier; | 161 crypto::SignatureVerifier verifier; |
| 162 if (!verifier.VerifyInit(crypto::SignatureVerifier::RSA_PKCS1_SHA1, | 162 if (!verifier.VerifyInit(crypto::SignatureVerifier::RSA_PKCS1_SHA1, |
| 163 signature.data(), static_cast<int>(signature.size()), | 163 signature.data(), signature.size(), key.data(), |
| 164 key.data(), static_cast<int>(key.size()))) { | 164 key.size())) { |
| 165 // Signature verification initialization failed. This is most likely | 165 // Signature verification initialization failed. This is most likely |
| 166 // caused by a public key in the wrong format (should encode algorithm). | 166 // caused by a public key in the wrong format (should encode algorithm). |
| 167 return ValidateError::CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED; | 167 return ValidateError::CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED; |
| 168 } | 168 } |
| 169 | 169 |
| 170 uint8_t buf[1 << 12] = {}; | 170 uint8_t buf[1 << 12] = {}; |
| 171 while ((len = ReadAndHash(buf, sizeof(buf[0]), arraysize(buf), file.get(), | 171 while ((len = ReadAndHash(buf, sizeof(buf[0]), arraysize(buf), file.get(), |
| 172 hash.get())) > 0) | 172 hash.get())) > 0) |
| 173 verifier.VerifyUpdate(buf, static_cast<int>(len)); | 173 verifier.VerifyUpdate(buf, len); |
| 174 | 174 |
| 175 if (!verifier.VerifyFinal()) | 175 if (!verifier.VerifyFinal()) |
| 176 return ValidateError::CRX_SIGNATURE_VERIFICATION_FAILED; | 176 return ValidateError::CRX_SIGNATURE_VERIFICATION_FAILED; |
| 177 | 177 |
| 178 std::string public_key_bytes = | 178 std::string public_key_bytes = |
| 179 std::string(reinterpret_cast<char*>(&key.front()), key.size()); | 179 std::string(reinterpret_cast<char*>(&key.front()), key.size()); |
| 180 if (public_key) | 180 if (public_key) |
| 181 base::Base64Encode(public_key_bytes, public_key); | 181 base::Base64Encode(public_key_bytes, public_key); |
| 182 | 182 |
| 183 std::string id = id_util::GenerateId(public_key_bytes); | 183 std::string id = id_util::GenerateId(public_key_bytes); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 211 else if (header.signature_size > kMaxSignatureSize) | 211 else if (header.signature_size > kMaxSignatureSize) |
| 212 *error = kInvalidSignatureTooLarge; | 212 *error = kInvalidSignatureTooLarge; |
| 213 else if (header.signature_size == 0) | 213 else if (header.signature_size == 0) |
| 214 *error = kInvalidSignatureTooSmall; | 214 *error = kInvalidSignatureTooSmall; |
| 215 else | 215 else |
| 216 valid = true; | 216 valid = true; |
| 217 return valid; | 217 return valid; |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace crx_file | 220 } // namespace crx_file |
| OLD | NEW |