summaryrefslogtreecommitdiffstats
path: root/media/cdm
diff options
context:
space:
mode:
authorjrummell@chromium.org <jrummell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 20:16:20 +0000
committerjrummell@chromium.org <jrummell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 20:16:20 +0000
commite4c0cf8142f712a0bb077ed3444f6ca227faa707 (patch)
tree5824f4941cff41ffd495ebc69661723ad06a6b7c /media/cdm
parent35e66dd4471421c5b69d6372c291fad4c9066102 (diff)
downloadchromium_src-e4c0cf8142f712a0bb077ed3444f6ca227faa707.zip
chromium_src-e4c0cf8142f712a0bb077ed3444f6ca227faa707.tar.gz
chromium_src-e4c0cf8142f712a0bb077ed3444f6ca227faa707.tar.bz2
Convert AddKey() calls from EME v0.1b to WD format
The latest version of the EME spec replaces AddKey/2 with Update/1. Currently the ClearKey tests for v0.1b pass the key id and key as separate parameters. The new way is to pass them as a single parameter (JSON Web Key). Adding code to combine the parameters into a JWK for ClearKey. Also pass a single parameter for other key systems, to ensure that it works with a single parameter. BUG=224786 TEST=encrypted-media layout tests and browser_tests for encrypted media pass Review URL: https://codereview.chromium.org/65533011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/cdm')
-rw-r--r--media/cdm/json_web_key.cc51
-rw-r--r--media/cdm/json_web_key.h21
-rw-r--r--media/cdm/key_system_names.cc13
-rw-r--r--media/cdm/key_system_names.h35
4 files changed, 120 insertions, 0 deletions
diff --git a/media/cdm/json_web_key.cc b/media/cdm/json_web_key.cc
new file mode 100644
index 0000000..8749b25
--- /dev/null
+++ b/media/cdm/json_web_key.cc
@@ -0,0 +1,51 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/cdm/json_web_key.h"
+
+#include "base/base64.h"
+#include "base/json/json_string_value_serializer.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+
+namespace media {
+
+// TODO(jrummell): Move JWK operations from aes_decryptor into this file.
+
+const char kKeysTag[] = "keys";
+const char kKeyTypeTag[] = "kty";
+const char kSymmetricKeyValue[] = "oct";
+const char kKeyTag[] = "k";
+const char kKeyIdTag[] = "kid";
+
+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;
+ std::string key_id_base64;
+ base::Base64Encode(
+ std::string(reinterpret_cast<const char*>(key), key_length),
+ &key_base64);
+ base::Base64Encode(
+ std::string(reinterpret_cast<const char*>(key_id), key_id_length),
+ &key_id_base64);
+
+ // Create the JWK, and wrap it into a JWK Set.
+ scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue());
+ jwk->SetString(kKeyTypeTag, kSymmetricKeyValue);
+ jwk->SetString(kKeyTag, key_base64);
+ jwk->SetString(kKeyIdTag, key_id_base64);
+ scoped_ptr<base::ListValue> list(new base::ListValue());
+ list->Append(jwk.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;
+}
+
+} // namespace media
diff --git a/media/cdm/json_web_key.h b/media/cdm/json_web_key.h
new file mode 100644
index 0000000..83fa222
--- /dev/null
+++ b/media/cdm/json_web_key.h
@@ -0,0 +1,21 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_CDM_JSON_WEB_KEY_H_
+#define MEDIA_CDM_JSON_WEB_KEY_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// Convert |key|, |key_id| to a JSON Web Key Set.
+MEDIA_EXPORT std::string GenerateJWKSet(const uint8* key, int key_length,
+ const uint8* key_id, int key_id_length);
+
+} // namespace media
+
+#endif // MEDIA_CDM_JSON_WEB_KEY_H_
diff --git a/media/cdm/key_system_names.cc b/media/cdm/key_system_names.cc
new file mode 100644
index 0000000..97cc9e8
--- /dev/null
+++ b/media/cdm/key_system_names.cc
@@ -0,0 +1,13 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/cdm/key_system_names.h"
+
+namespace media {
+
+const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
+const char kUnprefixedClearKey[] = "org.w3.clearkey";
+const char kExternalClearKey[] = "org.chromium.externalclearkey";
+
+} // namespace media
diff --git a/media/cdm/key_system_names.h b/media/cdm/key_system_names.h
new file mode 100644
index 0000000..0216c69
--- /dev/null
+++ b/media/cdm/key_system_names.h
@@ -0,0 +1,35 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_CDM_KEY_SYSTEM_NAMES_H_
+#define MEDIA_CDM_KEY_SYSTEM_NAMES_H_
+
+#include <string>
+
+#include "media/base/media_export.h"
+
+namespace media {
+
+// TODO(jrummell): Change other uses of Clear Key to use this common value.
+
+// The key system names for Clear Key.
+MEDIA_EXPORT extern const char kPrefixedClearKey[];
+MEDIA_EXPORT extern const char kUnprefixedClearKey[];
+
+// The key system name for External Clear Key.
+MEDIA_EXPORT extern const char kExternalClearKey[];
+
+// Returns true if |key_system| is Clear Key, false otherwise.
+MEDIA_EXPORT inline bool IsClearKey(const std::string& key_system) {
+ return key_system == kPrefixedClearKey || key_system == kUnprefixedClearKey;
+}
+
+// Returns true if |key_system| is External Clear Key, false otherwise.
+MEDIA_EXPORT inline bool IsExternalClearKey(const std::string& key_system) {
+ return key_system == kExternalClearKey;
+}
+
+} // namespace media
+
+#endif // MEDIA_CDM_KEY_SYSTEM_NAMES_H_