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
|
|
|
|
2016-06-05 20:24:51 +03:00
|
|
|
#include "BigEndian.h"
|
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"
|
2016-10-06 10:23:38 +03:00
|
|
|
#include "psshparser/PsshParser.h"
|
2017-01-11 23:52:05 +03:00
|
|
|
|
2015-04-02 23:08:27 +03:00
|
|
|
#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;
|
2017-01-11 23:52:05 +03:00
|
|
|
using namespace cdm;
|
2014-09-24 02:04:49 +04:00
|
|
|
|
|
|
|
ClearKeySession::ClearKeySession(const std::string& aSessionId,
|
2017-01-11 23:52:05 +03:00
|
|
|
SessionType aSessionType)
|
2014-12-18 23:54:34 +03:00
|
|
|
: mSessionId(aSessionId), mSessionType(aSessionType) {
|
2014-09-24 02:04:49 +04:00
|
|
|
CK_LOGD("ClearKeySession ctor %p", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearKeySession::~ClearKeySession() {
|
|
|
|
CK_LOGD("ClearKeySession dtor %p", this);
|
|
|
|
}
|
|
|
|
|
2017-01-11 23:52:05 +03:00
|
|
|
bool ClearKeySession::Init(InitDataType aInitDataType, const uint8_t* aInitData,
|
|
|
|
uint32_t aInitDataSize) {
|
2014-09-24 02:04:49 +04:00
|
|
|
CK_LOGD("ClearKeySession::Init");
|
|
|
|
|
2017-01-11 23:52:05 +03:00
|
|
|
if (aInitDataType == InitDataType::kCenc) {
|
2016-07-15 00:31:07 +03:00
|
|
|
ParseCENCInitData(aInitData, aInitDataSize, mKeyIds);
|
2017-01-11 23:52:05 +03:00
|
|
|
} else if (aInitDataType == InitDataType::kKeyIds) {
|
2016-10-10 06:42:01 +03:00
|
|
|
ClearKeyUtils::ParseKeyIdsInitData(aInitData, aInitDataSize, mKeyIds);
|
2017-01-11 23:52:05 +03:00
|
|
|
} else if (aInitDataType == InitDataType::kWebM &&
|
|
|
|
aInitDataSize <= kMaxWebmInitDataSize) {
|
2015-12-03 21:24:11 +03:00
|
|
|
// "webm" initData format is simply the raw bytes of the keyId.
|
2019-09-03 22:10:42 +03:00
|
|
|
std::vector<uint8_t> keyId;
|
2015-12-03 21:24:11 +03:00
|
|
|
keyId.assign(aInitData, aInitData + aInitDataSize);
|
|
|
|
mKeyIds.push_back(keyId);
|
2015-11-27 07:13:40 +03:00
|
|
|
}
|
|
|
|
|
2017-08-04 10:09:38 +03:00
|
|
|
if (mKeyIds.empty()) {
|
2017-01-11 23:52:05 +03:00
|
|
|
return false;
|
2014-09-24 02:04:49 +04:00
|
|
|
}
|
2015-01-09 04:30:07 +03:00
|
|
|
|
2017-01-11 23:52:05 +03:00
|
|
|
return true;
|
2014-09-24 02:04:49 +04:00
|
|
|
}
|
2014-12-18 23:54:34 +03:00
|
|
|
|
|
|
|
SessionType ClearKeySession::Type() const { return mSessionType; }
|
|
|
|
|
|
|
|
void ClearKeySession::AddKeyId(const KeyId& aKeyId) {
|
|
|
|
mKeyIds.push_back(aKeyId);
|
|
|
|
}
|