/* * Copyright 2012 Google Inc. All Rights Reserved. * These are one level up from unit tests -- they test the shared * clearkey DRM library and all of its components. * These are similar to the */ #include "WVCreateDrmPluginFactory.h" #include "MockOEMCrypto.h" #include "media/hardware/CryptoAPI.h" #include "media/drm/DrmClientAPI.h" #include "gtest/gtest.h" #include "stdio.h" using android::sp; using android::status_t; TEST(WVClearIntegrationTest, CreatesObject) { android::DrmPluginFactory* factory = createDrmPluginFactory(); EXPECT_NE(static_cast(NULL), factory) << "createDrmPluginFactory() returned null"; } static const uint8_t kWidevineUUID[16] = { 0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE, 0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED }; static const uint8_t kOldNetflixWidevineUUID[16] = { 0x29,0x70,0x1F,0xE4,0x3C,0xC7,0x4A,0x34, 0x8C,0x5B,0xAE,0x90,0xC7,0x43,0x9A,0x47 }; static const uint8_t kUnknownUUID[16] = { 0x6A,0x7F,0xAA,0xB0,0x83,0xC7,0x9E,0x20, 0x08,0xBC,0xEF,0x32,0x34,0x1A,0x9A,0x26 }; TEST(WVClearIntegrationTest, DecryptsBuffer) { android::DrmPluginFactory* factory = createDrmPluginFactory(); android::CryptoPlugin *plugin; const char *sessionId = "fake-session-id"; status_t result = factory->createCryptoPlugin(kWidevineUUID, sessionId, strlen(sessionId), &plugin); EXPECT_EQ(android::OK, result) << "WVDrmPluginFactory returned error from createCryptoPlugin()"; const size_t count = 751; // a nice big number, but not too round. bool secure = false; uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; uint8_t iv[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; uint8_t ecount[16]; uint8_t ivec[16]; unsigned int num = 0; unsigned char indata[count]; memset(ecount, 0, 16); memcpy(ivec, iv, 16); memset(indata, 0xAA, count); uint8_t srcPtr[count]; AES_KEY aes_key; AES_set_encrypt_key(key, 128, &aes_key); AES_ctr128_encrypt(indata, srcPtr, count, &aes_key, ivec, ecount, &num); android::CryptoPlugin::SubSample subSamples; subSamples.mNumBytesOfClearData = 0; subSamples.mNumBytesOfEncryptedData = count; size_t numSubSamples = 1; uint8_t dstPtr[count]; memset(dstPtr, 0, count); android::AString *errorDetailMsg=NULL; android::CryptoPlugin::Mode mode = android::CryptoPlugin::kMode_AES_CTR; plugin->decrypt( secure, key, iv, mode, srcPtr, &subSamples, numSubSamples, dstPtr, errorDetailMsg); EXPECT_EQ(0, memcmp(indata, dstPtr, count)) << "End-to-End decrypt did not work."; }