Chromium Code Reviews| 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 #include "media/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 void AesDecryptor::CreateSession(const std::string& init_data_type, | 234 void AesDecryptor::CreateSession(const std::string& init_data_type, |
| 235 const uint8* init_data, | 235 const uint8* init_data, |
| 236 int init_data_length, | 236 int init_data_length, |
| 237 SessionType session_type, | 237 SessionType session_type, |
| 238 scoped_ptr<NewSessionCdmPromise> promise) { | 238 scoped_ptr<NewSessionCdmPromise> promise) { |
| 239 std::string web_session_id(base::UintToString(next_web_session_id_++)); | 239 std::string web_session_id(base::UintToString(next_web_session_id_++)); |
| 240 valid_sessions_.insert(web_session_id); | 240 valid_sessions_.insert(web_session_id); |
| 241 | 241 |
| 242 // For now, the AesDecryptor does not care about |init_data_type| or | 242 // For now, the AesDecryptor does not care about |init_data_type| or |
| 243 // |session_type|; just resolve the promise and then fire a message event | 243 // |session_type|; just resolve the promise and then fire a message event |
| 244 // with the |init_data| as the request. | 244 // using the |init_data| as the key id in the license request. |
|
xhwang
2014/08/08 20:31:12
nit: s/id/ID
jrummell
2014/08/09 00:14:17
Done.
| |
| 245 // TODO(jrummell): Validate |init_data_type| and |session_type|. | 245 // TODO(jrummell): Validate |init_data_type| and |session_type|. |
| 246 std::vector<uint8> message; | 246 std::vector<uint8> message; |
| 247 if (init_data && init_data_length) | 247 if (init_data && init_data_length) |
| 248 message.assign(init_data, init_data + init_data_length); | 248 CreateLicenseRequest(init_data, init_data_length, session_type, &message); |
| 249 | 249 |
| 250 promise->resolve(web_session_id); | 250 promise->resolve(web_session_id); |
| 251 | 251 |
| 252 session_message_cb_.Run(web_session_id, message, GURL()); | 252 session_message_cb_.Run(web_session_id, message, GURL()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void AesDecryptor::LoadSession(const std::string& web_session_id, | 255 void AesDecryptor::LoadSession(const std::string& web_session_id, |
| 256 scoped_ptr<NewSessionCdmPromise> promise) { | 256 scoped_ptr<NewSessionCdmPromise> promise) { |
| 257 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems | 257 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems |
| 258 // that do not support loadSession. See http://crbug.com/342481 | 258 // that do not support loadSession. See http://crbug.com/342481 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 269 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. | 269 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. |
| 270 if (valid_sessions_.find(web_session_id) == valid_sessions_.end()) { | 270 if (valid_sessions_.find(web_session_id) == valid_sessions_.end()) { |
| 271 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 271 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 | 274 |
| 275 std::string key_string(reinterpret_cast<const char*>(response), | 275 std::string key_string(reinterpret_cast<const char*>(response), |
| 276 response_length); | 276 response_length); |
| 277 | 277 |
| 278 KeyIdAndKeyPairs keys; | 278 KeyIdAndKeyPairs keys; |
| 279 if (!ExtractKeysFromJWKSet(key_string, &keys)) { | 279 SessionType session_type = MediaKeys::TEMPORARY_SESSION; |
| 280 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) { | |
| 280 promise->reject( | 281 promise->reject( |
| 281 INVALID_ACCESS_ERROR, 0, "response is not a valid JSON Web Key Set."); | 282 INVALID_ACCESS_ERROR, 0, "response is not a valid JSON Web Key Set."); |
| 282 return; | 283 return; |
| 283 } | 284 } |
| 284 | 285 |
| 285 // Make sure that at least one key was extracted. | 286 // Make sure that at least one key was extracted. |
| 286 if (keys.empty()) { | 287 if (keys.empty()) { |
| 287 promise->reject( | 288 promise->reject( |
| 288 INVALID_ACCESS_ERROR, 0, "response does not contain any keys."); | 289 INVALID_ACCESS_ERROR, 0, "response does not contain any keys."); |
| 289 return; | 290 return; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 bool AesDecryptor::DecryptionKey::Init() { | 488 bool AesDecryptor::DecryptionKey::Init() { |
| 488 CHECK(!secret_.empty()); | 489 CHECK(!secret_.empty()); |
| 489 decryption_key_.reset(crypto::SymmetricKey::Import( | 490 decryption_key_.reset(crypto::SymmetricKey::Import( |
| 490 crypto::SymmetricKey::AES, secret_)); | 491 crypto::SymmetricKey::AES, secret_)); |
| 491 if (!decryption_key_) | 492 if (!decryption_key_) |
| 492 return false; | 493 return false; |
| 493 return true; | 494 return true; |
| 494 } | 495 } |
| 495 | 496 |
| 496 } // namespace media | 497 } // namespace media |
| OLD | NEW |