This CL merges the following changes from the Widevine repository: Avoid CdmSession reinitialization https://widevine-internal-review.googlesource.com/#/c/10530/ Fix timer-related unit tests. https://widevine-internal-review.googlesource.com/#/c/10510/ Correct return statement bug: 15590802 https://widevine-internal-review.googlesource.com/#/c/10553/ Usage reporting fixes bug/15388863 https://widevine-internal-review.googlesource.com/#/c/10460/ Make public methods virtual https://widevine-internal-review.googlesource.com/#/c/10500/ Fix the SetTimer contract in the CDM. https://widevine-internal-review.googlesource.com/#/c/10493/ Move inline CDM methods, add OVERRIDE. https://widevine-internal-review.googlesource.com/#/c/10475/ Simplify storage APIs related cleanup. https://widevine-internal-review.googlesource.com/#/c/10473/ Duration values are not correctly reported when queried b/15592374 https://widevine-internal-review.googlesource.com/#/c/10437/ Propagate IsKeyValid() through ContentDecryptionModule. https://widevine-internal-review.googlesource.com/#/c/10483/ Minor clean up in config_test_env. https://widevine-internal-review.googlesource.com/#/c/10440/ General clean up. https://widevine-internal-review.googlesource.com/#/c/10441/ Refactor HttpSocket and simplify UrlRequest interface. https://widevine-internal-review.googlesource.com/#/c/10410/ Install good keybox at end of unit tests b/15385981 https://widevine-internal-review.googlesource.com/#/c/10374/ Privacy crypto fixes b/15475012 https://widevine-internal-review.googlesource.com/#/c/10383/ Incorporate header files to resolve build issued based on customers feedback. https://widevine-internal-review.googlesource.com/#/c/10420/ Support unprovisioning b/12247651 https://widevine-internal-review.googlesource.com/#/c/10356/ Correct usage of Host::Allocate and Cdm::Decrypt. https://widevine-internal-review.googlesource.com/#/c/10378/ Fix logging bug, arguments in wrong order. https://widevine-internal-review.googlesource.com/#/c/10380/ Rename types that look like constants. https://widevine-internal-review.googlesource.com/#/c/10379/ Fix offline test failures b/13909635 https://widevine-internal-review.googlesource.com/#/c/10348/ Add -DUNIT_TEST to the unit test makefile for Android https://widevine-internal-review.googlesource.com/#/c/10375/ Refactor privacy-crypto and add dummy version. https://widevine-internal-review.googlesource.com/#/c/10353/ Remove References to Apiary https://widevine-internal-review.googlesource.com/#/c/9924/ Delete oldest entry in usage table when full bug: 15184824 https://widevine-internal-review.googlesource.com/#/c/10295/ Port DeviceFiles to iOS. https://widevine-internal-review.googlesource.com/#/c/10355/ Make testing functions in DeviceFiles private. https://widevine-internal-review.googlesource.com/#/c/10354/ Add RSA encryption to haystack https://widevine-internal-review.googlesource.com/#/c/10280/ Add string and vector includes to CDM header. https://widevine-internal-review.googlesource.com/#/c/10352/ First version of oemcrypto logging https://widevine-internal-review.googlesource.com/#/c/10252/ Update Names of Secure Stop Methods bug: 11987015 https://widevine-internal-review.googlesource.com/#/c/10152/ Adjust timing on the Usage Table unit test https://widevine-internal-review.googlesource.com/#/c/10307/ Fix all compiler warnings in CDM source release. https://widevine-internal-review.googlesource.com/#/c/10293/ Fix memset bug: args in wrong order https://widevine-internal-review.googlesource.com/#/c/10292/ Partial revert of 'Remove refs to test prov server, Level3 support...' https://widevine-internal-review.googlesource.com/#/c/10281/ Pack structure OEMCrypto_PST_Report https://widevine-internal-review.googlesource.com/#/c/10243/ Remove refs to test prov server, Level3 support; remove dead code https://widevine-internal-review.googlesource.com/#/c/10220/ Partial revert of 'Document data strings; clean up license server parameters.' https://widevine-internal-review.googlesource.com/#/c/10188/ Document data strings; clean up license server parameters. https://widevine-internal-review.googlesource.com/#/c/10120/ Fix broken build after partner branch merge. https://widevine-internal-review.googlesource.com/#/c/10181/ TODO Cleanup - core/src, core/include https://widevine-internal-review.googlesource.com/#/c/9965/ TODO Cleanup - cdm, chromium, core/test. https://widevine-internal-review.googlesource.com/#/c/9419/ Remove unneeded properties. https://widevine-internal-review.googlesource.com/#/c/10162/ Change-Id: If2bb9d743a562a3875bebb91933c0aaadea286b2
108 lines
3.2 KiB
C++
108 lines
3.2 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
//
|
|
// Mock implementation of OEMCrypto APIs
|
|
//
|
|
#include "oemcrypto_keybox_mock.h"
|
|
|
|
#include <arpa/inet.h> // needed for ntoh()
|
|
#include <string>
|
|
#include <cstring>
|
|
#include <sys/types.h>
|
|
#include "log.h"
|
|
#include "wvcrc32.h"
|
|
#include "wv_keybox.h"
|
|
|
|
namespace wvoec_mock {
|
|
|
|
const WidevineKeybox kDefaultKeybox = {
|
|
// Sample keybox used for test vectors
|
|
{
|
|
// deviceID
|
|
0x54, 0x65, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x30, // TestKey01
|
|
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........
|
|
}, {
|
|
// key
|
|
0xfb, 0xda, 0x04, 0x89, 0xa1, 0x58, 0x16, 0x0e,
|
|
0xa4, 0x02, 0xe9, 0x29, 0xe3, 0xb6, 0x8f, 0x04,
|
|
}, {
|
|
// data
|
|
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x19,
|
|
0x07, 0xd9, 0xff, 0xde, 0x13, 0xaa, 0x95, 0xc1,
|
|
0x22, 0x67, 0x80, 0x53, 0x36, 0x21, 0x36, 0xbd,
|
|
0xf8, 0x40, 0x8f, 0x82, 0x76, 0xe4, 0xc2, 0xd8,
|
|
0x7e, 0xc5, 0x2b, 0x61, 0xaa, 0x1b, 0x9f, 0x64,
|
|
0x6e, 0x58, 0x73, 0x49, 0x30, 0xac, 0xeb, 0xe8,
|
|
0x99, 0xb3, 0xe4, 0x64, 0x18, 0x9a, 0x14, 0xa8,
|
|
0x72, 0x02, 0xfb, 0x02, 0x57, 0x4e, 0x70, 0x64,
|
|
0x0b, 0xd2, 0x2e, 0xf4, 0x4b, 0x2d, 0x7e, 0x39,
|
|
}, {
|
|
// magic
|
|
0x6b, 0x62, 0x6f, 0x78,
|
|
}, {
|
|
// Crc
|
|
0x0a, 0x7a, 0x2c, 0x35,
|
|
}
|
|
};
|
|
|
|
WvKeybox::WvKeybox() : valid_(false) {
|
|
Prepare();
|
|
}
|
|
|
|
bool WvKeybox::Prepare() {
|
|
InstallKeybox(reinterpret_cast<const uint8_t*>(&kDefaultKeybox),
|
|
sizeof(kDefaultKeybox));
|
|
valid_ = true;
|
|
return valid_;
|
|
}
|
|
|
|
KeyboxError WvKeybox::Validate() {
|
|
if (!valid_) {
|
|
LOGE("[KEYBOX NOT LOADED]");
|
|
return OTHER_ERROR;
|
|
}
|
|
if (strncmp(reinterpret_cast<char*>(magic_), "kbox", 4) != 0) {
|
|
LOGE("[KEYBOX HAS BAD MAGIC]");
|
|
return BAD_MAGIC;
|
|
}
|
|
uint32_t crc_computed;
|
|
uint32_t* crc_stored = (uint32_t*)crc_;
|
|
WidevineKeybox keybox;
|
|
memset(&keybox, 0, sizeof(keybox));
|
|
memcpy(keybox.device_id_, &device_id_[0], device_id_.size());
|
|
memcpy(keybox.device_key_, &device_key_[0], sizeof(keybox.device_key_));
|
|
memcpy(keybox.data_, key_data_, sizeof(keybox.data_));
|
|
memcpy(keybox.magic_, magic_, sizeof(keybox.magic_));
|
|
|
|
crc_computed = ntohl(wvcrc32(reinterpret_cast<uint8_t*>(&keybox),
|
|
sizeof(keybox) - 4)); // Drop last 4 bytes.
|
|
if (crc_computed != *crc_stored) {
|
|
LOGE("[KEYBOX CRC problem: computed = %08x, stored = %08x]\n",
|
|
crc_computed, *crc_stored);
|
|
return BAD_CRC;
|
|
}
|
|
return NO_ERROR;
|
|
}
|
|
|
|
bool WvKeybox::InstallKeybox(const uint8_t* buffer, size_t keyBoxLength) {
|
|
if (keyBoxLength != 128) {
|
|
return false;
|
|
}
|
|
|
|
const WidevineKeybox* keybox
|
|
= reinterpret_cast<const WidevineKeybox*>(buffer);
|
|
size_t device_id_length
|
|
= strnlen(reinterpret_cast<const char*>(keybox->device_id_), 32);
|
|
device_id_.assign(keybox->device_id_,
|
|
keybox->device_id_ + device_id_length);
|
|
device_key_.assign(keybox->device_key_,
|
|
keybox->device_key_ + sizeof(keybox->device_key_));
|
|
memcpy(key_data_, keybox->data_, sizeof(keybox->data_));
|
|
memcpy(magic_, keybox->magic_, sizeof(keybox->magic_));
|
|
memcpy(crc_, keybox->crc_, sizeof(keybox->crc_));
|
|
return true;
|
|
}
|
|
|
|
}; // namespace wvoec_mock
|