Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d018607 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix the bug on APP_CERTIFICATE_LINEAGE rule as we forgot to modify the...

Merge "Fix the bug on APP_CERTIFICATE_LINEAGE rule as we forgot to modify the binary rule parser to support the new rule." into tm-dev am: f084f35b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16988947

Change-Id: I71182894aa2f20cbbb5b1a29fa97ed1ac5e683bb
parents a89ff2a5 f084f35b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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:
+37 −1
Original line number Diff line number Diff line
@@ -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;