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

Side by Side Diff: components/os_crypt/os_crypt_posix.cc

Issue 2137503002: Revert of Replace string::find(prefix) == 0 pattern with base::StartsWith(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « components/leveldb/env_mojo.cc ('k') | components/sync_sessions/favicon_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/os_crypt/os_crypt.h" 5 #include "components/os_crypt/os_crypt.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "crypto/encryptor.h" 13 #include "crypto/encryptor.h"
15 #include "crypto/symmetric_key.h" 14 #include "crypto/symmetric_key.h"
16 15
17 namespace { 16 namespace {
18 17
19 // Salt for Symmetric key derivation. 18 // Salt for Symmetric key derivation.
20 const char kSalt[] = "saltysalt"; 19 const char kSalt[] = "saltysalt";
21 20
22 // Key size required for 128 bit AES. 21 // Key size required for 128 bit AES.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if (ciphertext.empty()) { 111 if (ciphertext.empty()) {
113 *plaintext = std::string(); 112 *plaintext = std::string();
114 return true; 113 return true;
115 } 114 }
116 115
117 // Check that the incoming cyphertext was indeed encrypted with the expected 116 // Check that the incoming cyphertext was indeed encrypted with the expected
118 // version. If the prefix is not found then we'll assume we're dealing with 117 // version. If the prefix is not found then we'll assume we're dealing with
119 // old data saved as clear text and we'll return it directly. 118 // old data saved as clear text and we'll return it directly.
120 // Credit card numbers are current legacy data, so false match with prefix 119 // Credit card numbers are current legacy data, so false match with prefix
121 // won't happen. 120 // won't happen.
122 if (!base::StartsWith(ciphertext, kObfuscationPrefix, 121 if (ciphertext.find(kObfuscationPrefix) != 0) {
123 base::CompareCase::SENSITIVE)) {
124 *plaintext = ciphertext; 122 *plaintext = ciphertext;
125 return true; 123 return true;
126 } 124 }
127 125
128 // Strip off the versioning prefix before decrypting. 126 // Strip off the versioning prefix before decrypting.
129 std::string raw_ciphertext = ciphertext.substr(strlen(kObfuscationPrefix)); 127 std::string raw_ciphertext = ciphertext.substr(strlen(kObfuscationPrefix));
130 128
131 std::unique_ptr<crypto::SymmetricKey> encryption_key(GetEncryptionKey()); 129 std::unique_ptr<crypto::SymmetricKey> encryption_key(GetEncryptionKey());
132 if (!encryption_key.get()) 130 if (!encryption_key.get())
133 return false; 131 return false;
134 132
135 std::string iv(kIVBlockSizeAES128, ' '); 133 std::string iv(kIVBlockSizeAES128, ' ');
136 crypto::Encryptor encryptor; 134 crypto::Encryptor encryptor;
137 if (!encryptor.Init(encryption_key.get(), crypto::Encryptor::CBC, iv)) 135 if (!encryptor.Init(encryption_key.get(), crypto::Encryptor::CBC, iv))
138 return false; 136 return false;
139 137
140 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) 138 if (!encryptor.Decrypt(raw_ciphertext, plaintext))
141 return false; 139 return false;
142 140
143 return true; 141 return true;
144 } 142 }
OLDNEW
« no previous file with comments | « components/leveldb/env_mojo.cc ('k') | components/sync_sessions/favicon_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698