Squashed commit of the following CDM changes:
* Add additional parameters to CDM decryption API https://widevine-internal-review.googlesource.com/#/c/6500/ * Pass Length and Flags Parameters to Decrypt() https://widevine-internal-review.googlesource.com/#/c/6740/ * Remove core files from oemcrypto/mock https://widevine-internal-review.googlesource.com/#/c/6853/ Change-Id: I1c73f5454da20da99130b161543fb990e16e7130
This commit is contained in:
@@ -2,21 +2,26 @@ LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
CDM_SRC_DIR=../../cdm/src
|
||||
CORE_SRC_DIR=../../cdm/core/src
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
src/oemcrypto_engine_mock.cpp \
|
||||
src/oemcrypto_key_mock.cpp \
|
||||
src/oemcrypto_keybox_mock.cpp \
|
||||
src/oemcrypto_mock.cpp \
|
||||
src/lock.cpp \
|
||||
src/log.cpp \
|
||||
src/string_conversions.cpp \
|
||||
src/wvcrc.cpp \
|
||||
$(CDM_SRC_DIR)/lock.cpp \
|
||||
$(CDM_SRC_DIR)/log.cpp \
|
||||
$(CORE_SRC_DIR)/string_conversions.cpp \
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(LOCAL_PATH)/../include \
|
||||
$(LOCAL_PATH)/src \
|
||||
vendor/widevine/libwvdrmengine/cdm/core/include \
|
||||
vendor/widevine/libwvdrmengine/third_party/stringencoders/src \
|
||||
bionic \
|
||||
external/gtest/include \
|
||||
external/openssl/include \
|
||||
@@ -32,6 +37,7 @@ LOCAL_SHARED_LIBRARIES := \
|
||||
libutils \
|
||||
libz \
|
||||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := libmodp_b64
|
||||
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)
|
||||
LOCAL_MODULE := liboemcrypto
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Lock class - provides a simple android specific mutex implementation
|
||||
|
||||
#include "lock.h"
|
||||
#include "utils/Mutex.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class Lock::Impl {
|
||||
public:
|
||||
android::Mutex lock_;
|
||||
};
|
||||
|
||||
Lock::Lock() : impl_(new Lock::Impl()) {
|
||||
}
|
||||
|
||||
Lock::~Lock() {
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
void Lock::Acquire() {
|
||||
impl_->lock_.lock();
|
||||
}
|
||||
|
||||
void Lock::Release() {
|
||||
impl_->lock_.unlock();
|
||||
}
|
||||
|
||||
bool Lock::Try() {
|
||||
return (impl_->lock_.tryLock() == 0);
|
||||
}
|
||||
|
||||
}; // namespace wvcdm
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Lock - Platform independent interface for a Mutex class
|
||||
//
|
||||
#ifndef OEMCRYPTO_LOCK_H_
|
||||
#define OEMCRYPTO_LOCK_H_
|
||||
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
// Simple lock class. The implementation is platform dependent.
|
||||
//
|
||||
// The lock must be unlocked by the thread that locked it.
|
||||
// The lock is also not recursive (ie. cannot be taken multiple times).
|
||||
class Lock {
|
||||
public:
|
||||
Lock();
|
||||
~Lock();
|
||||
|
||||
void Acquire();
|
||||
void Release();
|
||||
|
||||
// Acquires a lock if not held and returns true.
|
||||
// Returns false if the lock is held by another thread.
|
||||
bool Try();
|
||||
|
||||
friend class AutoLock;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
Impl *impl_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(Lock);
|
||||
};
|
||||
|
||||
// Manages the lock automatically. It will be locked when AutoLock
|
||||
// is constructed and release when AutoLock goes out of scope.
|
||||
class AutoLock {
|
||||
public:
|
||||
explicit AutoLock(Lock& lock) : lock_(&lock) {
|
||||
lock_->Acquire();
|
||||
}
|
||||
|
||||
explicit AutoLock(Lock* lock) : lock_(lock) {
|
||||
lock_->Acquire();
|
||||
}
|
||||
|
||||
~AutoLock() {
|
||||
lock_->Release();
|
||||
}
|
||||
|
||||
private:
|
||||
Lock *lock_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(AutoLock);
|
||||
};
|
||||
|
||||
}; // namespace wvcdm
|
||||
|
||||
#endif // OEMCRYPTO_LOCK_H_
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Log - implemented using the standard Android logging mechanism
|
||||
|
||||
#define LOG_TAG "WVCdm"
|
||||
#define LOG_BUF_SIZE 1024
|
||||
|
||||
#include "log.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void InitLogging(int argc, const char* const* argv) {}
|
||||
|
||||
void Log(const char* file, int line, LogPriority level, const char* fmt, ...) {
|
||||
va_list ap;
|
||||
char buf[LOG_BUF_SIZE];
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
android_LogPriority prio = ANDROID_LOG_VERBOSE;
|
||||
|
||||
switch(level) {
|
||||
case LOG_ERROR: prio = ANDROID_LOG_ERROR; break;
|
||||
case LOG_WARN: prio = ANDROID_LOG_WARN; break;
|
||||
case LOG_INFO: prio = ANDROID_LOG_INFO; break;
|
||||
case LOG_DEBUG: prio = ANDROID_LOG_DEBUG; break;
|
||||
case LOG_VERBOSE: prio = ANDROID_LOG_VERBOSE; break;
|
||||
}
|
||||
|
||||
__android_log_write(prio, LOG_TAG, buf);
|
||||
}
|
||||
|
||||
}; // namespace wvcdm
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Log - Platform independent interface for a Logging class
|
||||
//
|
||||
#ifndef OEMCRYPTO_LOG_H_
|
||||
#define OEMCRYPTO_LOG_H_
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
// Simple logging class. The implementation is platform dependent.
|
||||
|
||||
typedef enum {
|
||||
LOG_ERROR,
|
||||
LOG_WARN,
|
||||
LOG_INFO,
|
||||
LOG_DEBUG,
|
||||
LOG_VERBOSE
|
||||
} LogPriority;
|
||||
|
||||
// Required to enable/disable verbose logging (LOGV) in Chromium. In Chromium,
|
||||
// verbose logging level is controlled using command line switches --v (global)
|
||||
// or --vmodule (per module). This function calls logging::InitLogging to
|
||||
// initialize logging, which should have already been included in most Chromium
|
||||
// based binaries. However, it is typically not included by default in
|
||||
// unittests, in particular, the unittests in CDM core need to call InitLogging
|
||||
// to be able to control verbose logging in command line.
|
||||
void InitLogging(int argc, const char* const* argv);
|
||||
|
||||
void Log(const char* file, int line, LogPriority level, const char* fmt, ...);
|
||||
|
||||
// Log APIs
|
||||
#define LOGE(...) Log(__FILE__, __LINE__, wvcdm::LOG_ERROR, __VA_ARGS__)
|
||||
#define LOGW(...) Log(__FILE__, __LINE__, wvcdm::LOG_WARN, __VA_ARGS__)
|
||||
#define LOGI(...) Log(__FILE__, __LINE__, wvcdm::LOG_INFO, __VA_ARGS__)
|
||||
#define LOGD(...) Log(__FILE__, __LINE__, wvcdm::LOG_DEBUG, __VA_ARGS__)
|
||||
#define LOGV(...) Log(__FILE__, __LINE__, wvcdm::LOG_VERBOSE, __VA_ARGS__)
|
||||
|
||||
}; // namespace wvcdm
|
||||
|
||||
#endif // OEMCRYPTO_LOG_H_
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "string_conversions.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
static bool CharToDigit(char ch, unsigned char* digit) {
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
*digit = ch - '0';
|
||||
} else {
|
||||
ch = tolower(ch);
|
||||
if ((ch >= 'a') && (ch <= 'f')) {
|
||||
*digit = ch - 'a' + 10;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// converts an ascii hex string(2 bytes per digit) into a decimal byte string
|
||||
std::vector<uint8_t> a2b_hex(const std::string& byte) {
|
||||
std::vector<uint8_t> array(0);
|
||||
unsigned int count = byte.size();
|
||||
if (count == 0 || (count % 2) != 0) {
|
||||
LOGE("Invalid input size %u for string %s", count, byte.c_str());
|
||||
return array;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < count / 2; ++i) {
|
||||
unsigned char msb = 0; // most significant 4 bits
|
||||
unsigned char lsb = 0; // least significant 4 bits
|
||||
if (!CharToDigit(byte[i * 2], &msb) ||
|
||||
!CharToDigit(byte[i * 2 + 1], &lsb)) {
|
||||
LOGE("Invalid hex value %c%c at index %d", byte[i * 2], byte[i * 2 + 1], i);
|
||||
return array;
|
||||
}
|
||||
array.push_back((msb << 4) | lsb);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
std::string b2a_hex(const std::vector<uint8_t>& byte) {
|
||||
return HexEncode(&byte[0], byte.size());
|
||||
}
|
||||
|
||||
std::string HexEncode(const uint8_t* in_buffer, unsigned int size) {
|
||||
static const char kHexChars[] = "0123456789ABCDEF";
|
||||
|
||||
// Each input byte creates two output hex characters.
|
||||
std::string out_buffer(size * 2, '\0');
|
||||
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
char byte = in_buffer[i];
|
||||
out_buffer[(i << 1)] = kHexChars[(byte >> 4) & 0xf];
|
||||
out_buffer[(i << 1) + 1] = kHexChars[byte & 0xf];
|
||||
}
|
||||
return out_buffer;
|
||||
}
|
||||
|
||||
std::string IntToString(int value) {
|
||||
// log10(2) ~= 0.3 bytes needed per bit or per byte log10(2**8) ~= 2.4.
|
||||
// So round up to allocate 3 output characters per byte, plus 1 for '-'.
|
||||
const int kOutputBufSize = 3 * sizeof(int) + 1;
|
||||
char buffer[kOutputBufSize];
|
||||
memset(buffer, 0, kOutputBufSize);
|
||||
snprintf(buffer, kOutputBufSize, "%d", value);
|
||||
|
||||
std::string out_string(buffer, sizeof(buffer));
|
||||
return out_string;
|
||||
}
|
||||
|
||||
std::string UintToString(unsigned int value) {
|
||||
// log10(2) ~= 0.3 bytes needed per bit or per byte log10(2**8) ~= 2.4.
|
||||
// So round up to allocate 3 output characters per byte.
|
||||
const int kOutputBufSize = 3 * sizeof(unsigned int);
|
||||
char buffer[kOutputBufSize];
|
||||
memset(buffer, 0, kOutputBufSize);
|
||||
snprintf(buffer, kOutputBufSize, "%u", value);
|
||||
|
||||
std::string out_string(buffer, sizeof(buffer));
|
||||
return out_string;
|
||||
}
|
||||
|
||||
}; // namespace wvcdm
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef OEMCRYPTO_STRING_CONVERSIONS_H_
|
||||
#define OEMCRYPTO_STRING_CONVERSIONS_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
std::vector<uint8_t> a2b_hex(const std::string& b);
|
||||
std::string b2a_hex(const std::vector<uint8_t>& b);
|
||||
std::string HexEncode(const uint8_t* bytes, unsigned size);
|
||||
std::string IntToString(int value);
|
||||
std::string UintToString(unsigned int value);
|
||||
|
||||
|
||||
}; // namespace wvcdm
|
||||
|
||||
#endif // OEMCRYPTO_STRING_CONVERSIONS_H_
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef OEMCRYPTO_WV_CDM_CONSTANTS_H_
|
||||
#define OEMCRYPTO_WV_CDM_CONSTANTS_H_
|
||||
|
||||
namespace wvcdm {
|
||||
static const size_t KEY_CONTROL_SIZE = 16;
|
||||
static const size_t KEY_IV_SIZE = 16;
|
||||
static const size_t KEY_PAD_SIZE = 16;
|
||||
static const size_t KEY_SIZE = 16;
|
||||
static const size_t MAC_KEY_SIZE = 32;
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // OEMCRYPTO_WV_CDM_CONSTANTS_H_
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef OEMCRYPTO_WV_CDM_TYPES_H_
|
||||
#define OEMCRYPTO_WV_CDM_TYPES_H_
|
||||
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
typedef std::string CdmKeySystem;
|
||||
typedef std::string CdmInitData;
|
||||
typedef std::string CdmKeyMessage;
|
||||
typedef std::string CdmKeyResponse;
|
||||
typedef std::string KeyId;
|
||||
typedef std::string CdmSessionId;
|
||||
typedef std::string RequestId;
|
||||
typedef uint32_t CryptoResult;
|
||||
typedef uint32_t CryptoSessionId;
|
||||
typedef std::string CryptoKeyId;
|
||||
|
||||
enum CdmResponseType {
|
||||
NO_ERROR,
|
||||
UNKNOWN_ERROR,
|
||||
KEY_ADDED,
|
||||
KEY_ERROR,
|
||||
KEY_MESSAGE,
|
||||
NEED_KEY,
|
||||
KEY_CANCELED,
|
||||
};
|
||||
|
||||
#define CORE_DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName&); \
|
||||
void operator=(const TypeName&)
|
||||
|
||||
enum CdmEventType {
|
||||
LICENSE_EXPIRED,
|
||||
LICENSE_RENEWAL_NEEDED
|
||||
};
|
||||
|
||||
// forward class references
|
||||
class KeyMessage;
|
||||
class Request;
|
||||
class Key;
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // OEMCRYPTO_WV_CDM_TYPES_H_
|
||||
@@ -4,8 +4,7 @@ LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
oemcrypto_test.cpp \
|
||||
../../cdm/src/log.cpp \
|
||||
oemcrypto_test.cpp
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
@@ -19,6 +18,8 @@ LOCAL_C_INCLUDES += \
|
||||
external/stlport/stlport \
|
||||
$(LOCAL_PATH)/../include \
|
||||
$(LOCAL_PATH)/../mock/src \
|
||||
vendor/widevine/libwvdrmengine/cdm/core/include \
|
||||
vendor/widevine/libwvdrmengine/third_party/stringencoders/src \
|
||||
|
||||
# TODO(fredgc): fix order dependencies on libwvlevel3 and libwvwrapper.
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
|
||||
Reference in New Issue
Block a user