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

Side by Side Diff: media/cdm/json_web_key.h

Issue 427993002: Implement ClearKey message format as JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CDM_JSON_WEB_KEY_H_ 5 #ifndef MEDIA_CDM_JSON_WEB_KEY_H_
6 #define MEDIA_CDM_JSON_WEB_KEY_H_ 6 #define MEDIA_CDM_JSON_WEB_KEY_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "media/base/media_export.h" 13 #include "media/base/media_export.h"
14 #include "media/base/media_keys.h"
14 15
15 namespace media { 16 namespace media {
16 17
18 // The ClearKey license request format is a JSON object containing the
19 // following members:
xhwang 2014/07/30 05:56:07 provide ref to the eme spec
jrummell 2014/07/30 18:44:15 Done.
20 // "kids" : An array of key IDs. Each element of the array is the base64url
21 // encoding of the octet sequence containing the key ID value.
22 // "type" : The requested SessionType.
23 // An example:
24 // { "kids":["67ef0gd8pvfd0","77ef0gd8pvfd0"], "type":"temporary" }
25
26 // The ClearKey license format is a JSON Web Key (JWK) Set containing
27 // representation of the symmetric key to be used for decryption.
28 // For each JWK in the set, the parameter values are as follows:
29 // "kty" (key type) : "oct" (octet sequence)
30 // "alg" (algorithm) : "A128KW" (AES key wrap using a 128-bit key)
31 // "k" (key value) : The base64url encoding of the octet sequence
32 // containing the symmetric key value.
33 // "kid" (key ID) : The base64url encoding of the octet sequence
34 // containing the key ID value.
35 // The JSON object may have an optional "type" member value, which may be
36 // any of the SessionType values. If not specified, the default value of
37 // "temporary" is used.
17 // A JSON Web Key Set looks like the following in JSON: 38 // A JSON Web Key Set looks like the following in JSON:
18 // { "keys": [ JWK1, JWK2, ... ] } 39 // { "keys": [ JWK1, JWK2, ... ], "type":"temporary" }
19 // A symmetric keys JWK looks like the following in JSON: 40 // A symmetric keys JWK looks like the following in JSON:
20 // { "kty":"oct", 41 // { "kty":"oct",
42 // "alg":"A128KW",
21 // "kid":"AQIDBAUGBwgJCgsMDQ4PEA", 43 // "kid":"AQIDBAUGBwgJCgsMDQ4PEA",
22 // "k":"FBUWFxgZGhscHR4fICEiIw" } 44 // "k":"FBUWFxgZGhscHR4fICEiIw" }
45
23 // There may be other properties specified, but they are ignored. 46 // There may be other properties specified, but they are ignored.
24 // Ref: http://tools.ietf.org/html/draft-ietf-jose-json-web-key and: 47 // Ref: http://tools.ietf.org/html/draft-ietf-jose-json-web-key and:
25 // http://tools.ietf.org/html/draft-jones-jose-json-private-and-symmetric-key 48 // http://tools.ietf.org/html/draft-jones-jose-json-private-and-symmetric-key
26 //
27 // For EME WD, both 'kid' and 'k' are base64 encoded strings, without trailing
28 // padding.
29 49
30 // Vector of [key_id, key_value] pairs. Values are raw binary data, stored in 50 // Vector of [key_id, key_value] pairs. Values are raw binary data, stored in
31 // strings for convenience. 51 // strings for convenience.
32 typedef std::pair<std::string, std::string> KeyIdAndKeyPair; 52 typedef std::pair<std::string, std::string> KeyIdAndKeyPair;
33 typedef std::vector<KeyIdAndKeyPair> KeyIdAndKeyPairs; 53 typedef std::vector<KeyIdAndKeyPair> KeyIdAndKeyPairs;
34 54
35 // Converts a single |key|, |key_id| pair to a JSON Web Key Set. 55 // Converts a single |key|, |key_id| pair to a JSON Web Key Set.
36 MEDIA_EXPORT std::string GenerateJWKSet(const uint8* key, int key_length, 56 MEDIA_EXPORT std::string GenerateJWKSet(const uint8* key, int key_length,
37 const uint8* key_id, int key_id_length); 57 const uint8* key_id, int key_id_length);
38 58
39 // Extracts the JSON Web Keys from a JSON Web Key Set. If |input| looks like 59 // Extracts the JSON Web Keys from a JSON Web Key Set. If |input| looks like
40 // a valid JWK Set, then true is returned and |keys| is updated to contain 60 // a valid JWK Set, then true is returned and |keys| and |session_type| are
41 // the list of keys found. Otherwise return false. 61 // updated to contain the values found. Otherwise return false.
42 MEDIA_EXPORT bool ExtractKeysFromJWKSet(const std::string& jwk_set, 62 MEDIA_EXPORT bool ExtractKeysFromJWKSet(const std::string& jwk_set,
43 KeyIdAndKeyPairs* keys); 63 KeyIdAndKeyPairs* keys,
64 MediaKeys::SessionType* session_type);
65
66 // Create a license request message for the |key_id| and |session_type|
67 // specified. Currently ClearKey generates a message for each key individually,
68 // so no need to take a list of |key_id|'s. |result| is updated to contain the
69 // resulting JSON string.
70 MEDIA_EXPORT void CreateLicenseRequest(const uint8* key_id,
71 int key_id_length,
72 MediaKeys::SessionType session_type,
73 std::vector<uint8>& result);
xhwang 2014/07/30 05:56:07 We prefer to using pointer for output parameters:
jrummell 2014/07/30 18:44:15 Done.
74
75 // Extract the first key from the license request message.
xhwang 2014/07/30 05:56:07 From the documentation on l.18-24, a license reque
jrummell 2014/07/30 18:44:15 Done.
76 MEDIA_EXPORT bool ExtractLicenseKey(const std::vector<uint8>& message,
xhwang 2014/07/30 05:56:07 what is the return value?
jrummell 2014/07/30 18:44:15 Done.
77 std::vector<uint8>& first_key);
xhwang 2014/07/30 05:56:07 ditto about passing pointer instead of ref
jrummell 2014/07/30 18:44:15 Done.
44 78
45 } // namespace media 79 } // namespace media
46 80
47 #endif // MEDIA_CDM_JSON_WEB_KEY_H_ 81 #endif // MEDIA_CDM_JSON_WEB_KEY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698