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.
|
|
|
|
*/
|
2014-09-24 02:04:49 +04:00
|
|
|
|
2015-01-16 00:37:54 +03:00
|
|
|
#include "ClearKeyDecryptionManager.h"
|
2014-09-24 02:04:49 +04:00
|
|
|
#include "ClearKeySession.h"
|
|
|
|
#include "ClearKeyUtils.h"
|
2014-12-18 23:54:34 +03:00
|
|
|
#include "ClearKeyStorage.h"
|
|
|
|
#include "gmp-task-utils.h"
|
2014-09-24 02:04:49 +04:00
|
|
|
#include "gmp-api/gmp-decryption.h"
|
2015-04-02 23:08:27 +03:00
|
|
|
#include "Endian.h"
|
|
|
|
#include <assert.h>
|
2015-05-06 02:40:42 +03:00
|
|
|
#include <string.h>
|
2014-09-24 02:04:49 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
ClearKeySession::ClearKeySession(const std::string& aSessionId,
|
2014-12-18 23:54:34 +03:00
|
|
|
GMPDecryptorCallback* aCallback,
|
|
|
|
GMPSessionType aSessionType)
|
2014-09-24 02:04:49 +04:00
|
|
|
: mSessionId(aSessionId)
|
|
|
|
, mCallback(aCallback)
|
2014-12-18 23:54:34 +03:00
|
|
|
, mSessionType(aSessionType)
|
2014-09-24 02:04:49 +04:00
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySession ctor %p", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearKeySession::~ClearKeySession()
|
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySession dtor %p", this);
|
2015-01-16 00:37:54 +03:00
|
|
|
|
|
|
|
auto& keyIds = GetKeyIds();
|
|
|
|
for (auto it = keyIds.begin(); it != keyIds.end(); it++) {
|
2015-04-02 23:08:27 +03:00
|
|
|
assert(ClearKeyDecryptionManager::Get()->HasKeyForKeyId(*it));
|
2015-01-16 00:37:54 +03:00
|
|
|
|
|
|
|
ClearKeyDecryptionManager::Get()->ReleaseKeyId(*it);
|
|
|
|
mCallback->KeyStatusChanged(&mSessionId[0], mSessionId.size(),
|
|
|
|
&(*it)[0], it->size(),
|
|
|
|
kGMPUnknown);
|
|
|
|
}
|
2014-09-24 02:04:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-01-09 04:30:07 +03:00
|
|
|
ClearKeySession::Init(uint32_t aCreateSessionToken,
|
|
|
|
uint32_t aPromiseId,
|
2014-09-24 02:04:49 +04:00
|
|
|
const uint8_t* aInitData, uint32_t aInitDataSize)
|
|
|
|
{
|
|
|
|
CK_LOGD("ClearKeySession::Init");
|
|
|
|
|
|
|
|
ClearKeyUtils::ParseInitData(aInitData, aInitDataSize, mKeyIds);
|
|
|
|
if (!mKeyIds.size()) {
|
|
|
|
const char message[] = "Couldn't parse cenc key init data";
|
|
|
|
mCallback->RejectPromise(aPromiseId, kGMPAbortError, message, strlen(message));
|
|
|
|
return;
|
|
|
|
}
|
2015-01-09 04:30:07 +03:00
|
|
|
|
|
|
|
mCallback->SetSessionId(aCreateSessionToken, &mSessionId[0], mSessionId.length());
|
|
|
|
|
|
|
|
mCallback->ResolvePromise(aPromiseId);
|
2014-09-24 02:04:49 +04:00
|
|
|
}
|
2014-12-18 23:54:34 +03:00
|
|
|
|
|
|
|
GMPSessionType
|
|
|
|
ClearKeySession::Type() const
|
|
|
|
{
|
|
|
|
return mSessionType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearKeySession::AddKeyId(const KeyId& aKeyId)
|
|
|
|
{
|
|
|
|
mKeyIds.push_back(aKeyId);
|
|
|
|
}
|