Add Property to Access System ID

Adds a new property to the CDM's QueryStatus called QUERY_KEY_SYSTEM_ID that
contains the System ID. (as read from OEMCrypto_GetKeyData)  Adds a new
property to the DrmPlugin (cleverly named "systemId") that allows the app to
query for this.  Also adds unit tests.

Also changes the Device ID getter in crypto_engine.cpp to return a failure
instead of an empty ID.

Bug: 8621632

Merge of https://widevine-internal-review.googlesource.com/#/c/5010/ from
widevine cdm repository to android repository.

Change-Id: I8f309af18487c499e8ce25e829059e45623ea4dc
This commit is contained in:
Jeff Tinker
2013-04-18 13:55:15 -07:00
parent 0fc9bf9699
commit 0ab787b958
8 changed files with 87 additions and 25 deletions

View File

@@ -5,6 +5,7 @@
#ifndef CDM_BASE_CRYPTO_ENGINE_H_
#define CDM_BASE_CRYPTO_ENGINE_H_
#include <stdint.h>
#include <string>
#include "crypto_session.h"
@@ -48,7 +49,8 @@ class CryptoEngine {
} SecurityLevel;
SecurityLevel GetSecurityLevel();
std::string GetDeviceUniqueId();
bool GetDeviceUniqueId(std::string* deviceId);
bool GetSystemId(uint32_t* systemId);
private:

View File

@@ -37,6 +37,8 @@ static const std::string QUERY_KEY_SECURITY_LEVEL = "SecurityLevel";
// "L1", "L3"
static const std::string QUERY_KEY_DEVICE_ID = "DeviceID";
// device unique id
static const std::string QUERY_KEY_SYSTEM_ID = "SystemID";
// system id
static const std::string QUERY_VALUE_TRUE = "True";
static const std::string QUERY_VALUE_FALSE = "False";

View File

@@ -3,6 +3,7 @@
#include "cdm_engine.h"
#include <iostream>
#include <sstream>
#include "buffer_reader.h"
#include "cdm_session.h"
@@ -315,7 +316,19 @@ CdmResponseType CdmEngine::QueryStatus(CdmQueryMap* key_info) {
return KEY_ERROR;
}
(*key_info)[QUERY_KEY_DEVICE_ID] = crypto_engine->GetDeviceUniqueId();
std::string deviceId;
bool success = crypto_engine->GetDeviceUniqueId(&deviceId);
if (success) {
(*key_info)[QUERY_KEY_DEVICE_ID] = deviceId;
}
uint32_t system_id;
success = crypto_engine->GetSystemId(&system_id);
if (success) {
std::ostringstream system_id_stream;
system_id_stream << system_id;
(*key_info)[QUERY_KEY_SYSTEM_ID] = system_id_stream.str();
}
return NO_ERROR;
}

View File

@@ -5,6 +5,7 @@
#include "crypto_engine.h"
#include <arpa/inet.h> // TODO(fredgc): Add ntoh to wv_cdm_utilities.h
#include <iostream>
#include <vector>
@@ -195,7 +196,7 @@ CryptoEngine::SecurityLevel CryptoEngine::GetSecurityLevel() {
return kSecurityLevelUnknown;
}
std::string CryptoEngine::GetDeviceUniqueId() {
bool CryptoEngine::GetDeviceUniqueId(std::string* deviceId) {
std::vector<uint8_t> id;
size_t idLength = 32;
@@ -204,10 +205,29 @@ std::string CryptoEngine::GetDeviceUniqueId() {
OEMCryptoResult sts = OEMCrypto_GetDeviceID(&id[0], &idLength);
if (OEMCrypto_SUCCESS != sts) {
return std::string();
return false;
}
return std::string(reinterpret_cast<const char*>(&id[0]));
*deviceId = reinterpret_cast<const char*>(&id[0]);
return true;
}
bool CryptoEngine::GetSystemId(uint32_t* systemId) {
uint8_t buf[72];
size_t buflen = 72;
OEMCryptoResult sts = OEMCrypto_GetKeyData(buf, &buflen);
if (OEMCrypto_SUCCESS != sts) {
return false;
}
// Decode 32-bit int encoded as network-byte-order byte array starting at
// index 4.
uint32_t* id = reinterpret_cast<uint32_t*>(&buf[4]);
*systemId = ntohl(*id);
return true;
}
}; // namespace wvcdm

View File

@@ -154,8 +154,11 @@ bool CdmLicense::PrepareKeyRequest(const CdmInitData& init_data,
client_info->set_value(value);
}
client_info->set_name(kDeviceIdKey);
client_info->set_value(CryptoEngine::GetInstance()->GetDeviceUniqueId());
if (CryptoEngine::GetInstance()->GetDeviceUniqueId(&value)) {
client_info = client_id->add_client_info();
client_info->set_name(kDeviceIdKey);
client_info->set_value(value);
}
// Content Identification may be a cenc_id, a webm_id or a license_id
LicenseRequest_ContentIdentification* content_id =

View File

@@ -2,6 +2,7 @@
#include <errno.h>
#include <getopt.h>
#include <sstream>
#include "config_test_env.h"
#include "gtest/gtest.h"
@@ -217,6 +218,13 @@ TEST_F(WvCdmRequestLicenseTest, QueryStatus) {
ASSERT_TRUE(itr != query_info.end());
EXPECT_GT((int)itr->second.size(), 0);
itr = query_info.find(wvcdm::QUERY_KEY_SYSTEM_ID);
ASSERT_TRUE(itr != query_info.end());
std::istringstream ss(itr->second);
uint32_t system_id;
EXPECT_TRUE(ss >> system_id);
EXPECT_TRUE(ss.eof());
decryptor_.CloseSession(session_id_);
}