OLD | NEW |
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" | |
13 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
14 #include "media/base/media_keys.h" | 13 #include "media/base/media_keys.h" |
15 | 14 |
16 namespace media { | 15 namespace media { |
17 | 16 |
18 // The ClearKey license request format (ref: | 17 // The ClearKey license request format (ref: |
19 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#clear-key) | 18 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#clear-key) |
20 // is a JSON object containing the following members: | 19 // is a JSON object containing the following members: |
21 // "kids" : An array of key IDs. Each element of the array is the base64url | 20 // "kids" : An array of key IDs. Each element of the array is the base64url |
22 // encoding of the octet sequence containing the key ID value. | 21 // encoding of the octet sequence containing the key ID value. |
(...skipping 19 matching lines...) Expand all Loading... |
42 // { "kty":"oct", | 41 // { "kty":"oct", |
43 // "alg":"A128KW", | 42 // "alg":"A128KW", |
44 // "kid":"AQIDBAUGBwgJCgsMDQ4PEA", | 43 // "kid":"AQIDBAUGBwgJCgsMDQ4PEA", |
45 // "k":"FBUWFxgZGhscHR4fICEiIw" } | 44 // "k":"FBUWFxgZGhscHR4fICEiIw" } |
46 | 45 |
47 // There may be other properties specified, but they are ignored. | 46 // There may be other properties specified, but they are ignored. |
48 // 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: |
49 // 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 |
50 | 49 |
51 // Vector of key IDs. | 50 // Vector of key IDs. |
52 typedef std::vector<std::vector<uint8>> KeyIdList; | 51 typedef std::vector<std::vector<uint8_t>> KeyIdList; |
53 | 52 |
54 // Vector of [key_id, key_value] pairs. Values are raw binary data, stored in | 53 // Vector of [key_id, key_value] pairs. Values are raw binary data, stored in |
55 // strings for convenience. | 54 // strings for convenience. |
56 typedef std::pair<std::string, std::string> KeyIdAndKeyPair; | 55 typedef std::pair<std::string, std::string> KeyIdAndKeyPair; |
57 typedef std::vector<KeyIdAndKeyPair> KeyIdAndKeyPairs; | 56 typedef std::vector<KeyIdAndKeyPair> KeyIdAndKeyPairs; |
58 | 57 |
59 // Converts a single |key|, |key_id| pair to a JSON Web Key Set. | 58 // Converts a single |key|, |key_id| pair to a JSON Web Key Set. |
60 MEDIA_EXPORT std::string GenerateJWKSet(const uint8* key, int key_length, | 59 MEDIA_EXPORT std::string GenerateJWKSet(const uint8_t* key, |
61 const uint8* key_id, int key_id_length); | 60 int key_length, |
| 61 const uint8_t* key_id, |
| 62 int key_id_length); |
62 | 63 |
63 // Converts a set of |key|, |key_id| pairs to a JSON Web Key Set. | 64 // Converts a set of |key|, |key_id| pairs to a JSON Web Key Set. |
64 MEDIA_EXPORT std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys, | 65 MEDIA_EXPORT std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys, |
65 MediaKeys::SessionType session_type); | 66 MediaKeys::SessionType session_type); |
66 | 67 |
67 // Extracts the JSON Web Keys from a JSON Web Key Set. If |input| looks like | 68 // Extracts the JSON Web Keys from a JSON Web Key Set. If |input| looks like |
68 // a valid JWK Set, then true is returned and |keys| and |session_type| are | 69 // a valid JWK Set, then true is returned and |keys| and |session_type| are |
69 // updated to contain the values found. Otherwise return false. | 70 // updated to contain the values found. Otherwise return false. |
70 MEDIA_EXPORT bool ExtractKeysFromJWKSet(const std::string& jwk_set, | 71 MEDIA_EXPORT bool ExtractKeysFromJWKSet(const std::string& jwk_set, |
71 KeyIdAndKeyPairs* keys, | 72 KeyIdAndKeyPairs* keys, |
72 MediaKeys::SessionType* session_type); | 73 MediaKeys::SessionType* session_type); |
73 | 74 |
74 // Extracts the Key Ids from a Key IDs Initialization Data | 75 // Extracts the Key Ids from a Key IDs Initialization Data |
75 // (https://w3c.github.io/encrypted-media/keyids-format.html). If |input| looks | 76 // (https://w3c.github.io/encrypted-media/keyids-format.html). If |input| looks |
76 // valid, then true is returned and |key_ids| is updated to contain the values | 77 // valid, then true is returned and |key_ids| is updated to contain the values |
77 // found. Otherwise return false and |error_message| contains the reason. | 78 // found. Otherwise return false and |error_message| contains the reason. |
78 MEDIA_EXPORT bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input, | 79 MEDIA_EXPORT bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input, |
79 KeyIdList* key_ids, | 80 KeyIdList* key_ids, |
80 std::string* error_message); | 81 std::string* error_message); |
81 | 82 |
82 // Creates a license request message for the |key_ids| and |session_type| | 83 // Creates a license request message for the |key_ids| and |session_type| |
83 // specified. |license| is updated to contain the resulting JSON string. | 84 // specified. |license| is updated to contain the resulting JSON string. |
84 MEDIA_EXPORT void CreateLicenseRequest(const KeyIdList& key_ids, | 85 MEDIA_EXPORT void CreateLicenseRequest(const KeyIdList& key_ids, |
85 MediaKeys::SessionType session_type, | 86 MediaKeys::SessionType session_type, |
86 std::vector<uint8>* license); | 87 std::vector<uint8_t>* license); |
87 | 88 |
88 // Creates a keyIDs init_data message for the |key_ids| specified. | 89 // Creates a keyIDs init_data message for the |key_ids| specified. |
89 // |key_ids_init_data| is updated to contain the resulting JSON string. | 90 // |key_ids_init_data| is updated to contain the resulting JSON string. |
90 MEDIA_EXPORT void CreateKeyIdsInitData(const KeyIdList& key_ids, | 91 MEDIA_EXPORT void CreateKeyIdsInitData(const KeyIdList& key_ids, |
91 std::vector<uint8>* key_ids_init_data); | 92 std::vector<uint8_t>* key_ids_init_data); |
92 | 93 |
93 // Extract the first key from the license request message. Returns true if | 94 // Extract the first key from the license request message. Returns true if |
94 // |license| is a valid license request and contains at least one key, | 95 // |license| is a valid license request and contains at least one key, |
95 // otherwise false and |first_key| is not touched. | 96 // otherwise false and |first_key| is not touched. |
96 MEDIA_EXPORT bool ExtractFirstKeyIdFromLicenseRequest( | 97 MEDIA_EXPORT bool ExtractFirstKeyIdFromLicenseRequest( |
97 const std::vector<uint8>& license, | 98 const std::vector<uint8_t>& license, |
98 std::vector<uint8>* first_key); | 99 std::vector<uint8_t>* first_key); |
99 | 100 |
100 } // namespace media | 101 } // namespace media |
101 | 102 |
102 #endif // MEDIA_CDM_JSON_WEB_KEY_H_ | 103 #endif // MEDIA_CDM_JSON_WEB_KEY_H_ |
OLD | NEW |