Merge changes I518ef46b,I2c2c1c1d
* changes: Unit Tests for Security Patch Level Fail early in oemcrypto unit tests
This commit is contained in:
committed by
Android (Google) Code Review
commit
8bf6a6f2d0
@@ -62,7 +62,7 @@ typedef OEMCryptoResult (*L1_LoadKeys_t)(
|
||||
const uint8_t* enc_mac_key_iv, const uint8_t* enc_mac_key, size_t num_keys,
|
||||
const OEMCrypto_KeyObject* key_array, const uint8_t* pst,
|
||||
size_t pst_length);
|
||||
typedef OEMCryptoResult (*L1_LoadKeys_V10_t)(
|
||||
typedef OEMCryptoResult (*L1_LoadKeys_V9_or_V10_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length,
|
||||
const uint8_t* enc_mac_key_iv, const uint8_t* enc_mac_key, size_t num_keys,
|
||||
@@ -72,7 +72,7 @@ typedef OEMCryptoResult (*L1_LoadKeys_V8_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length,
|
||||
const uint8_t* enc_mac_key_iv, const uint8_t* enc_mac_key, size_t num_keys,
|
||||
const OEMCrypto_KeyObject* key_array);
|
||||
const OEMCrypto_KeyObject_V10* key_array);
|
||||
typedef OEMCryptoResult (*L1_RefreshKeys_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length, size_t num_keys,
|
||||
@@ -91,7 +91,7 @@ typedef OEMCryptoResult (*L1_DecryptCENC_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* data_addr, size_t data_length,
|
||||
bool is_encrypted, const uint8_t* iv, size_t offset,
|
||||
const OEMCrypto_DestBufferDesc* out_buffer,
|
||||
const OEMCrypto_PatternDesc* pattern, uint8_t subsample_flags);
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern, uint8_t subsample_flags);
|
||||
typedef OEMCryptoResult (*L1_CopyBuffer_t)(const uint8_t* data_addr,
|
||||
size_t data_length,
|
||||
OEMCrypto_DestBufferDesc* out_buffer,
|
||||
@@ -229,7 +229,7 @@ struct FunctionPointers {
|
||||
L1_LoadKeys_V8_t LoadKeys_V8;
|
||||
L1_GenerateRSASignature_V8_t GenerateRSASignature_V8;
|
||||
L1_GetHDCPCapability_V9_t GetHDCPCapability_V9;
|
||||
L1_LoadKeys_V10_t LoadKeys_V10;
|
||||
L1_LoadKeys_V9_or_V10_t LoadKeys_V9_or_V10;
|
||||
};
|
||||
|
||||
struct LevelSession {
|
||||
@@ -338,7 +338,6 @@ class Adapter {
|
||||
LOOKUP(LoadKeys_V8, OEMCrypto_LoadKeys_V8);
|
||||
LOOKUP(GenerateRSASignature_V8, OEMCrypto_GenerateRSASignature_V8);
|
||||
} else {
|
||||
LOOKUP(LoadKeys, OEMCrypto_LoadKeys);
|
||||
LOOKUP(GenerateRSASignature, OEMCrypto_GenerateRSASignature);
|
||||
LOOKUP(SupportsUsageTable, OEMCrypto_SupportsUsageTable);
|
||||
LOOKUP(UpdateUsageTable, OEMCrypto_UpdateUsageTable);
|
||||
@@ -347,6 +346,7 @@ class Adapter {
|
||||
LOOKUP(DeleteUsageEntry, OEMCrypto_DeleteUsageEntry);
|
||||
LOOKUP(DeleteUsageTable, OEMCrypto_DeleteUsageTable);
|
||||
if (level1_.version == 9) {
|
||||
LOOKUP(LoadKeys_V9_or_V10, OEMCrypto_LoadKeys_V9_or_V10);
|
||||
LOOKUP(GetHDCPCapability_V9, OEMCrypto_GetHDCPCapability_V9);
|
||||
} else {
|
||||
LOOKUP(LoadTestKeybox, OEMCrypto_LoadTestKeybox);
|
||||
@@ -359,9 +359,9 @@ class Adapter {
|
||||
LOOKUP(GetMaxNumberOfSessions, OEMCrypto_GetMaxNumberOfSessions);
|
||||
LOOKUP(ForceDeleteUsageEntry, OEMCrypto_ForceDeleteUsageEntry);
|
||||
if (level1_.version == 10) {
|
||||
LOOKUP(LoadKeys_V10, OEMCrypto_LoadKeys_V10);
|
||||
LOOKUP(DecryptCTR_V10, OEMCrypto_DecryptCTR_V10);
|
||||
} else {
|
||||
LOOKUP(LoadKeys_V9_or_V10, OEMCrypto_LoadKeys_V9_or_V10);
|
||||
LOOKUP(DecryptCTR_V10, OEMCrypto_DecryptCTR_V10);
|
||||
} else { // version 11.
|
||||
LOOKUP(LoadKeys, OEMCrypto_LoadKeys);
|
||||
LOOKUP(DecryptCENC, OEMCrypto_DecryptCENC);
|
||||
LOOKUP(SecurityPatchLevel, OEMCrypto_Security_Patch_Level);
|
||||
@@ -420,7 +420,7 @@ class Adapter {
|
||||
level3_.GenerateDerivedKeys = Level3_GenerateDerivedKeys;
|
||||
level3_.GenerateNonce = Level3_GenerateNonce;
|
||||
level3_.GenerateSignature = Level3_GenerateSignature;
|
||||
level3_.LoadKeys_V10 = Level3_LoadKeys;
|
||||
level3_.LoadKeys_V9_or_V10 = Level3_LoadKeys;
|
||||
level3_.RefreshKeys = Level3_RefreshKeys;
|
||||
level3_.QueryKeyControl = Level3_QueryKeyControl;
|
||||
level3_.SelectKey = Level3_SelectKey;
|
||||
@@ -609,7 +609,7 @@ uint8_t OEMCrypto_Security_Patch_Level(SecurityLevel level) {
|
||||
if (!kAdapter) return 0;
|
||||
const FunctionPointers* fcn = kAdapter->get(level);
|
||||
if (!fcn) return 0;
|
||||
if (fcn->version < 10) return 0;
|
||||
if (fcn->version < 11) return 0;
|
||||
return fcn->SecurityPatchLevel();
|
||||
}
|
||||
|
||||
@@ -742,13 +742,9 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys(
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
if (pair.fcn->version == 8) {
|
||||
return pair.fcn->LoadKeys_V8(pair.session, message, message_length,
|
||||
signature, signature_length, enc_mac_key_iv,
|
||||
enc_mac_key, num_keys, key_array);
|
||||
} else if (pair.fcn->version < 11) {
|
||||
if (pair.fcn->version < 11) {
|
||||
std::vector<OEMCrypto_KeyObject_V10> key_array_v10(num_keys);
|
||||
for(int i=0; i< num_keys; i++) {
|
||||
for(size_t i=0; i < num_keys; i++) {
|
||||
key_array_v10[i].key_id = key_array[i].key_id;
|
||||
key_array_v10[i].key_id_length = key_array[i].key_id_length;
|
||||
key_array_v10[i].key_data_iv = key_array[i].key_data_iv;
|
||||
@@ -761,10 +757,17 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys(
|
||||
return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
return pair.fcn->LoadKeys_V10(pair.session, message, message_length,
|
||||
signature,
|
||||
signature_length, enc_mac_key_iv, enc_mac_key,
|
||||
num_keys, &key_array_v10[0], pst, pst_length);
|
||||
if (pair.fcn->version == 8) {
|
||||
return pair.fcn->LoadKeys_V8(pair.session, message, message_length,
|
||||
signature, signature_length, enc_mac_key_iv,
|
||||
enc_mac_key, num_keys, &key_array_v10[0]);
|
||||
} else {
|
||||
return pair.fcn->LoadKeys_V9_or_V10(pair.session, message, message_length,
|
||||
signature, signature_length,
|
||||
enc_mac_key_iv, enc_mac_key,
|
||||
num_keys, &key_array_v10[0],
|
||||
pst, pst_length);
|
||||
}
|
||||
} else {
|
||||
return pair.fcn->LoadKeys(pair.session, message, message_length, signature,
|
||||
signature_length, enc_mac_key_iv, enc_mac_key,
|
||||
@@ -806,7 +809,8 @@ extern "C" OEMCryptoResult OEMCrypto_SelectKey(const OEMCrypto_SESSION session,
|
||||
extern "C" OEMCryptoResult OEMCrypto_DecryptCENC(
|
||||
OEMCrypto_SESSION session, const uint8_t* data_addr, size_t data_length,
|
||||
bool is_encrypted, const uint8_t* iv, size_t offset,
|
||||
OEMCrypto_DestBufferDesc* out_buffer, const OEMCrypto_PatternDesc* pattern,
|
||||
OEMCrypto_DestBufferDesc* out_buffer,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern,
|
||||
uint8_t subsample_flags) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
@@ -944,6 +948,10 @@ extern "C" uint32_t OEMCrypto_APIVersion() {
|
||||
return OEMCrypto_APIVersion(kLevelDefault);
|
||||
}
|
||||
|
||||
extern "C" uint8_t OEMCrypto_Security_Patch_Level() {
|
||||
return OEMCrypto_Security_Patch_Level(kLevelDefault);
|
||||
}
|
||||
|
||||
extern "C" const char* OEMCrypto_SecurityLevel() {
|
||||
return OEMCrypto_SecurityLevel(kLevelDefault);
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -204,7 +204,7 @@ typedef enum OEMCrypto_Algorithm {
|
||||
#define OEMCrypto_FirstSubsample 1
|
||||
#define OEMCrypto_LastSubsample 2
|
||||
|
||||
/* OEMCrypto_PatternDesc
|
||||
/* OEMCrypto_CENCEncryptPatternDesc
|
||||
* This is used in OEMCrypto_DecryptCENC to indicate the encrypt/skip pattern
|
||||
* used, as specified in the CENC standard.
|
||||
*/
|
||||
@@ -212,7 +212,7 @@ typedef struct {
|
||||
size_t encrypt; // number of 16 byte blocks to decrypt.
|
||||
size_t skip; // number of 16 byte blocks to leave in clear.
|
||||
size_t offset; // offset into the pattern in blocks for this call.
|
||||
} OEMCrypto_PatternDesc;
|
||||
} OEMCrypto_CENCEncryptPatternDesc;
|
||||
|
||||
/*
|
||||
* OEMCrypto_Usage_Entry_Status.
|
||||
@@ -281,7 +281,7 @@ typedef enum OEMCrypto_HDCP_Capability {
|
||||
#define OEMCrypto_WrapKeybox _oecc08
|
||||
#define OEMCrypto_OpenSession _oecc09
|
||||
#define OEMCrypto_CloseSession _oecc10
|
||||
#define OEMCrypto_DecryptCTR _oecc11
|
||||
#define OEMCrypto_DecryptCTR_V10 _oecc11
|
||||
#define OEMCrypto_GenerateDerivedKeys _oecc12
|
||||
#define OEMCrypto_GenerateSignature _oecc13
|
||||
#define OEMCrypto_GenerateNonce _oecc14
|
||||
@@ -305,7 +305,7 @@ typedef enum OEMCrypto_HDCP_Capability {
|
||||
#define OEMCrypto_ReportUsage _oecc32
|
||||
#define OEMCrypto_DeleteUsageEntry _oecc33
|
||||
#define OEMCrypto_DeleteUsageTable _oecc34
|
||||
#define OEMCrypto_LoadKeys_v10 _oecc35
|
||||
#define OEMCrypto_LoadKeys_V9_or_V10 _oecc35
|
||||
#define OEMCrypto_GenerateRSASignature _oecc36
|
||||
#define OEMCrypto_GetMaxNumberOfSessions _oecc37
|
||||
#define OEMCrypto_GetNumberOfOpenSessions _oecc38
|
||||
@@ -1076,7 +1076,7 @@ OEMCryptoResult OEMCrypto_DecryptCENC(OEMCrypto_SESSION session,
|
||||
const uint8_t *iv,
|
||||
size_t block_offset,
|
||||
OEMCrypto_DestBufferDesc* out_buffer,
|
||||
const OEMCrypto_PatternDesc* pattern,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern,
|
||||
uint8_t subsample_flags);
|
||||
|
||||
|
||||
|
||||
@@ -50,4 +50,10 @@ const char* CryptoEngine::security_level() {
|
||||
return "L3";
|
||||
}
|
||||
|
||||
// This should start at 0, and be incremented only when a security patch has
|
||||
// been applied to the device that fixes a security bug.
|
||||
uint8_t CryptoEngine::security_patch_level() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace wvoec_mock
|
||||
|
||||
@@ -51,4 +51,10 @@ const char* CryptoEngine::security_level() {
|
||||
return "L1";
|
||||
}
|
||||
|
||||
// This should start at 0, and be incremented only when a security patch has
|
||||
// been applied to the device that fixes a security bug.
|
||||
uint8_t CryptoEngine::security_patch_level() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
} // namespace wvoec_mock
|
||||
|
||||
@@ -53,4 +53,10 @@ const char* CryptoEngine::security_level() {
|
||||
return "L2";
|
||||
}
|
||||
|
||||
// This should start at 0, and be incremented only when a security patch has
|
||||
// been applied to the device that fixes a security bug.
|
||||
uint8_t CryptoEngine::security_patch_level() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace wvoec_mock
|
||||
|
||||
@@ -683,6 +683,14 @@ bool SessionContext::InstallKey(const KeyId& key_id,
|
||||
LOGE("Anti-rollback hardware is required but hardware not present.");
|
||||
return false;
|
||||
}
|
||||
uint8_t minimum_patch_level
|
||||
= (key_control_block.control_bits() & kControlSecurityPatchLevelMask) >>
|
||||
kControlSecurityPatchLevelShift;
|
||||
if (minimum_patch_level > OEMCrypto_Security_Patch_Level()) {
|
||||
LOGE("[InstallKey(): security patch level: %d. Minimum:%d]",
|
||||
OEMCrypto_Security_Patch_Level(), minimum_patch_level);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CheckNonceOrEntry(key_control_block, pst)) {
|
||||
LOGE("Failed Nonce/PST check.");
|
||||
|
||||
@@ -259,6 +259,7 @@ class CryptoEngine {
|
||||
bool supports_keybox();
|
||||
bool is_anti_rollback_hw_present();
|
||||
const char* security_level();
|
||||
uint8_t security_patch_level();
|
||||
|
||||
private:
|
||||
bool LoadPkcs8RsaKey(const uint8_t* buffer, size_t length);
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace wvoec_mock {
|
||||
bool KeyControlBlock::Validate() {
|
||||
if (memcmp(verification_, "kctl", 4) && // original verification
|
||||
memcmp(verification_, "kc09", 4) && // add in version 9 api
|
||||
memcmp(verification_, "kc10", 4)) { // add in version 10 api
|
||||
memcmp(verification_, "kc10", 4) && // add in version 10 api
|
||||
memcmp(verification_, "kc11", 4)) { // add in version 11 api
|
||||
LOGE("KCB: BAD verification string: %4.4s", verification_);
|
||||
valid_ = false;
|
||||
} else {
|
||||
@@ -71,6 +72,9 @@ KeyControlBlock::KeyControlBlock(
|
||||
LOGD(" bits kControlKDCPVersion 0x%02x.",
|
||||
(control_bits() & kControlHDCPVersionMask)
|
||||
>> kControlHDCPVersionShift);
|
||||
LOGD(" bits kControlSecurityPatchLevel 0x%02x.",
|
||||
(control_bits() & kControlSecurityPatchLevelMask)
|
||||
>> kControlSecurityPatchLevelShift);
|
||||
LOGD(" bit kControlAllowEncrypt %s.",
|
||||
(control_bits() & kControlAllowEncrypt) ? "set" : "unset");
|
||||
LOGD(" bit kControlAllowDecrypt %s.",
|
||||
|
||||
@@ -15,6 +15,9 @@ const uint32_t kControlObserveDataPath = (1<<31);
|
||||
const uint32_t kControlObserveHDCP = (1<<30);
|
||||
const uint32_t kControlObserveCGMS = (1<<29);
|
||||
const uint32_t kControlRequireAntiRollbackHardware = (1<<28);
|
||||
const uint32_t kControlSecurityPatchLevelShift = 15;
|
||||
const uint32_t kControlSecurityPatchLevelMask =
|
||||
(0x3F<<kControlSecurityPatchLevelShift);
|
||||
const uint32_t kControlReplayMask = (0x03<<13);
|
||||
const uint32_t kControlNonceRequired = (0x01<<13);
|
||||
const uint32_t kControlNonceOrEntry = (0x02<<13);
|
||||
|
||||
@@ -327,6 +327,8 @@ OEMCryptoResult OEMCrypto_LoadKeys(OEMCrypto_SESSION session,
|
||||
key_array[i].key_control_iv, wvcdm::KEY_IV_SIZE);
|
||||
dump_array_part("key_array", i, "key_control",
|
||||
key_array[i].key_control, wvcdm::KEY_IV_SIZE);
|
||||
LOGV("key_array[%zu].cipher_mode=%s;\n", i,
|
||||
key_array[i].cipher_mode == OEMCrypto_CipherMode_CTR ? "CTR" : "CBC");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,6 +382,10 @@ OEMCryptoResult OEMCrypto_LoadKeys(OEMCrypto_SESSION session,
|
||||
LOGE("[OEMCrypto_LoadKeys(): OEMCrypto_ERROR_INVALID_CONTEXT -range check %d]", i);
|
||||
return OEMCrypto_ERROR_INVALID_CONTEXT;
|
||||
}
|
||||
if (key_array[i].cipher_mode != OEMCrypto_CipherMode_CTR) {
|
||||
LOGE("[OEMCrypto_LoadKeys(): CBC Mode not yet implemented]");
|
||||
return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
return session_ctx->LoadKeys(message, message_length, signature,
|
||||
@@ -603,7 +609,7 @@ OEMCryptoResult OEMCrypto_DecryptCENC(OEMCrypto_SESSION session,
|
||||
const uint8_t* iv,
|
||||
size_t block_offset,
|
||||
OEMCrypto_DestBufferDesc* out_buffer,
|
||||
const OEMCrypto_PatternDesc* pattern,
|
||||
const OEMCrypto_CENCEncryptPatternDesc* pattern,
|
||||
uint8_t subsample_flags) {
|
||||
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
|
||||
LOGI("-- OEMCryptoResult OEMCrypto_DecryptCTR"
|
||||
@@ -1214,14 +1220,19 @@ uint32_t OEMCrypto_APIVersion() {
|
||||
|
||||
extern "C"
|
||||
uint8_t OEMCrypto_Security_Patch_Level() {
|
||||
return 0;
|
||||
uint8_t security_patch_level = crypto_engine->security_patch_level();
|
||||
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
|
||||
LOGI("-- uint8_t OEMCrypto_Security_Patch_Level(); // returns %d.\n",
|
||||
security_patch_level);
|
||||
}
|
||||
return security_patch_level;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const char* OEMCrypto_SecurityLevel() {
|
||||
const char* security_level = crypto_engine->security_level();
|
||||
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
|
||||
LOGI("-- bool OEMCrypto_SecurityLevel(); // returns %s.\n", security_level);
|
||||
LOGI("-- const char* OEMCrypto_SecurityLevel(); // returns %s.\n", security_level);
|
||||
}
|
||||
return security_level;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user