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

Unified Diff: media/cdm/json_web_key.cc

Issue 975983002: Update Clear Key to support keyids formatted init_data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: truncate Created 5 years, 10 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 cd50a8c2e01397e7ddebdff9c1cfc7a9cb7c1f2d..c737523a3812d1356587793b65203290d0fa4ca7 100644
--- a/media/cdm/json_web_key.cc
+++ b/media/cdm/json_web_key.cc
@@ -10,6 +10,7 @@
#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/values.h"
@@ -88,6 +89,15 @@ static std::string DecodeBase64Url(const std::string& encoded_text) {
return decoded_text;
}
+static std::string ShortenTo64Characters(const std::string& input) {
+ if (input.length() <= 64u)
+ return input;
+
+ std::string result = input.substr(0, 61);
+ result.append("...");
+ return result;
+}
+
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.
@@ -226,6 +236,70 @@ bool ExtractKeysFromJWKSet(const std::string& jwk_set,
return true;
}
+bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input,
+ KeyIdList* key_ids,
+ std::string* error_message) {
+ if (!base::IsStringASCII(input)) {
+ error_message->assign("Non ASCII: ");
+ error_message->append(ShortenTo64Characters(input));
sandersd (OOO until July 31) 2015/03/04 01:39:24 I'm not too happy with this implementation when we
jrummell 2015/03/04 22:37:16 Found a routine to escape non-ASCII characters, so
+ return false;
+ }
+
+ scoped_ptr<base::Value> root(base::JSONReader().ReadToValue(input));
+ if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) {
+ error_message->assign("Not valid JSON: ");
+ error_message->append(ShortenTo64Characters(input));
+ return false;
+ }
+
+ // Locate the set from the dictionary.
+ base::DictionaryValue* dictionary =
+ static_cast<base::DictionaryValue*>(root.get());
+ base::ListValue* list_val = NULL;
+ if (!dictionary->GetList(kKeyIdsTag, &list_val)) {
+ error_message->assign("Missing '");
+ error_message->append(kKeyIdsTag);
+ error_message->append("' parameter or not a list");
+ return false;
+ }
+
+ // Create a local list of key ids, so that |key_ids| only gets updated on
+ // success.
+ KeyIdList local_key_ids;
+ for (size_t i = 0; i < list_val->GetSize(); ++i) {
+ std::string encoded_key_id;
+ if (!list_val->GetString(i, &encoded_key_id)) {
+ error_message->assign("'");
+ error_message->append(kKeyIdsTag);
+ error_message->append("'[");
+ error_message->append(base::UintToString(i));
+ error_message->append("] is not string.");
+ return false;
+ }
+
+ // Key ID is a base64-encoded string, so decode it.
+ std::string raw_key_id = DecodeBase64Url(encoded_key_id);
+ if (raw_key_id.empty()) {
+ error_message->assign("'");
+ error_message->append(kKeyIdsTag);
+ error_message->append("'[");
+ error_message->append(base::UintToString(i));
+ error_message->append("] is not valid base64url encoded. Value: ");
+ error_message->append(ShortenTo64Characters(encoded_key_id));
+ return false;
+ }
+
+ // Add the decoded key ID to the list.
+ local_key_ids.push_back(std::vector<uint8>(
+ raw_key_id.data(), raw_key_id.data() + raw_key_id.length()));
+ }
+
+ // All done.
+ key_ids->swap(local_key_ids);
+ error_message->clear();
+ return true;
+}
+
void CreateLicenseRequest(const KeyIdList& key_ids,
MediaKeys::SessionType session_type,
std::vector<uint8>* license) {
« 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