|
4 | 4 |
|
5 | 5 | #include "chromeos/components/sync_wifi/pending_network_configuration_tracker_impl.h"
|
6 | 6 |
|
| 7 | +#include "base/base64url.h" |
7 | 8 | #include "base/guid.h"
|
8 | 9 | #include "base/optional.h"
|
9 | 10 | #include "base/strings/stringprintf.h"
|
@@ -34,10 +35,15 @@ PendingNetworkConfigurationUpdate ConvertToPendingUpdate(
|
34 | 35 | const NetworkIdentifier& id) {
|
35 | 36 | std::string* change_guid = dict->FindStringKey(kChangeGuidKey);
|
36 | 37 | base::Optional<sync_pb::WifiConfigurationSpecifics> specifics;
|
37 |
| - std::string* specifics_string = dict->FindStringKey(kSpecificsKey); |
38 |
| - if (!specifics_string->empty()) { |
| 38 | + std::string* encoded_specifics_string = dict->FindStringKey(kSpecificsKey); |
| 39 | + std::string specifics_string; |
| 40 | + if (encoded_specifics_string && |
| 41 | + base::Base64UrlDecode(*encoded_specifics_string, |
| 42 | + base::Base64UrlDecodePolicy::REQUIRE_PADDING, |
| 43 | + &specifics_string) && |
| 44 | + !specifics_string.empty()) { |
39 | 45 | sync_pb::WifiConfigurationSpecifics data;
|
40 |
| - data.ParseFromString(*specifics_string); |
| 46 | + data.ParseFromString(specifics_string); |
41 | 47 | specifics = data;
|
42 | 48 | }
|
43 | 49 | base::Optional<int> completed_attempts =
|
@@ -76,11 +82,16 @@ std::string PendingNetworkConfigurationTrackerImpl::TrackPendingUpdate(
|
76 | 82 | else
|
77 | 83 | CHECK(specifics->SerializeToString(&serialized_specifics));
|
78 | 84 |
|
| 85 | + // base::Value only allows UTF8 encoded strings. |
| 86 | + std::string encoded_specifics; |
| 87 | + base::Base64UrlEncode(serialized_specifics, |
| 88 | + base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
| 89 | + &encoded_specifics); |
79 | 90 | std::string change_guid = base::GenerateGUID();
|
80 | 91 |
|
81 | 92 | dict_.SetPath(GeneratePath(id, kChangeGuidKey), base::Value(change_guid));
|
82 | 93 | dict_.SetPath(GeneratePath(id, kSpecificsKey),
|
83 |
| - base::Value(serialized_specifics)); |
| 94 | + base::Value(encoded_specifics)); |
84 | 95 | dict_.SetPath(GeneratePath(id, kCompletedAttemptsKey), base::Value(0));
|
85 | 96 | pref_service_->Set(kPendingNetworkConfigurationsPref, dict_);
|
86 | 97 |
|
|
0 commit comments