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

Side by Side Diff: components/crx_file/crx_file.cc

Issue 1679873005: Switch SignatureVerifier to taking an algorithm enum. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix iOS build Created 4 years, 9 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
OLDNEW
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/numerics/safe_math.h" 13 #include "base/numerics/safe_math.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "components/crx_file/constants.h"
17 #include "components/crx_file/id_util.h" 16 #include "components/crx_file/id_util.h"
18 #include "crypto/secure_hash.h" 17 #include "crypto/secure_hash.h"
19 #include "crypto/sha2.h" 18 #include "crypto/sha2.h"
20 #include "crypto/signature_verifier.h" 19 #include "crypto/signature_verifier.h"
21 20
22 namespace crx_file { 21 namespace crx_file {
23 22
24 namespace { 23 namespace {
25 24
26 // The current version of the crx format. 25 // The current version of the crx format.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (len != header.key_size) 152 if (len != header.key_size)
154 return ValidateError::CRX_PUBLIC_KEY_INVALID; 153 return ValidateError::CRX_PUBLIC_KEY_INVALID;
155 154
156 std::vector<uint8_t> signature(header.signature_size); 155 std::vector<uint8_t> signature(header.signature_size);
157 len = ReadAndHash(&signature.front(), sizeof(uint8_t), header.signature_size, 156 len = ReadAndHash(&signature.front(), sizeof(uint8_t), header.signature_size,
158 file.get(), hash.get()); 157 file.get(), hash.get());
159 if (len < header.signature_size) 158 if (len < header.signature_size)
160 return ValidateError::CRX_SIGNATURE_INVALID; 159 return ValidateError::CRX_SIGNATURE_INVALID;
161 160
162 crypto::SignatureVerifier verifier; 161 crypto::SignatureVerifier verifier;
163 if (!verifier.VerifyInit( 162 if (!verifier.VerifyInit(crypto::SignatureVerifier::RSA_PKCS1_SHA1,
164 crx_file::kSignatureAlgorithm, sizeof(crx_file::kSignatureAlgorithm), 163 signature.data(), static_cast<int>(signature.size()),
165 &signature.front(), static_cast<int>(signature.size()), &key.front(), 164 key.data(), static_cast<int>(key.size()))) {
166 static_cast<int>(key.size()))) {
167 // Signature verification initialization failed. This is most likely 165 // Signature verification initialization failed. This is most likely
168 // 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).
169 return ValidateError::CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED; 167 return ValidateError::CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED;
170 } 168 }
171 169
172 uint8_t buf[1 << 12] = {}; 170 uint8_t buf[1 << 12] = {};
173 while ((len = ReadAndHash(buf, sizeof(buf[0]), arraysize(buf), file.get(), 171 while ((len = ReadAndHash(buf, sizeof(buf[0]), arraysize(buf), file.get(),
174 hash.get())) > 0) 172 hash.get())) > 0)
175 verifier.VerifyUpdate(buf, static_cast<int>(len)); 173 verifier.VerifyUpdate(buf, static_cast<int>(len));
176 174
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 else if (header.signature_size > kMaxSignatureSize) 211 else if (header.signature_size > kMaxSignatureSize)
214 *error = kInvalidSignatureTooLarge; 212 *error = kInvalidSignatureTooLarge;
215 else if (header.signature_size == 0) 213 else if (header.signature_size == 0)
216 *error = kInvalidSignatureTooSmall; 214 *error = kInvalidSignatureTooSmall;
217 else 215 else
218 valid = true; 216 valid = true;
219 return valid; 217 return valid;
220 } 218 }
221 219
222 } // namespace crx_file 220 } // namespace crx_file
OLDNEW
« no previous file with comments | « components/crx_file/constants.h ('k') | components/policy/core/common/cloud/cloud_policy_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698