Bug 1150437 - Make gmp-clearkey consistently Apache2 licensed. r=edwin,jwwang,kentuckyfriedtakahe

This commit is contained in:
Chris Pearce 2015-04-03 09:08:27 +13:00
parent 17aef946bf
commit 1fa249bfb8
27 changed files with 491 additions and 123 deletions

View File

@ -1,9 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include "AnnexB.h"
#include "mozilla/Endian.h"
#include "Endian.h"
using mozilla::BigEndian;

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __AnnexB_h__
#define __AnnexB_h__

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#ifndef __ArrayUtils_h__
#define __ArrayUtils_h__
#define MOZ_ARRAY_LENGTH(array_) \
(sizeof(array_)/sizeof(array_[0]))
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013, Mozilla Foundation and contributors
* 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013, Mozilla Foundation and contributors
* 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.

View File

@ -1,13 +1,23 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include "ClearKeyBase64.h"
#include <algorithm>
#include "mozilla/ArrayUtils.h"
using namespace std;
/**

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeyBase64_h__
#define __ClearKeyBase64_h__

View File

@ -1,19 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include <string.h>
#include <vector>
#include "ClearKeyDecryptionManager.h"
#include "gmp-decryption.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include <assert.h>
class ClearKeyDecryptor : public RefCounted
{
public:
MOZ_IMPLICIT ClearKeyDecryptor();
ClearKeyDecryptor();
void InitKey(const Key& aKey);
bool HasKey() const { return !!mKey.size(); }
@ -84,7 +95,7 @@ ClearKeyDecryptionManager::HasKeyForKeyId(const KeyId& aKeyId) const
const Key&
ClearKeyDecryptionManager::GetDecryptionKey(const KeyId& aKeyId)
{
MOZ_ASSERT(HasKeyForKeyId(aKeyId));
assert(HasKeyForKeyId(aKeyId));
return mDecryptors[aKeyId]->DecryptionKey();
}
@ -111,7 +122,7 @@ void
ClearKeyDecryptionManager::ReleaseKeyId(KeyId aKeyId)
{
CK_LOGD("ClearKeyDecryptionManager::ReleaseKeyId");
MOZ_ASSERT(HasKeyForKeyId(aKeyId));
assert(HasKeyForKeyId(aKeyId));
ClearKeyDecryptor* decryptor = mDecryptors[aKeyId];
if (!decryptor->Release()) {
@ -178,7 +189,7 @@ ClearKeyDecryptor::Decrypt(uint8_t* aBuffer, uint32_t aBufferSize,
memcpy(&tmp[0], aBuffer, aBufferSize);
}
MOZ_ASSERT(aMetadata->IVSize() == 8 || aMetadata->IVSize() == 16);
assert(aMetadata->IVSize() == 8 || aMetadata->IVSize() == 16);
std::vector<uint8_t> iv(aMetadata->IV(), aMetadata->IV() + aMetadata->IVSize());
iv.insert(iv.end(), CLEARKEY_KEY_LEN - aMetadata->IVSize(), 0);

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeyDecryptionManager_h__
#define __ClearKeyDecryptionManager_h__

View File

@ -1,20 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include "ClearKeyPersistence.h"
#include "ClearKeyUtils.h"
#include "ClearKeyStorage.h"
#include "ClearKeySessionManager.h"
#include "mozilla/RefPtr.h"
#include "RefCounted.h"
#include <stdint.h>
#include <string.h>
#include <set>
#include <vector>
#include <sstream>
#include <assert.h>
using namespace mozilla;
using namespace std;
// Whether we've loaded the persistent session ids from GMPStorage yet.
@ -36,7 +48,7 @@ ReadAllRecordsFromIterator(GMPRecordIterator* aRecordIterator,
void* aUserArg,
GMPErr aStatus)
{
MOZ_ASSERT(sPersistentKeyState == LOADING);
assert(sPersistentKeyState == LOADING);
if (GMP_SUCCEEDED(aStatus)) {
// Extract the record names which are valid uint32_t's; they're
// the persistent session ids.
@ -44,7 +56,7 @@ ReadAllRecordsFromIterator(GMPRecordIterator* aRecordIterator,
uint32_t len = 0;
while (GMP_SUCCEEDED(aRecordIterator->GetName(&name, &len))) {
if (ClearKeyUtils::IsValidSessionId(name, len)) {
MOZ_ASSERT(name[len] == 0);
assert(name[len] == 0);
sPersistentSessionIds.insert(atoi(name));
}
aRecordIterator->NextRecord();

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeyPersistence_h__
#define __ClearKeyPersistence_h__

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include "ClearKeyDecryptionManager.h"
#include "ClearKeySession.h"
@ -9,7 +21,8 @@
#include "gmp-task-utils.h"
#include "gmp-api/gmp-decryption.h"
#include "mozilla/Endian.h"
#include "Endian.h"
#include <assert.h>
using namespace mozilla;
@ -29,7 +42,7 @@ ClearKeySession::~ClearKeySession()
auto& keyIds = GetKeyIds();
for (auto it = keyIds.begin(); it != keyIds.end(); it++) {
MOZ_ASSERT(ClearKeyDecryptionManager::Get()->HasKeyForKeyId(*it));
assert(ClearKeyDecryptionManager::Get()->HasKeyForKeyId(*it));
ClearKeyDecryptionManager::Get()->ReleaseKeyId(*it);
mCallback->KeyStatusChanged(&mSessionId[0], mSessionId.size(),

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeySession_h__
#define __ClearKeySession_h__

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include <stdint.h>
#include <stdio.h>
@ -16,9 +28,8 @@
#include "WMFUtils.h"
#endif
#include "mozilla/Assertions.h"
#include <assert.h>
using namespace mozilla;
using namespace std;
ClearKeySessionManager::ClearKeySessionManager()
@ -36,7 +47,7 @@ ClearKeySessionManager::ClearKeySessionManager()
ClearKeySessionManager::~ClearKeySessionManager()
{
CK_LOGD("ClearKeySessionManager dtor %p", this);
MOZ_ASSERT(!mRefCount);
assert(!mRefCount);
}
static bool
@ -88,7 +99,7 @@ ClearKeySessionManager::CreateSession(uint32_t aCreateSessionToken,
}
string sessionId = ClearKeyPersistence::GetNewSessionId(aSessionType);
MOZ_ASSERT(mSessions.find(sessionId) == mSessions.end());
assert(mSessions.find(sessionId) == mSessions.end());
ClearKeySession* session = new ClearKeySession(sessionId, mCallback, aSessionType);
session->Init(aCreateSessionToken, aPromiseId, aInitData, aInitDataSize);
@ -172,10 +183,10 @@ ClearKeySessionManager::PersistentSessionDataLoaded(GMPErr aStatus,
const uint8_t* base = aKeyData + 2 * CLEARKEY_KEY_LEN * i;
KeyId keyId(base, base + CLEARKEY_KEY_LEN);
MOZ_ASSERT(keyId.size() == CLEARKEY_KEY_LEN);
assert(keyId.size() == CLEARKEY_KEY_LEN);
Key key(base + CLEARKEY_KEY_LEN, base + 2 * CLEARKEY_KEY_LEN);
MOZ_ASSERT(key.size() == CLEARKEY_KEY_LEN);
assert(key.size() == CLEARKEY_KEY_LEN);
session->AddKeyId(keyId);
@ -254,10 +265,10 @@ ClearKeySessionManager::Serialize(const ClearKeySession* aSession,
if (!mDecryptionManager->HasKeyForKeyId(keyId)) {
continue;
}
MOZ_ASSERT(keyId.size() == CLEARKEY_KEY_LEN);
assert(keyId.size() == CLEARKEY_KEY_LEN);
aOutKeyData.insert(aOutKeyData.end(), keyId.begin(), keyId.end());
const Key& key = mDecryptionManager->GetDecryptionKey(keyId);
MOZ_ASSERT(key.size() == CLEARKEY_KEY_LEN);
assert(key.size() == CLEARKEY_KEY_LEN);
aOutKeyData.insert(aOutKeyData.end(), key.begin(), key.end());
}
}
@ -278,7 +289,7 @@ ClearKeySessionManager::CloseSession(uint32_t aPromiseId,
}
ClearKeySession* session = itr->second;
MOZ_ASSERT(session);
assert(session);
ClearInMemorySessionData(session);
mCallback->ResolvePromise(aPromiseId);
@ -307,7 +318,7 @@ ClearKeySessionManager::RemoveSession(uint32_t aPromiseId,
}
ClearKeySession* session = itr->second;
MOZ_ASSERT(session);
assert(session);
string sid = session->Id();
bool isPersistent = session->Type() == kGMPPersistentSession;
ClearInMemorySessionData(session);

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeyDecryptor_h__
#define __ClearKeyDecryptor_h__
@ -14,8 +26,6 @@
#include "ClearKeySession.h"
#include "ClearKeyUtils.h"
#include "gmp-api/gmp-decryption.h"
#include "mozilla/Attributes.h"
#include "mozilla/RefPtr.h"
#include "RefCounted.h"
class ClearKeySessionManager final : public GMPDecryptor
@ -76,7 +86,7 @@ private:
void ClearInMemorySessionData(ClearKeySession* aSession);
void Serialize(const ClearKeySession* aSession, std::vector<uint8_t>& aOutKeyData);
mozilla::RefPtr<ClearKeyDecryptionManager> mDecryptionManager;
RefPtr<ClearKeyDecryptionManager> mDecryptionManager;
GMPDecryptorCallback* mCallback;
GMPThread* mThread;

View File

@ -1,14 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include "ClearKeyStorage.h"
#include "ClearKeyUtils.h"
#include "gmp-task-utils.h"
#include "mozilla/Assertions.h"
#include "mozilla/ArrayUtils.h"
#include <assert.h>
#include "ArrayUtils.h"
#include <vector>
@ -50,7 +62,7 @@ public:
virtual void ReadComplete(GMPErr aStatus,
const uint8_t* aData,
uint32_t aDataSize) override {
MOZ_ASSERT(false, "Should not reach here.");
assert(false); // Should not reach here.
}
virtual void WriteComplete(GMPErr aStatus) override {
@ -115,7 +127,7 @@ public:
*/
static void Read(const std::string& aRecordName,
ReadContinuation* aContinuation) {
MOZ_ASSERT(aContinuation);
assert(aContinuation);
(new ReadRecordClient(aContinuation))->Do(aRecordName);
}
@ -134,7 +146,7 @@ public:
}
virtual void WriteComplete(GMPErr aStatus) override {
MOZ_ASSERT(false, "Should not reach here.");
assert(false); // Should not reach here.
}
private:

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeyStorage_h__
#define __ClearKeyStorage_h__

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include <algorithm>
#include <ctype.h>
@ -10,9 +22,9 @@
#include "ClearKeyUtils.h"
#include "ClearKeyBase64.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/Endian.h"
#include "ArrayUtils.h"
#include <assert.h>
#include "Endian.h"
#include "openaes/oaes_lib.h"
using namespace std;
@ -43,7 +55,7 @@ static void
IncrementIV(vector<uint8_t>& aIV) {
using mozilla::BigEndian;
MOZ_ASSERT(aIV.size() == 16);
assert(aIV.size() == 16);
BigEndian::writeUint64(&aIV[8], BigEndian::readUint64(&aIV[8]) + 1);
}
@ -51,8 +63,8 @@ IncrementIV(vector<uint8_t>& aIV) {
ClearKeyUtils::DecryptAES(const vector<uint8_t>& aKey,
vector<uint8_t>& aData, vector<uint8_t>& aIV)
{
MOZ_ASSERT(aIV.size() == CLEARKEY_KEY_LEN);
MOZ_ASSERT(aKey.size() == CLEARKEY_KEY_LEN);
assert(aIV.size() == CLEARKEY_KEY_LEN);
assert(aKey.size() == CLEARKEY_KEY_LEN);
OAES_CTX* aes = oaes_alloc();
oaes_key_import_data(aes, &aKey[0], aKey.size());
@ -65,7 +77,7 @@ ClearKeyUtils::DecryptAES(const vector<uint8_t>& aKey,
vector<uint8_t> enc(encLen);
oaes_encrypt(aes, &aIV[0], CLEARKEY_KEY_LEN, &enc[0], &encLen);
MOZ_ASSERT(encLen >= 2 * OAES_BLOCK_SIZE + CLEARKEY_KEY_LEN);
assert(encLen >= 2 * OAES_BLOCK_SIZE + CLEARKEY_KEY_LEN);
size_t blockLen = min(aData.size() - i, CLEARKEY_KEY_LEN);
for (size_t j = 0; j < blockLen; j++) {
aData[i + j] ^= enc[2 * OAES_BLOCK_SIZE + j];
@ -111,8 +123,7 @@ EncodeBase64Web(vector<uint8_t> aBinary, string& aEncoded)
// Cast idx to size_t before using it as an array-index,
// to pacify clang 'Wchar-subscripts' warning:
size_t idx = static_cast<size_t>(out[i]);
MOZ_ASSERT(idx < MOZ_ARRAY_LENGTH(sAlphabet),
"out of bounds index for 'sAlphabet'");
assert(idx < MOZ_ARRAY_LENGTH(sAlphabet)); // out of bounds index for 'sAlphabet'
out[i] = sAlphabet[idx];
}
@ -181,7 +192,7 @@ ClearKeyUtils::MakeKeyRequest(const vector<KeyId>& aKeyIDs,
string& aOutRequest,
GMPSessionType aSessionType)
{
MOZ_ASSERT(aKeyIDs.size() && aOutRequest.empty());
assert(aKeyIDs.size() && aOutRequest.empty());
aOutRequest.append("{ \"kids\":[");
for (size_t i = 0; i < aKeyIDs.size(); i++) {
@ -439,7 +450,7 @@ ParseKeys(ParserContext& aCtx, vector<KeyIdPair>& aOutKeys)
return false;
}
MOZ_ASSERT(!key.mKey.empty() && !key.mKeyId.empty());
assert(!key.mKey.empty() && !key.mKeyId.empty());
aOutKeys.push_back(key);
uint8_t sym = PeekSymbol(aCtx);
@ -507,7 +518,7 @@ ClearKeyUtils::SessionTypeToString(GMPSessionType aSessionType)
case kGMPTemporySession: return "temporary";
case kGMPPersistentSession: return "persistent";
default: {
MOZ_ASSERT(false, "Should not reach here.");
assert(false); // Should not reach here.
return "invalid";
}
}

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __ClearKeyUtils_h__
#define __ClearKeyUtils_h__

View File

@ -0,0 +1,68 @@
/*
* 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.
*/
#ifndef __Endian_h__
#define __Endian_h__
#include <stdint.h>
namespace mozilla {
class BigEndian {
public:
static uint32_t readUint32(const void* aPtr) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(aPtr);
return uint32_t(p[0]) << 24 |
uint32_t(p[1]) << 16 |
uint32_t(p[2]) << 8 |
uint32_t(p[3]);
}
static uint16_t readUint16(const void* aPtr) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(aPtr);
return uint32_t(p[0]) << 8 |
uint32_t(p[1]);
}
static uint64_t readUint64(const void* aPtr) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(aPtr);
return uint64_t(p[0]) << 56 |
uint64_t(p[1]) << 48 |
uint64_t(p[2]) << 40 |
uint64_t(p[3]) << 32 |
uint64_t(p[4]) << 24 |
uint64_t(p[5]) << 16 |
uint64_t(p[6]) << 8 |
uint64_t(p[7]);
}
static void writeUint64(void* aPtr, uint64_t aValue) {
uint8_t* p = reinterpret_cast<uint8_t*>(aPtr);
p[0] = uint8_t(aValue >> 56) & 0xff;
p[1] = uint8_t(aValue >> 48) & 0xff;
p[2] = uint8_t(aValue >> 40) & 0xff;
p[3] = uint8_t(aValue >> 32) & 0xff;
p[4] = uint8_t(aValue >> 24) & 0xff;
p[5] = uint8_t(aValue >> 16) & 0xff;
p[6] = uint8_t(aValue >> 8) & 0xff;
p[7] = uint8_t(aValue) & 0xff;
}
};
}
#endif // __Endian_h__

View File

@ -1,10 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#ifndef __RefCount_h__
#define __RefCount_h__
#include <stdint.h>
// Note: Not thread safe!
class RefCounted {
public:
@ -31,4 +45,33 @@ protected:
uint32_t mRefCount;
};
template<class T>
class RefPtr {
public:
explicit RefPtr(T* aPtr) : mPtr(nullptr) {
Assign(aPtr);
}
~RefPtr() {
Assign(nullptr);
}
T* operator->() const { return mPtr; }
RefPtr& operator=(T* aVal) {
Assign(aVal);
return *this;
}
private:
void Assign(T* aPtr) {
if (mPtr) {
mPtr->Release();
}
mPtr = aPtr;
if (mPtr) {
aPtr->AddRef();
}
}
T* mPtr;
};
#endif // __RefCount_h__

View File

@ -21,9 +21,8 @@
#include "ClearKeyDecryptionManager.h"
#include "ClearKeyUtils.h"
#include "gmp-task-utils.h"
#include "mozilla/Endian.h"
#include "Endian.h"
#include "VideoDecoder.h"
#include "mozilla/Move.h"
using namespace wmf;
@ -196,11 +195,10 @@ VideoDecoder::DecodeTask(GMPVideoEncodedFrame* aInput)
MaybeRunOnMainThread(
WrapTask(this,
&VideoDecoder::ReturnOutput,
CComPtr<IMFSample>(mozilla::Move(output)),
CComPtr<IMFSample>(output),
mDecoder->GetFrameWidth(),
mDecoder->GetFrameHeight(),
mDecoder->GetStride()));
assert(!output.Get());
}
if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
AutoLock lock(mMutex);
@ -351,11 +349,10 @@ VideoDecoder::DrainTask()
MaybeRunOnMainThread(
WrapTask(this,
&VideoDecoder::ReturnOutput,
CComPtr<IMFSample>(mozilla::Move(output)),
CComPtr<IMFSample>(output),
mDecoder->GetFrameWidth(),
mDecoder->GetFrameHeight(),
mDecoder->GetStride()));
assert(!output.Get());
}
}
MaybeRunOnMainThread(WrapTask(mCallback, &GMPVideoDecoderCallback::DrainComplete));

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
MFPLAT_FUNC(MFCreateSample);
MFPLAT_FUNC(MFCreateAlignedMemoryBuffer);

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
#include <assert.h>
#include <stdio.h>
@ -9,7 +21,6 @@
#include "ClearKeySessionManager.h"
#include "gmp-api/gmp-decryption.h"
#include "gmp-api/gmp-platform.h"
#include "mozilla/Attributes.h"
#if defined(ENABLE_WMF)
#include "WMFUtils.h"
@ -17,6 +28,12 @@
#include "VideoDecoder.h"
#endif
#if defined(WIN32)
#define GMP_EXPORT __declspec(dllexport)
#else
#define GMP_EXPORT __attribute__((visibility("default")))
#endif
static GMPPlatformAPI* sPlatform = nullptr;
GMPPlatformAPI*
GetPlatform()
@ -26,14 +43,14 @@ GetPlatform()
extern "C" {
MOZ_EXPORT GMPErr
GMP_EXPORT GMPErr
GMPInit(GMPPlatformAPI* aPlatformAPI)
{
sPlatform = aPlatformAPI;
return GMPNoErr;
}
MOZ_EXPORT GMPErr
GMP_EXPORT GMPErr
GMPGetAPI(const char* aApiName, void* aHostAPI, void** aPluginAPI)
{
CK_LOGD("ClearKey GMPGetAPI |%s|", aApiName);
@ -58,7 +75,7 @@ GMPGetAPI(const char* aApiName, void* aHostAPI, void** aPluginAPI)
return *aPluginAPI ? GMPNoErr : GMPNotImplementedErr;
}
MOZ_EXPORT GMPErr
GMP_EXPORT GMPErr
GMPShutdown(void)
{
CK_LOGD("ClearKey GMPShutdown");

View File

@ -1,6 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
// 0 arguments --

View File

@ -1,8 +1,18 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* 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.
*/
// Original author: ekr@rtfm.com

View File

@ -10,10 +10,10 @@
#include <vector>
#include "../ClearKeyBase64.cpp"
#include "../ArrayUtils.h"
using namespace std;
using namespace mozilla;
struct B64Test {
const char* b64;