Fix the bug on APP_CERTIFICATE_LINEAGE rule as we forgot to modify the

binary rule parser to support the new rule.

Bug: 218486995
Test: atest services/core/java/com/android/server/integrity/parser/RuleBinaryParser.java
Change-Id: Icd964b376829bfe04a1c06e5d86b73515eced8a7
This commit is contained in:
Ömer Yaveroğlu
2022-02-23 17:00:22 +00:00
parent 1c5859537d
commit 6055709095
2 changed files with 38 additions and 1 deletions

View File

@@ -168,6 +168,7 @@ public class RuleBinaryParser implements RuleParser {
switch (key) {
case AtomicFormula.PACKAGE_NAME:
case AtomicFormula.APP_CERTIFICATE:
case AtomicFormula.APP_CERTIFICATE_LINEAGE:
case AtomicFormula.INSTALLER_NAME:
case AtomicFormula.INSTALLER_CERTIFICATE:
case AtomicFormula.STAMP_CERTIFICATE_HASH:

View File

@@ -71,9 +71,11 @@ public class RuleBinaryParserTest {
private static final String PACKAGE_NAME = getBits(AtomicFormula.PACKAGE_NAME, KEY_BITS);
private static final String APP_CERTIFICATE = getBits(AtomicFormula.APP_CERTIFICATE, KEY_BITS);
private static final String APP_CERTIFICATE_LINEAGE =
getBits(AtomicFormula.APP_CERTIFICATE_LINEAGE, KEY_BITS);
private static final String VERSION_CODE = getBits(AtomicFormula.VERSION_CODE, KEY_BITS);
private static final String PRE_INSTALLED = getBits(AtomicFormula.PRE_INSTALLED, KEY_BITS);
private static final int INVALID_KEY_VALUE = 8;
private static final int INVALID_KEY_VALUE = 9;
private static final String INVALID_KEY = getBits(INVALID_KEY_VALUE, KEY_BITS);
private static final String EQ = getBits(AtomicFormula.EQ, OPERATOR_BITS);
@@ -336,6 +338,40 @@ public class RuleBinaryParserTest {
assertThat(rules).isEqualTo(Collections.singletonList(expectedRule));
}
@Test
public void testBinaryString_validAtomicFormulaWithCertificateLineage() throws Exception {
String appCertificate = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
String ruleBits =
START_BIT
+ ATOMIC_FORMULA_START_BITS
+ APP_CERTIFICATE_LINEAGE
+ EQ
+ IS_HASHED
+ getBits(appCertificate.length(), VALUE_SIZE_BITS)
+ getValueBits(appCertificate)
+ DENY
+ END_BIT;
byte[] ruleBytes = getBytes(ruleBits);
ByteBuffer rule =
ByteBuffer.allocate(DEFAULT_FORMAT_VERSION_BYTES.length + ruleBytes.length);
rule.put(DEFAULT_FORMAT_VERSION_BYTES);
rule.put(ruleBytes);
RuleParser binaryParser = new RuleBinaryParser();
Rule expectedRule =
new Rule(
new AtomicFormula.StringAtomicFormula(
AtomicFormula.APP_CERTIFICATE_LINEAGE,
IntegrityUtils.getHexDigest(
appCertificate.getBytes(StandardCharsets.UTF_8)),
/* isHashedValue= */ true),
Rule.DENY);
List<Rule> rules = binaryParser.parse(rule.array());
assertThat(rules).isEqualTo(Collections.singletonList(expectedRule));
}
@Test
public void testBinaryString_validAtomicFormula_integerValue_noIndexing() throws Exception {
int versionCode = 1;