| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void AesDecryptor::CreateSession(const std::string& init_data_type, | 238 void AesDecryptor::CreateSession(const std::string& init_data_type, |
| 239 const uint8* init_data, | 239 const uint8* init_data, |
| 240 int init_data_length, | 240 int init_data_length, |
| 241 SessionType session_type, | 241 SessionType session_type, |
| 242 scoped_ptr<NewSessionCdmPromise> promise) { | 242 scoped_ptr<NewSessionCdmPromise> promise) { |
| 243 std::string web_session_id(base::UintToString(next_web_session_id_++)); | 243 std::string web_session_id(base::UintToString(next_web_session_id_++)); |
| 244 valid_sessions_.insert(web_session_id); | 244 valid_sessions_.insert(web_session_id); |
| 245 | 245 |
| 246 // For now, the AesDecryptor does not care about |init_data_type| or | 246 // For now, the AesDecryptor does not care about |init_data_type| or |
| 247 // |session_type|; just resolve the promise and then fire a message event | 247 // |session_type|; just resolve the promise and then fire a message event |
| 248 // with the |init_data| as the request. | 248 // using the |init_data| as the key ID in the license request. |
| 249 // TODO(jrummell): Validate |init_data_type| and |session_type|. | 249 // TODO(jrummell): Validate |init_data_type| and |session_type|. |
| 250 std::vector<uint8> message; | 250 std::vector<uint8> message; |
| 251 if (init_data && init_data_length) | 251 if (init_data && init_data_length) |
| 252 message.assign(init_data, init_data + init_data_length); | 252 CreateLicenseRequest(init_data, init_data_length, session_type, &message); |
| 253 | 253 |
| 254 promise->resolve(web_session_id); | 254 promise->resolve(web_session_id); |
| 255 | 255 |
| 256 session_message_cb_.Run(web_session_id, message, GURL()); | 256 session_message_cb_.Run(web_session_id, message, GURL()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void AesDecryptor::LoadSession(const std::string& web_session_id, | 259 void AesDecryptor::LoadSession(const std::string& web_session_id, |
| 260 scoped_ptr<NewSessionCdmPromise> promise) { | 260 scoped_ptr<NewSessionCdmPromise> promise) { |
| 261 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems | 261 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems |
| 262 // that do not support loadSession. See http://crbug.com/342481 | 262 // that do not support loadSession. See http://crbug.com/342481 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 273 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. | 273 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. |
| 274 if (valid_sessions_.find(web_session_id) == valid_sessions_.end()) { | 274 if (valid_sessions_.find(web_session_id) == valid_sessions_.end()) { |
| 275 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 275 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 std::string key_string(reinterpret_cast<const char*>(response), | 279 std::string key_string(reinterpret_cast<const char*>(response), |
| 280 response_length); | 280 response_length); |
| 281 | 281 |
| 282 KeyIdAndKeyPairs keys; | 282 KeyIdAndKeyPairs keys; |
| 283 if (!ExtractKeysFromJWKSet(key_string, &keys)) { | 283 SessionType session_type = MediaKeys::TEMPORARY_SESSION; |
| 284 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) { |
| 284 promise->reject( | 285 promise->reject( |
| 285 INVALID_ACCESS_ERROR, 0, "response is not a valid JSON Web Key Set."); | 286 INVALID_ACCESS_ERROR, 0, "response is not a valid JSON Web Key Set."); |
| 286 return; | 287 return; |
| 287 } | 288 } |
| 288 | 289 |
| 289 // Make sure that at least one key was extracted. | 290 // Make sure that at least one key was extracted. |
| 290 if (keys.empty()) { | 291 if (keys.empty()) { |
| 291 promise->reject( | 292 promise->reject( |
| 292 INVALID_ACCESS_ERROR, 0, "response does not contain any keys."); | 293 INVALID_ACCESS_ERROR, 0, "response does not contain any keys."); |
| 293 return; | 294 return; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 bool AesDecryptor::DecryptionKey::Init() { | 509 bool AesDecryptor::DecryptionKey::Init() { |
| 509 CHECK(!secret_.empty()); | 510 CHECK(!secret_.empty()); |
| 510 decryption_key_.reset(crypto::SymmetricKey::Import( | 511 decryption_key_.reset(crypto::SymmetricKey::Import( |
| 511 crypto::SymmetricKey::AES, secret_)); | 512 crypto::SymmetricKey::AES, secret_)); |
| 512 if (!decryption_key_) | 513 if (!decryption_key_) |
| 513 return false; | 514 return false; |
| 514 return true; | 515 return true; |
| 515 } | 516 } |
| 516 | 517 |
| 517 } // namespace media | 518 } // namespace media |
| OLD | NEW |