OEMCrypto Query Key Control Block

Merge from Widevine repo http://go/wvgerrit/13818

This CL adds the ability to query OEMCrypto about the key control
block and duration of a key that has been loaded.  There are unit
tests and implementation in the level 3 and reference implementation.

b/18503541

Change-Id: I8e40d90a3c64c1ce030af6fef9e98c8eac0df1a5
This commit is contained in:
Fred Gylys-Colwell
2015-03-30 15:38:52 -07:00
parent 10cc0a5ddb
commit 582eb32661
5 changed files with 115 additions and 0 deletions

View File

@@ -1012,6 +1012,26 @@ class Session {
&signature_[0], signature_.size(), NULL, NULL,
kNumKeys, key_array_, pst_ptr, pst.length()));
}
VerifyTestKeys();
}
void VerifyTestKeys() {
for (unsigned int i = 0; i < kNumKeys; i++) {
KeyControlBlock block;
size_t size = sizeof(block);
OEMCryptoResult sts = OEMCrypto_QueryKeyControl(
session_id(), license_.keys[i].key_id,
sizeof(license_.keys[i].key_id),
reinterpret_cast<uint8_t*>(&block), &size);
if (sts != OEMCrypto_ERROR_NOT_IMPLEMENTED) {
ASSERT_EQ(OEMCrypto_SUCCESS, sts);
ASSERT_EQ(sizeof(block), size);
ASSERT_EQ(license_.keys[i].control.duration,
block.duration) << "For key " << i;
ASSERT_EQ(license_.keys[i].control.control_bits,
block.control_bits) << "For key " << i;
}
}
}
void RefreshTestKeys(const size_t key_count, uint32_t control_bits,
@@ -2331,6 +2351,32 @@ TEST_F(DISABLED_TestKeybox, LoadKeysWithNoDerivedKeys) {
ASSERT_NE(OEMCrypto_SUCCESS, sts);
}
TEST_F(DISABLED_TestKeybox, QueryKeyControl) {
Session s;
s.open();
s.GenerateDerivedKeys();
s.FillSimpleMessage(0, wvoec_mock::kControlNonceEnabled, s.get_nonce());
s.EncryptAndSign();
s.LoadTestKeys();
// Note: successful cases are tested in VerifyTestKeys.
KeyControlBlock block;
size_t size = sizeof(block) - 1;
OEMCryptoResult sts = OEMCrypto_QueryKeyControl(
s.session_id(), s.license().keys[0].key_id,
sizeof(s.license().keys[0].key_id), reinterpret_cast<uint8_t*>(&block),
&size);
if (sts == OEMCrypto_ERROR_NOT_IMPLEMENTED) {
return;
}
ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER, sts);
const char *key_id = "no_key";
size = sizeof(block);
ASSERT_EQ(OEMCrypto_ERROR_NO_CONTENT_KEY,
OEMCrypto_QueryKeyControl(
s.session_id(), reinterpret_cast<const uint8_t*>(key_id),
strlen(key_id), reinterpret_cast<uint8_t*>(&block), &size));
}
TEST_F(DISABLED_TestKeybox, AntiRollbackHardwareRequired) {
Session s;
s.open();