Commit 4d83add3 authored by jrummell's avatar jrummell Committed by Commit bot

Properly determine if a new key was added in AesDecryptor::Update()

BUG=448219
TEST=new test passes

Review URL: https://codereview.chromium.org/1002193005

Cr-Commit-Position: refs/heads/master@{#320958}
parent 1edacadd
...@@ -334,6 +334,7 @@ void AesDecryptor::UpdateSession(const std::string& session_id, ...@@ -334,6 +334,7 @@ void AesDecryptor::UpdateSession(const std::string& session_id,
return; return;
} }
bool key_added = false;
for (KeyIdAndKeyPairs::iterator it = keys.begin(); it != keys.end(); ++it) { for (KeyIdAndKeyPairs::iterator it = keys.begin(); it != keys.end(); ++it) {
if (it->second.length() != if (it->second.length() !=
static_cast<size_t>(DecryptConfig::kDecryptionKeySize)) { static_cast<size_t>(DecryptConfig::kDecryptionKeySize)) {
...@@ -341,6 +342,12 @@ void AesDecryptor::UpdateSession(const std::string& session_id, ...@@ -341,6 +342,12 @@ void AesDecryptor::UpdateSession(const std::string& session_id,
promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid key length."); promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid key length.");
return; return;
} }
// If this key_id doesn't currently exist in this session,
// a new key is added.
if (!HasKey(session_id, it->first))
key_added = true;
if (!AddDecryptionKey(session_id, it->first, it->second)) { if (!AddDecryptionKey(session_id, it->first, it->second)) {
promise->reject(INVALID_ACCESS_ERROR, 0, "Unable to add key."); promise->reject(INVALID_ACCESS_ERROR, 0, "Unable to add key.");
return; return;
...@@ -374,9 +381,7 @@ void AesDecryptor::UpdateSession(const std::string& session_id, ...@@ -374,9 +381,7 @@ void AesDecryptor::UpdateSession(const std::string& session_id,
} }
} }
// Assume that at least 1 new key has been successfully added and thus session_keys_change_cb_.Run(session_id, key_added, keys_info.Pass());
// sending true for |has_additional_usable_key|. http://crbug.com/448219.
session_keys_change_cb_.Run(session_id, true, keys_info.Pass());
} }
void AesDecryptor::CloseSession(const std::string& session_id, void AesDecryptor::CloseSession(const std::string& session_id,
...@@ -546,6 +551,16 @@ AesDecryptor::DecryptionKey* AesDecryptor::GetKey( ...@@ -546,6 +551,16 @@ AesDecryptor::DecryptionKey* AesDecryptor::GetKey(
return key_id_found->second->LatestDecryptionKey(); return key_id_found->second->LatestDecryptionKey();
} }
bool AesDecryptor::HasKey(const std::string& session_id,
const std::string& key_id) {
base::AutoLock auto_lock(key_map_lock_);
KeyIdToSessionKeysMap::const_iterator key_id_found = key_map_.find(key_id);
if (key_id_found == key_map_.end())
return false;
return key_id_found->second->Contains(session_id);
}
void AesDecryptor::DeleteKeysForSession(const std::string& session_id) { void AesDecryptor::DeleteKeysForSession(const std::string& session_id) {
base::AutoLock auto_lock(key_map_lock_); base::AutoLock auto_lock(key_map_lock_);
......
...@@ -126,6 +126,9 @@ class MEDIA_EXPORT AesDecryptor : public MediaKeys, ...@@ -126,6 +126,9 @@ class MEDIA_EXPORT AesDecryptor : public MediaKeys,
// the key. Returns NULL if no key is associated with |key_id|. // the key. Returns NULL if no key is associated with |key_id|.
DecryptionKey* GetKey(const std::string& key_id) const; DecryptionKey* GetKey(const std::string& key_id) const;
// Determines if |key_id| is already specified for |session_id|.
bool HasKey(const std::string& session_id, const std::string& key_id);
// Deletes all keys associated with |session_id|. // Deletes all keys associated with |session_id|.
void DeleteKeysForSession(const std::string& session_id); void DeleteKeysForSession(const std::string& session_id);
......
This diff is collapsed.
...@@ -302,6 +302,12 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase { ...@@ -302,6 +302,12 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
void OnEncryptedMediaInitData(const std::string& init_data_type, void OnEncryptedMediaInitData(const std::string& init_data_type,
const std::vector<uint8>& init_data, const std::vector<uint8>& init_data,
AesDecryptor* decryptor) override { AesDecryptor* decryptor) override {
// Since only 1 session is created, skip the request if the |init_data|
// has been seen before (no need to add the same key again).
if (init_data == prev_init_data_)
return;
prev_init_data_ = init_data;
if (current_session_id_.empty()) { if (current_session_id_.empty()) {
if (init_data_type == kCencInitDataType) { if (init_data_type == kCencInitDataType) {
// Since the 'cenc' files are not created with proper 'pssh' boxes, // Since the 'cenc' files are not created with proper 'pssh' boxes,
...@@ -340,6 +346,7 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase { ...@@ -340,6 +346,7 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
} }
std::string current_session_id_; std::string current_session_id_;
std::vector<uint8> prev_init_data_;
}; };
class RotatingKeyProvidingApp : public KeyProvidingApp { class RotatingKeyProvidingApp : public KeyProvidingApp {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment