Fixed loading mac keys in mock and Level3
Merge of http://go/wvgerrit/45521/ Bug: b/73818548 Test: request_license_tests and GTS tests on sailfish and taimen This change loads the mac keys into the session to be used in GenerateSignature from the last call to one of: DeriveKeysFromSessionKey, GenerateDerivedKeys, LoadKeys, and LoadUsageEntry. OEMCrypto tests are changed to reflect this as well (specifically the order in which we call the above methods).
This commit is contained in:
@@ -304,16 +304,7 @@ bool SessionContext::GenerateSignature(const uint8_t* message,
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t* mac_key = NULL;
|
||||
bool using_usage_mac_key_client = false;
|
||||
if (mac_key_client_.size() == wvcdm::MAC_KEY_SIZE) {
|
||||
// If we have a mac key, use it.
|
||||
mac_key = &mac_key_client_[0];
|
||||
} else if (usage_entry_status_ == kUsageEntryLoaded) {
|
||||
// If not, but we have a usage entry, use its key.
|
||||
mac_key = usage_entry_->mac_key_client();
|
||||
using_usage_mac_key_client = true;
|
||||
} else {
|
||||
if (mac_key_client_.size() != wvcdm::MAC_KEY_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -322,11 +313,17 @@ bool SessionContext::GenerateSignature(const uint8_t* message,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (using_usage_mac_key_client &&
|
||||
LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
std::vector<uint8_t> usage_entry_mac_key_client(
|
||||
bool using_usage_entry_mac_key_client = false;
|
||||
std::vector<uint8_t> usage_entry_mac_key_client;
|
||||
if (usage_entry_status_ == kUsageEntryLoaded) {
|
||||
usage_entry_mac_key_client.assign(
|
||||
usage_entry_->mac_key_client(),
|
||||
usage_entry_->mac_key_client() + wvcdm::MAC_KEY_SIZE * sizeof(uint8_t));
|
||||
using_usage_entry_mac_key_client =
|
||||
mac_key_client_ == usage_entry_mac_key_client;
|
||||
}
|
||||
if (using_usage_entry_mac_key_client &&
|
||||
LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("message signed with HMAC and usage_entry_'s mac_key_client, "
|
||||
"mac_key_client = " +
|
||||
wvcdm::b2a_hex(usage_entry_mac_key_client)).c_str());
|
||||
@@ -336,8 +333,8 @@ bool SessionContext::GenerateSignature(const uint8_t* message,
|
||||
}
|
||||
|
||||
unsigned int md_len = *signature_length;
|
||||
if (HMAC(EVP_sha256(), mac_key, wvcdm::MAC_KEY_SIZE, message, message_length,
|
||||
signature, &md_len)) {
|
||||
if (HMAC(EVP_sha256(), &mac_key_client_[0], wvcdm::MAC_KEY_SIZE, message,
|
||||
message_length, signature, &md_len)) {
|
||||
*signature_length = md_len;
|
||||
return true;
|
||||
}
|
||||
@@ -1277,6 +1274,17 @@ OEMCryptoResult SessionContext::LoadUsageEntry(
|
||||
ce_->usage_table().LoadUsageEntry(this, &usage_entry_, index, buffer);
|
||||
if (usage_entry_) {
|
||||
usage_entry_status_ = kUsageEntryLoaded;
|
||||
// Copy the mac keys to the current session.
|
||||
mac_key_server_ = std::vector<uint8_t>(
|
||||
usage_entry_->mac_key_server(),
|
||||
usage_entry_->mac_key_server() + wvcdm::MAC_KEY_SIZE);
|
||||
mac_key_client_ = std::vector<uint8_t>(
|
||||
usage_entry_->mac_key_client(),
|
||||
usage_entry_->mac_key_client() + wvcdm::MAC_KEY_SIZE);
|
||||
if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("mac_key_client_ has been updated to = " +
|
||||
wvcdm::b2a_hex(mac_key_client_)).c_str());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user