Merge changes I4e4a6a01,I4e360ea5,I6e08e76f
* changes: Refactor OEMCrypto Engine Add Shared License bit to key control block Reference Code for Big Usage Tables
This commit is contained in:
committed by
Android (Google) Code Review
commit
a118988ecf
@@ -819,8 +819,47 @@ void Session::InstallRSASessionTestKey(const vector<uint8_t>& wrapped_rsa_key) {
|
||||
GenerateDerivedKeysFromSessionKey();
|
||||
}
|
||||
|
||||
void Session::CreateNewUsageEntry() {
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_CreateNewUsageEntry(session_id(), &usage_entry_number_));
|
||||
}
|
||||
|
||||
void Session::UpdateUsageEntry(std::vector<uint8_t>* header_buffer) {
|
||||
size_t header_buffer_length = 0;
|
||||
size_t entry_buffer_length = 0;
|
||||
ASSERT_EQ(
|
||||
OEMCrypto_ERROR_SHORT_BUFFER,
|
||||
OEMCrypto_UpdateUsageEntry(session_id(), NULL, &header_buffer_length,
|
||||
NULL, &entry_buffer_length));
|
||||
ASSERT_LT(0u, header_buffer_length);
|
||||
header_buffer->resize(header_buffer_length);
|
||||
ASSERT_LT(0u, entry_buffer_length);
|
||||
encrypted_usage_entry_.resize(entry_buffer_length);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_UpdateUsageEntry(
|
||||
session_id(), &(header_buffer->front()), &header_buffer_length,
|
||||
&encrypted_usage_entry_[0], &entry_buffer_length));
|
||||
}
|
||||
|
||||
void Session::DeactivateUsageEntry(const std::string& pst,
|
||||
OEMCryptoResult expect_result) {
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_DeactivateUsageEntry(
|
||||
session_id(), reinterpret_cast<const uint8_t*>(pst.c_str()),
|
||||
pst.length()));
|
||||
}
|
||||
|
||||
void Session::LoadUsageEntry(uint32_t index, const vector<uint8_t>& buffer) {
|
||||
usage_entry_number_ = index;
|
||||
encrypted_usage_entry_ = buffer;
|
||||
ASSERT_EQ(
|
||||
OEMCrypto_SUCCESS,
|
||||
OEMCrypto_LoadUsageEntry(session_id(), index, &buffer[0], buffer.size()));
|
||||
}
|
||||
|
||||
void Session::GenerateReport(const std::string& pst, bool expect_success,
|
||||
Session* other) {
|
||||
ASSERT_TRUE(open_);
|
||||
if (other) { // If other is specified, copy mac keys.
|
||||
mac_key_server_ = other->mac_key_server_;
|
||||
mac_key_client_ = other->mac_key_client_;
|
||||
@@ -834,7 +873,7 @@ void Session::GenerateReport(const std::string& pst, bool expect_success,
|
||||
}
|
||||
if (sts == OEMCrypto_ERROR_SHORT_BUFFER) {
|
||||
ASSERT_EQ(wvcdm::Unpacked_PST_Report::report_size(pst.length()), length);
|
||||
pst_report_buffer_.resize(length);
|
||||
pst_report_buffer_.assign(length, 0xFF); // Fill with garbage values.
|
||||
}
|
||||
sts = OEMCrypto_ReportUsage(session_id(),
|
||||
reinterpret_cast<const uint8_t*>(pst.c_str()),
|
||||
@@ -843,6 +882,7 @@ void Session::GenerateReport(const std::string& pst, bool expect_success,
|
||||
ASSERT_NE(OEMCrypto_SUCCESS, sts);
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(pst_report_buffer_.size(), length);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, sts);
|
||||
vector<uint8_t> computed_signature(SHA_DIGEST_LENGTH);
|
||||
unsigned int sig_len = SHA_DIGEST_LENGTH;
|
||||
@@ -857,23 +897,6 @@ void Session::GenerateReport(const std::string& pst, bool expect_success,
|
||||
EXPECT_EQ(0, memcmp(pst.c_str(), pst_report().pst(), pst.length()));
|
||||
}
|
||||
|
||||
void Session::DeleteEntry(const std::string& pst) {
|
||||
uint8_t* pst_ptr = encrypted_license().pst;
|
||||
memcpy(pst_ptr, pst.c_str(), min(sizeof(license_.pst), pst.length()));
|
||||
ServerSignBuffer(reinterpret_cast<const uint8_t*>(&padded_message_),
|
||||
message_size_, &signature_);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_DeleteUsageEntry(session_id(), pst_ptr, pst.length(),
|
||||
message_ptr(), message_size_,
|
||||
&signature_[0], signature_.size()));
|
||||
}
|
||||
|
||||
void Session::ForceDeleteEntry(const std::string& pst) {
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(pst.c_str()), pst.length()));
|
||||
}
|
||||
|
||||
const uint8_t* Session::message_ptr() {
|
||||
return reinterpret_cast<const uint8_t*>(&encrypted_license());
|
||||
}
|
||||
|
||||
@@ -248,6 +248,29 @@ class Session {
|
||||
// Loads the specified wrapped_rsa_key into OEMCrypto, and then runs
|
||||
// GenerateDerivedKeysFromSessionKey to install known encryption and mac keys.
|
||||
void InstallRSASessionTestKey(const vector<uint8_t>& wrapped_rsa_key);
|
||||
// Creates a new usage entry, and keeps track of the index.
|
||||
void CreateNewUsageEntry();
|
||||
// Copy encrypted usage entry from other session, and then load it.
|
||||
// This session must already be open.
|
||||
void LoadUsageEntry(uint32_t index, const vector<uint8_t>& buffer);
|
||||
// Copy encrypted usage entry from other session.
|
||||
// This session must already be open.
|
||||
void LoadUsageEntry(const Session& other) {
|
||||
LoadUsageEntry(other.usage_entry_number(), other.encrypted_usage_entry());
|
||||
}
|
||||
// Reload previously used usage entry.
|
||||
void ReloadUsageEntry() { LoadUsageEntry(*this); }
|
||||
// Update the usage entry and save the header to the specified buffer.
|
||||
void UpdateUsageEntry(std::vector<uint8_t>* header_buffer);
|
||||
// Deactivate this sessions usage entry.
|
||||
void DeactivateUsageEntry(const std::string& pst,
|
||||
OEMCryptoResult expect_result = OEMCrypto_SUCCESS);
|
||||
// The usage entry number for this session's usage entry.
|
||||
uint32_t usage_entry_number() const { return usage_entry_number_; }
|
||||
// The encrypted buffer holding the recently updated and saved usage entry.
|
||||
const vector<uint8_t>& encrypted_usage_entry() const {
|
||||
return encrypted_usage_entry_;
|
||||
}
|
||||
// Generates a usage report for the specified pst. If expect_success is true,
|
||||
// the report's signature is verified, and several fields are given sanity
|
||||
// checks. If other is not null, then the mac keys are copied from other in
|
||||
@@ -259,12 +282,6 @@ class Session {
|
||||
wvcdm::Unpacked_PST_Report pst_report() {
|
||||
return wvcdm::Unpacked_PST_Report(&pst_report_buffer_[0]);
|
||||
}
|
||||
// Creates a signed delete usage table entry message and calls
|
||||
// OEMCrypto_DeleteUsageEntry on it.
|
||||
void DeleteEntry(const std::string& pst);
|
||||
// Calls OEMCrypto_ForceDeleteUsageEntry to delete a usage table entry without
|
||||
// a signed message.
|
||||
void ForceDeleteEntry(const std::string& pst);
|
||||
|
||||
// The unencrypted license response or license renewal response.
|
||||
MessageData& license() { return license_; }
|
||||
@@ -310,6 +327,8 @@ class Session {
|
||||
OEMCrypto_KeyObject key_array_[kMaxNumKeys];
|
||||
std::vector<uint8_t> signature_;
|
||||
int num_keys_;
|
||||
vector<uint8_t> encrypted_usage_entry_;
|
||||
uint32_t usage_entry_number_;
|
||||
};
|
||||
|
||||
} // namespace wvoec
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user