2015-04-02 23:08:27 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015, Mozilla Foundation and contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2015-01-12 10:15:55 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-01-12 10:15:55 +03:00
|
|
|
#include "ClearKeyDecryptionManager.h"
|
|
|
|
#include "ClearKeySessionManager.h"
|
|
|
|
#include "ClearKeyUtils.h"
|
|
|
|
#include "ClearKeyStorage.h"
|
2016-10-19 12:25:00 +03:00
|
|
|
#include "ClearKeyPersistence.h"
|
2017-01-14 00:23:31 +03:00
|
|
|
#include "gmp-task-utils.h"
|
2015-04-02 23:08:27 +03:00
|
|
|
#include <assert.h>
|
2015-01-12 10:15:55 +03:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeySessionManager::ClearKeySessionManager()
|
2015-01-12 10:15:55 +03:00
|
|
|
: mDecryptionManager(ClearKeyDecryptionManager::Get())
|
|
|
|
{
|
2015-01-27 08:35:36 +03:00
|
|
|
CK_LOGD("ClearKeySessionManager ctor %p", this);
|
2015-01-12 10:15:55 +03:00
|
|
|
AddRef();
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
if (GetPlatform()->createthread(&mThread) != GMPNoErr) {
|
|
|
|
CK_LOGD("failed to create thread in clearkey cdm");
|
|
|
|
mThread = nullptr;
|
|
|
|
}
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ClearKeySessionManager::~ClearKeySessionManager()
|
|
|
|
{
|
2015-01-27 08:35:36 +03:00
|
|
|
CK_LOGD("ClearKeySessionManager dtor %p", this);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeySessionManager::Init(GMPDecryptorCallback* aCallback,
|
|
|
|
bool aDistinctiveIdentifierAllowed,
|
2016-07-07 08:26:15 +03:00
|
|
|
bool aPersistentStateAllowed)
|
2015-01-12 10:15:55 +03:00
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::Init");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback = aCallback;
|
|
|
|
ClearKeyPersistence::EnsureInitialized();
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeySessionManager::CreateSession(uint32_t aCreateSessionToken,
|
|
|
|
uint32_t aPromiseId,
|
|
|
|
const char* aInitDataType,
|
|
|
|
uint32_t aInitDataTypeSize,
|
2015-01-12 10:15:55 +03:00
|
|
|
const uint8_t* aInitData,
|
|
|
|
uint32_t aInitDataSize,
|
2017-01-14 00:23:31 +03:00
|
|
|
GMPSessionType aSessionType)
|
2015-01-12 10:15:55 +03:00
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::CreateSession type:%s", aInitDataType);
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
string initDataType(aInitDataType, aInitDataType + aInitDataTypeSize);
|
|
|
|
// initDataType must be "cenc", "keyids", or "webm".
|
|
|
|
if (initDataType != "cenc" &&
|
|
|
|
initDataType != "keyids" &&
|
|
|
|
initDataType != "webm") {
|
|
|
|
string message = "'" + initDataType + "' is an initDataType unsupported by ClearKey";
|
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPNotSupportedError,
|
|
|
|
message.c_str(), message.size());
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
if (ClearKeyPersistence::DeferCreateSessionIfNotReady(this,
|
|
|
|
aCreateSessionToken,
|
|
|
|
aPromiseId,
|
|
|
|
initDataType,
|
|
|
|
aInitData,
|
|
|
|
aInitDataSize,
|
|
|
|
aSessionType)) {
|
2016-10-19 12:25:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
string sessionId = ClearKeyPersistence::GetNewSessionId(aSessionType);
|
2015-04-02 23:08:27 +03:00
|
|
|
assert(mSessions.find(sessionId) == mSessions.end());
|
2015-01-12 10:15:55 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeySession* session = new ClearKeySession(sessionId, mCallback, aSessionType);
|
|
|
|
session->Init(aCreateSessionToken, aPromiseId, initDataType, aInitData, aInitDataSize);
|
2015-01-12 10:15:55 +03:00
|
|
|
mSessions[sessionId] = session;
|
|
|
|
|
|
|
|
const vector<KeyId>& sessionKeys = session->GetKeyIds();
|
|
|
|
vector<KeyId> neededKeys;
|
|
|
|
for (auto it = sessionKeys.begin(); it != sessionKeys.end(); it++) {
|
|
|
|
// Need to request this key ID from the client. We always send a key
|
|
|
|
// request, whether or not another session has sent a request with the same
|
|
|
|
// key ID. Otherwise a script can end up waiting for another script to
|
|
|
|
// respond to the request (which may not necessarily happen).
|
|
|
|
neededKeys.push_back(*it);
|
|
|
|
mDecryptionManager->ExpectKeyId(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (neededKeys.empty()) {
|
|
|
|
CK_LOGD("No keys needed from client.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send a request for needed key data.
|
|
|
|
string request;
|
|
|
|
ClearKeyUtils::MakeKeyRequest(neededKeys, request, aSessionType);
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->SessionMessage(&sessionId[0], sessionId.length(),
|
|
|
|
kGMPLicenseRequest,
|
|
|
|
(uint8_t*)&request[0], request.length());
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::LoadSession(uint32_t aPromiseId,
|
|
|
|
const char* aSessionId,
|
|
|
|
uint32_t aSessionIdLength)
|
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::LoadSession");
|
2016-10-19 12:25:00 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
if (!ClearKeyUtils::IsValidSessionId(aSessionId, aSessionIdLength)) {
|
|
|
|
mCallback->ResolveLoadSessionPromise(aPromiseId, false);
|
2016-10-19 12:25:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
if (ClearKeyPersistence::DeferLoadSessionIfNotReady(this,
|
|
|
|
aPromiseId,
|
|
|
|
aSessionId,
|
|
|
|
aSessionIdLength)) {
|
2016-10-19 12:25:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
string sid(aSessionId, aSessionId + aSessionIdLength);
|
|
|
|
if (!ClearKeyPersistence::IsPersistentSessionId(sid)) {
|
|
|
|
mCallback->ResolveLoadSessionPromise(aPromiseId, false);
|
2016-10-19 12:25:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
// Callsback PersistentSessionDataLoaded with results...
|
|
|
|
ClearKeyPersistence::LoadSessionData(this, sid, aPromiseId);
|
2016-10-19 12:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeySessionManager::PersistentSessionDataLoaded(GMPErr aStatus,
|
|
|
|
uint32_t aPromiseId,
|
2016-10-19 12:25:00 +03:00
|
|
|
const string& aSessionId,
|
|
|
|
const uint8_t* aKeyData,
|
|
|
|
uint32_t aKeyDataSize)
|
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::PersistentSessionDataLoaded");
|
2017-01-14 00:23:31 +03:00
|
|
|
if (GMP_FAILED(aStatus) ||
|
|
|
|
Contains(mSessions, aSessionId) ||
|
2016-10-19 12:25:00 +03:00
|
|
|
(aKeyDataSize % (2 * CENC_KEY_LEN)) != 0) {
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->ResolveLoadSessionPromise(aPromiseId, false);
|
2016-10-19 12:25:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearKeySession* session = new ClearKeySession(aSessionId,
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback,
|
|
|
|
kGMPPersistentSession);
|
2016-10-19 12:25:00 +03:00
|
|
|
mSessions[aSessionId] = session;
|
|
|
|
|
|
|
|
uint32_t numKeys = aKeyDataSize / (2 * CENC_KEY_LEN);
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
vector<GMPMediaKeyInfo> key_infos;
|
2016-10-19 12:25:00 +03:00
|
|
|
vector<KeyIdPair> keyPairs;
|
|
|
|
for (uint32_t i = 0; i < numKeys; i ++) {
|
|
|
|
const uint8_t* base = aKeyData + 2 * CENC_KEY_LEN * i;
|
|
|
|
|
|
|
|
KeyIdPair keyPair;
|
|
|
|
|
|
|
|
keyPair.mKeyId = KeyId(base, base + CENC_KEY_LEN);
|
|
|
|
assert(keyPair.mKeyId.size() == CENC_KEY_LEN);
|
|
|
|
|
|
|
|
keyPair.mKey = Key(base + CENC_KEY_LEN, base + 2 * CENC_KEY_LEN);
|
|
|
|
assert(keyPair.mKey.size() == CENC_KEY_LEN);
|
|
|
|
|
|
|
|
session->AddKeyId(keyPair.mKeyId);
|
|
|
|
|
|
|
|
mDecryptionManager->ExpectKeyId(keyPair.mKeyId);
|
|
|
|
mDecryptionManager->InitKey(keyPair.mKeyId, keyPair.mKey);
|
|
|
|
mKeyIds.insert(keyPair.mKey);
|
2017-01-11 23:52:05 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
keyPairs.push_back(keyPair);
|
|
|
|
key_infos.push_back(GMPMediaKeyInfo(&keyPairs[i].mKeyId[0],
|
|
|
|
keyPairs[i].mKeyId.size(),
|
|
|
|
kGMPUsable));
|
2016-10-19 12:25:00 +03:00
|
|
|
}
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->BatchedKeyStatusChanged(&aSessionId[0], aSessionId.size(),
|
|
|
|
key_infos.data(), key_infos.size());
|
2016-10-19 12:25:00 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->ResolveLoadSessionPromise(aPromiseId, true);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::UpdateSession(uint32_t aPromiseId,
|
|
|
|
const char* aSessionId,
|
|
|
|
uint32_t aSessionIdLength,
|
|
|
|
const uint8_t* aResponse,
|
|
|
|
uint32_t aResponseSize)
|
|
|
|
{
|
2017-01-11 23:52:05 +03:00
|
|
|
CK_LOGD("ClearKeySessionManager::UpdateSession");
|
2017-01-14 00:23:31 +03:00
|
|
|
string sessionId(aSessionId, aSessionId + aSessionIdLength);
|
2015-01-12 10:15:55 +03:00
|
|
|
|
|
|
|
auto itr = mSessions.find(sessionId);
|
|
|
|
if (itr == mSessions.end() || !(itr->second)) {
|
|
|
|
CK_LOGW("ClearKey CDM couldn't resolve session ID in UpdateSession.");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPNotFoundError, nullptr, 0);
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ClearKeySession* session = itr->second;
|
|
|
|
|
2016-10-07 13:16:30 +03:00
|
|
|
// Verify the size of session response.
|
|
|
|
if (aResponseSize >= kMaxSessionResponseLength) {
|
|
|
|
CK_LOGW("Session response size is not within a reasonable size.");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPTypeError, nullptr, 0);
|
2016-10-07 13:16:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-12 10:15:55 +03:00
|
|
|
// Parse the response for any (key ID, key) pairs.
|
|
|
|
vector<KeyIdPair> keyPairs;
|
2017-01-14 00:23:31 +03:00
|
|
|
if (!ClearKeyUtils::ParseJWK(aResponse, aResponseSize, keyPairs, session->Type())) {
|
2015-01-12 10:15:55 +03:00
|
|
|
CK_LOGW("ClearKey CDM failed to parse JSON Web Key.");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPTypeError, nullptr, 0);
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
vector<GMPMediaKeyInfo> key_infos;
|
2016-10-04 12:18:46 +03:00
|
|
|
for (size_t i = 0; i < keyPairs.size(); i++) {
|
|
|
|
KeyIdPair& keyPair = keyPairs[i];
|
|
|
|
mDecryptionManager->InitKey(keyPair.mKeyId, keyPair.mKey);
|
|
|
|
mKeyIds.insert(keyPair.mKeyId);
|
2017-01-14 00:23:31 +03:00
|
|
|
key_infos.push_back(GMPMediaKeyInfo(&keyPair.mKeyId[0],
|
|
|
|
keyPair.mKeyId.size(),
|
|
|
|
kGMPUsable));
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->BatchedKeyStatusChanged(aSessionId, aSessionIdLength,
|
|
|
|
key_infos.data(), key_infos.size());
|
2015-01-12 10:15:55 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
if (session->Type() != kGMPPersistentSession) {
|
|
|
|
mCallback->ResolvePromise(aPromiseId);
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the keys on disk. We store a record whose name is the sessionId,
|
|
|
|
// and simply append each keyId followed by its key.
|
|
|
|
vector<uint8_t> keydata;
|
|
|
|
Serialize(session, keydata);
|
2017-01-14 00:23:31 +03:00
|
|
|
GMPTask* resolve = WrapTask(mCallback, &GMPDecryptorCallback::ResolvePromise, aPromiseId);
|
|
|
|
static const char* message = "Couldn't store cenc key init data";
|
|
|
|
GMPTask* reject = WrapTask(mCallback,
|
|
|
|
&GMPDecryptorCallback::RejectPromise,
|
|
|
|
aPromiseId,
|
|
|
|
kGMPInvalidStateError,
|
|
|
|
message,
|
|
|
|
strlen(message));
|
|
|
|
StoreData(sessionId, keydata, resolve, reject);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::Serialize(const ClearKeySession* aSession,
|
|
|
|
std::vector<uint8_t>& aOutKeyData)
|
|
|
|
{
|
|
|
|
const std::vector<KeyId>& keyIds = aSession->GetKeyIds();
|
|
|
|
for (size_t i = 0; i < keyIds.size(); i++) {
|
|
|
|
const KeyId& keyId = keyIds[i];
|
|
|
|
if (!mDecryptionManager->HasKeyForKeyId(keyId)) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-07 01:14:04 +03:00
|
|
|
assert(keyId.size() == CENC_KEY_LEN);
|
2015-01-12 10:15:55 +03:00
|
|
|
aOutKeyData.insert(aOutKeyData.end(), keyId.begin(), keyId.end());
|
|
|
|
const Key& key = mDecryptionManager->GetDecryptionKey(keyId);
|
2016-10-07 01:14:04 +03:00
|
|
|
assert(key.size() == CENC_KEY_LEN);
|
2015-01-12 10:15:55 +03:00
|
|
|
aOutKeyData.insert(aOutKeyData.end(), key.begin(), key.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::CloseSession(uint32_t aPromiseId,
|
|
|
|
const char* aSessionId,
|
|
|
|
uint32_t aSessionIdLength)
|
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::CloseSession");
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
string sessionId(aSessionId, aSessionId + aSessionIdLength);
|
2015-01-12 10:15:55 +03:00
|
|
|
auto itr = mSessions.find(sessionId);
|
|
|
|
if (itr == mSessions.end()) {
|
|
|
|
CK_LOGW("ClearKey CDM couldn't close non-existent session.");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPNotFoundError, nullptr, 0);
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearKeySession* session = itr->second;
|
2015-04-02 23:08:27 +03:00
|
|
|
assert(session);
|
2015-01-12 10:15:55 +03:00
|
|
|
|
|
|
|
ClearInMemorySessionData(session);
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->SessionClosed(aSessionId, aSessionIdLength);
|
|
|
|
mCallback->ResolvePromise(aPromiseId);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::ClearInMemorySessionData(ClearKeySession* aSession)
|
|
|
|
{
|
|
|
|
mSessions.erase(aSession->Id());
|
|
|
|
delete aSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::RemoveSession(uint32_t aPromiseId,
|
|
|
|
const char* aSessionId,
|
|
|
|
uint32_t aSessionIdLength)
|
|
|
|
{
|
2017-01-11 23:52:05 +03:00
|
|
|
CK_LOGD("ClearKeySessionManager::RemoveSession");
|
2017-01-14 00:23:31 +03:00
|
|
|
string sessionId(aSessionId, aSessionId + aSessionIdLength);
|
2015-01-12 10:15:55 +03:00
|
|
|
auto itr = mSessions.find(sessionId);
|
|
|
|
if (itr == mSessions.end()) {
|
|
|
|
CK_LOGW("ClearKey CDM couldn't remove non-existent session.");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPNotFoundError, nullptr, 0);
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearKeySession* session = itr->second;
|
2015-04-02 23:08:27 +03:00
|
|
|
assert(session);
|
2015-01-12 10:15:55 +03:00
|
|
|
string sid = session->Id();
|
2017-01-14 00:23:31 +03:00
|
|
|
bool isPersistent = session->Type() == kGMPPersistentSession;
|
2015-01-12 10:15:55 +03:00
|
|
|
ClearInMemorySessionData(session);
|
|
|
|
|
|
|
|
if (!isPersistent) {
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->ResolvePromise(aPromiseId);
|
2015-01-12 10:15:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeyPersistence::PersistentSessionRemoved(sid);
|
2016-10-19 12:25:00 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
// Overwrite the record storing the sessionId's key data with a zero
|
|
|
|
// length record to delete it.
|
2015-01-12 10:15:55 +03:00
|
|
|
vector<uint8_t> emptyKeydata;
|
2017-01-14 00:23:31 +03:00
|
|
|
GMPTask* resolve = WrapTask(mCallback, &GMPDecryptorCallback::ResolvePromise, aPromiseId);
|
|
|
|
static const char* message = "Could not remove session";
|
|
|
|
GMPTask* reject = WrapTask(mCallback,
|
|
|
|
&GMPDecryptorCallback::RejectPromise,
|
|
|
|
aPromiseId,
|
|
|
|
kGMPInvalidAccessError,
|
|
|
|
message,
|
|
|
|
strlen(message));
|
|
|
|
StoreData(sessionId, emptyKeydata, resolve, reject);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySessionManager::SetServerCertificate(uint32_t aPromiseId,
|
|
|
|
const uint8_t* aServerCert,
|
|
|
|
uint32_t aServerCertSize)
|
|
|
|
{
|
|
|
|
// ClearKey CDM doesn't support this method by spec.
|
|
|
|
CK_LOGD("ClearKeySessionManager::SetServerCertificate");
|
2017-01-14 00:23:31 +03:00
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPNotSupportedError,
|
|
|
|
nullptr /* message */, 0 /* messageLen */);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
void
|
|
|
|
ClearKeySessionManager::Decrypt(GMPBuffer* aBuffer,
|
|
|
|
GMPEncryptedBufferMetadata* aMetadata)
|
2015-01-12 10:15:55 +03:00
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::Decrypt");
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
if (!mThread) {
|
|
|
|
CK_LOGW("No decrypt thread");
|
|
|
|
mCallback->Decrypted(aBuffer, GMPGenericErr);
|
|
|
|
return;
|
|
|
|
}
|
2017-01-11 23:52:05 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
mThread->Post(WrapTaskRefCounted(this,
|
|
|
|
&ClearKeySessionManager::DoDecrypt,
|
|
|
|
aBuffer, aMetadata));
|
|
|
|
}
|
2015-01-12 10:15:55 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
void
|
|
|
|
ClearKeySessionManager::DoDecrypt(GMPBuffer* aBuffer,
|
|
|
|
GMPEncryptedBufferMetadata* aMetadata)
|
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySessionManager::DoDecrypt");
|
2017-01-11 23:52:05 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
GMPErr rv = mDecryptionManager->Decrypt(aBuffer->Data(), aBuffer->Size(),
|
|
|
|
CryptoMetaData(aMetadata));
|
|
|
|
CK_LOGD("DeDecrypt finished with code %x\n", rv);
|
|
|
|
mCallback->Decrypted(aBuffer, rv);
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-14 00:23:31 +03:00
|
|
|
ClearKeySessionManager::Shutdown()
|
2015-01-12 10:15:55 +03:00
|
|
|
{
|
2017-01-14 00:23:31 +03:00
|
|
|
CK_LOGD("ClearKeySessionManager::Shutdown %p", this);
|
2015-01-12 10:15:55 +03:00
|
|
|
|
|
|
|
for (auto it = mSessions.begin(); it != mSessions.end(); it++) {
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
mSessions.clear();
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
void
|
|
|
|
ClearKeySessionManager::DecryptingComplete()
|
2015-01-12 10:15:55 +03:00
|
|
|
{
|
2017-01-14 00:23:31 +03:00
|
|
|
CK_LOGD("ClearKeySessionManager::DecryptingComplete %p", this);
|
2015-01-12 10:15:55 +03:00
|
|
|
|
2017-01-14 00:23:31 +03:00
|
|
|
GMPThread* thread = mThread;
|
|
|
|
thread->Join();
|
|
|
|
|
|
|
|
Shutdown();
|
|
|
|
mDecryptionManager = nullptr;
|
|
|
|
Release();
|
2015-01-12 10:15:55 +03:00
|
|
|
}
|