Commit 2cebd70a authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Make use of new hex decoding functions for Chrome OS code.

Bug: 1021236
Change-Id: I18e1d63683419beb48f4bbc820946fc9162c9f39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898616
Auto-Submit: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712389}
parent 835033c9
...@@ -88,10 +88,7 @@ class EnrollmentPolicyObserverTest : public DeviceSettingsTestBase { ...@@ -88,10 +88,7 @@ class EnrollmentPolicyObserverTest : public DeviceSettingsTestBase {
policy_client_.SetDMToken("fake_dm_token"); policy_client_.SetDMToken("fake_dm_token");
std::vector<uint8_t> eid; EXPECT_TRUE(base::HexStringToString(kEnrollmentId, &enrollment_id_));
EXPECT_TRUE(base::HexStringToBytes(kEnrollmentId, &eid));
enrollment_id_.assign(reinterpret_cast<const char*>(eid.data()),
eid.size());
// Destroy the DeviceSettingsTestBase fake client and replace it. // Destroy the DeviceSettingsTestBase fake client and replace it.
CryptohomeClient::Shutdown(); CryptohomeClient::Shutdown();
......
...@@ -414,16 +414,15 @@ void CloudExternalDataManagerBase::OnPolicyStoreLoaded() { ...@@ -414,16 +414,15 @@ void CloudExternalDataManagerBase::OnPolicyStoreLoaded() {
const base::DictionaryValue* dict = NULL; const base::DictionaryValue* dict = NULL;
std::string url; std::string url;
std::string hex_hash; std::string hex_hash;
std::vector<uint8_t> hash; std::string hash;
if (it.second.value && it.second.value->GetAsDictionary(&dict) && if (it.second.value && it.second.value->GetAsDictionary(&dict) &&
dict->GetStringWithoutPathExpansion("url", &url) && dict->GetStringWithoutPathExpansion("url", &url) &&
dict->GetStringWithoutPathExpansion("hash", &hex_hash) && dict->GetStringWithoutPathExpansion("hash", &hex_hash) &&
!url.empty() && !hex_hash.empty() && !url.empty() && !hex_hash.empty() &&
base::HexStringToBytes(hex_hash, &hash)) { base::HexStringToString(hex_hash, &hash)) {
// Add the external data reference to |metadata| if it is valid (URL and // Add the external data reference to |metadata| if it is valid (URL and
// hash are not empty, hash can be decoded as a hex string). // hash are not empty, hash can be decoded as a hex string).
(*metadata)[it.first] = (*metadata)[it.first] = MetadataEntry(url, hash);
MetadataEntry(url, std::string(hash.begin(), hash.end()));
} }
} }
......
...@@ -100,15 +100,12 @@ std::string CryptohomeTokenEncryptor::DecryptTokenWithKey( ...@@ -100,15 +100,12 @@ std::string CryptohomeTokenEncryptor::DecryptTokenWithKey(
const crypto::SymmetricKey* key, const crypto::SymmetricKey* key,
const std::string& salt, const std::string& salt,
const std::string& encrypted_token_hex) { const std::string& encrypted_token_hex) {
std::vector<uint8_t> encrypted_token_bytes; std::string encrypted_token;
if (!base::HexStringToBytes(encrypted_token_hex, &encrypted_token_bytes)) { if (!base::HexStringToString(encrypted_token_hex, &encrypted_token)) {
LOG(WARNING) << "Corrupt encrypted token found."; LOG(WARNING) << "Corrupt encrypted token found.";
return std::string(); return std::string();
} }
std::string encrypted_token(
reinterpret_cast<char*>(encrypted_token_bytes.data()),
encrypted_token_bytes.size());
crypto::Encryptor encryptor; crypto::Encryptor encryptor;
if (!encryptor.Init(key, crypto::Encryptor::CTR, std::string())) { if (!encryptor.Init(key, crypto::Encryptor::CTR, std::string())) {
LOG(WARNING) << "Failed to initialize Encryptor."; LOG(WARNING) << "Failed to initialize Encryptor.";
......
...@@ -527,8 +527,8 @@ bool Validator::ValidateSSIDAndHexSSID(base::DictionaryValue* object) { ...@@ -527,8 +527,8 @@ bool Validator::ValidateSSIDAndHexSSID(base::DictionaryValue* object) {
std::string hex_ssid_string; std::string hex_ssid_string;
if (object->GetStringWithoutPathExpansion(::onc::wifi::kHexSSID, if (object->GetStringWithoutPathExpansion(::onc::wifi::kHexSSID,
&hex_ssid_string)) { &hex_ssid_string)) {
std::vector<uint8_t> decoded_ssid; std::string decoded_ssid;
if (!base::HexStringToBytes(hex_ssid_string, &decoded_ssid)) { if (!base::HexStringToString(hex_ssid_string, &decoded_ssid)) {
path_.push_back(::onc::wifi::kHexSSID); path_.push_back(::onc::wifi::kHexSSID);
std::ostringstream msg; std::ostringstream msg;
msg << "Not a valid hex representation: '" << hex_ssid_string << "'"; msg << "Not a valid hex representation: '" << hex_ssid_string << "'";
...@@ -550,9 +550,7 @@ bool Validator::ValidateSSIDAndHexSSID(base::DictionaryValue* object) { ...@@ -550,9 +550,7 @@ bool Validator::ValidateSSIDAndHexSSID(base::DictionaryValue* object) {
// HexSSID contains the UTF-8 encoding of SSID. If not, remove the SSID // HexSSID contains the UTF-8 encoding of SSID. If not, remove the SSID
// field. // field.
if (ssid_string.length() > 0) { if (ssid_string.length() > 0) {
std::string decoded_ssid_string( if (ssid_string != decoded_ssid) {
reinterpret_cast<const char*>(&decoded_ssid[0]), decoded_ssid.size());
if (ssid_string != decoded_ssid_string) {
path_.push_back(::onc::wifi::kSSID); path_.push_back(::onc::wifi::kSSID);
std::ostringstream msg; std::ostringstream msg;
msg << "Fields '" << ::onc::wifi::kSSID << "' and '" msg << "Fields '" << ::onc::wifi::kSSID << "' and '"
......
...@@ -91,9 +91,9 @@ std::string GetSSIDFromProperties(const base::Value& properties, ...@@ -91,9 +91,9 @@ std::string GetSSIDFromProperties(const base::Value& properties,
} }
std::string ssid; std::string ssid;
std::vector<uint8_t> raw_ssid_bytes; std::string ssid_bytes;
if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) { if (base::HexStringToString(hex_ssid, &ssid_bytes)) {
ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); ssid = ssid_bytes;
VLOG(2) << "GetSSIDFromProperties: " << name << " HexSsid=" << hex_ssid VLOG(2) << "GetSSIDFromProperties: " << name << " HexSsid=" << hex_ssid
<< " SSID=" << ssid; << " SSID=" << ssid;
} else { } else {
......
...@@ -35,21 +35,14 @@ class SecureChannelSessionKeysTest : public testing::Test { ...@@ -35,21 +35,14 @@ class SecureChannelSessionKeysTest : public testing::Test {
}; };
TEST_F(SecureChannelSessionKeysTest, GenerateKeys) { TEST_F(SecureChannelSessionKeysTest, GenerateKeys) {
std::vector<uint8_t> data; std::string master_key;
ASSERT_TRUE(base::HexStringToString(kMasterKeyHex, &master_key));
std::string master_key(kMasterKeyHex); std::string initiator_key;
ASSERT_TRUE(base::HexStringToBytes(master_key, &data)); ASSERT_TRUE(base::HexStringToString(kInitiatorKeyHex, &initiator_key));
master_key.assign(reinterpret_cast<char*>(&data[0]), data.size());
data.clear(); std::string responder_key;
std::string initiator_key(kInitiatorKeyHex); ASSERT_TRUE(base::HexStringToString(kResponderKeyHex, &responder_key));
ASSERT_TRUE(base::HexStringToBytes(initiator_key, &data));
initiator_key.assign(reinterpret_cast<char*>(&data[0]), data.size());
data.clear();
std::string responder_key(kResponderKeyHex);
ASSERT_TRUE(base::HexStringToBytes(responder_key, &data));
responder_key.assign(reinterpret_cast<char*>(&data[0]), data.size());
SessionKeys session_keys(master_key); SessionKeys session_keys(master_key);
EXPECT_EQ(initiator_key, session_keys.initiator_encode_key()); EXPECT_EQ(initiator_key, session_keys.initiator_encode_key());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment