Loading services/core/java/com/android/server/integrity/parser/RuleBinaryParser.java +1 −0 Original line number Diff line number Diff line Loading @@ -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: Loading services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java +37 −1 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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; Loading Loading
services/core/java/com/android/server/integrity/parser/RuleBinaryParser.java +1 −0 Original line number Diff line number Diff line Loading @@ -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: Loading
services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java +37 −1 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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; Loading