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

Unified Diff: media/cdm/json_web_key.cc

Issue 1132223002: Sanitize data before providing it to the CDM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows change Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/cdm/json_web_key.h ('k') | media/cdm/json_web_key_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cdm/json_web_key.cc
diff --git a/media/cdm/json_web_key.cc b/media/cdm/json_web_key.cc
index f60c6f5b10267e2d775f8a9c65e1bf3a8b942476..0576f369009caa59fc6ab40c41982ad68f54d81c 100644
--- a/media/cdm/json_web_key.cc
+++ b/media/cdm/json_web_key.cc
@@ -102,21 +102,59 @@ static std::string ShortenTo64Characters(const std::string& input) {
return escaped_str.substr(0, 61).append("...");
}
+static scoped_ptr<base::DictionaryValue> CreateJSONDictionary(
+ const uint8* key,
+ int key_length,
+ const uint8* key_id,
+ int key_id_length) {
+ scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue());
+ jwk->SetString(kKeyTypeTag, kKeyTypeOct);
+ jwk->SetString(kKeyTag, EncodeBase64Url(key, key_length));
+ jwk->SetString(kKeyIdTag, EncodeBase64Url(key_id, key_id_length));
+ return jwk.Pass();
+}
+
std::string GenerateJWKSet(const uint8* key, int key_length,
const uint8* key_id, int key_id_length) {
- // Both |key| and |key_id| need to be base64 encoded strings in the JWK.
- std::string key_base64 = EncodeBase64Url(key, key_length);
- std::string key_id_base64 = EncodeBase64Url(key_id, key_id_length);
-
// Create the JWK, and wrap it into a JWK Set.
- scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue());
- jwk->SetString(kKeyTypeTag, kKeyTypeOct);
- jwk->SetString(kKeyTag, key_base64);
- jwk->SetString(kKeyIdTag, key_id_base64);
scoped_ptr<base::ListValue> list(new base::ListValue());
- list->Append(jwk.release());
+ list->Append(
+ CreateJSONDictionary(key, key_length, key_id, key_id_length).release());
+ base::DictionaryValue jwk_set;
+ jwk_set.Set(kKeysTag, list.release());
+
+ // Finally serialize |jwk_set| into a string and return it.
+ std::string serialized_jwk;
+ JSONStringValueSerializer serializer(&serialized_jwk);
+ serializer.Serialize(jwk_set);
+ return serialized_jwk;
+}
+
+std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys,
+ MediaKeys::SessionType session_type) {
+ scoped_ptr<base::ListValue> list(new base::ListValue());
+ for (const auto& key_pair : keys) {
+ list->Append(CreateJSONDictionary(
+ reinterpret_cast<const uint8*>(key_pair.second.data()),
+ key_pair.second.length(),
+ reinterpret_cast<const uint8*>(key_pair.first.data()),
+ key_pair.first.length())
+ .release());
+ }
+
base::DictionaryValue jwk_set;
jwk_set.Set(kKeysTag, list.release());
+ switch (session_type) {
+ case MediaKeys::TEMPORARY_SESSION:
+ jwk_set.SetString(kTypeTag, kTemporarySession);
+ break;
+ case MediaKeys::PERSISTENT_LICENSE_SESSION:
+ jwk_set.SetString(kTypeTag, kPersistentLicenseSession);
+ break;
+ case MediaKeys::PERSISTENT_RELEASE_MESSAGE_SESSION:
+ jwk_set.SetString(kTypeTag, kPersistentReleaseMessageSession);
+ break;
+ }
// Finally serialize |jwk_set| into a string and return it.
std::string serialized_jwk;
« no previous file with comments | « media/cdm/json_web_key.h ('k') | media/cdm/json_web_key_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698