Merge "Fix the isHashed value to true for all certificate keys."

This commit is contained in:
TreeHugger Robot
2020-02-06 20:19:37 +00:00
committed by Android (Google) Code Review
3 changed files with 14 additions and 8 deletions

View File

@@ -332,9 +332,12 @@ public abstract class AtomicFormula extends IntegrityFormula {
* Constructs a new {@link StringAtomicFormula} together with handling the necessary
* hashing for the given key.
*
* <p> The value will be hashed with SHA256 and the hex digest will be computed; for
* all cases except when the key is PACKAGE_NAME or INSTALLER_NAME and the value
* is less than 33 characters.
* <p> The value will be automatically hashed with SHA256 and the hex digest will be
* computed when the key is PACKAGE_NAME or INSTALLER_NAME and the value is more than 32
* characters.
*
* <p> The APP_CERTIFICATES and INSTALLER_CERTIFICATES are always delivered in hashed
* form. So the isHashedValue is set to true by default.
*
* @throws IllegalArgumentException if {@code key} cannot be used with string value.
*/
@@ -348,7 +351,10 @@ public abstract class AtomicFormula extends IntegrityFormula {
String.format(
"Key %s cannot be used with StringAtomicFormula", keyToString(key)));
mValue = hashValue(key, value);
mIsHashedValue = !mValue.equals(value);
mIsHashedValue =
key == APP_CERTIFICATE || key == INSTALLER_CERTIFICATE
? true
: !mValue.equals(value);
}
StringAtomicFormula(Parcel in) {

View File

@@ -97,7 +97,7 @@ public class AtomicFormulaTest {
assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(appCert);
assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test
@@ -110,7 +110,7 @@ public class AtomicFormulaTest {
assertThat(stringAtomicFormula.getKey()).isEqualTo(
AtomicFormula.INSTALLER_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(installerCert);
assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test

View File

@@ -54,7 +54,7 @@ public class IntegrityFormulaTest {
assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(appCertificate);
assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test
@@ -82,7 +82,7 @@ public class IntegrityFormulaTest {
assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.INSTALLER_CERTIFICATE);
assertThat(stringAtomicFormula.getValue()).matches(installerCertificate);
assertThat(stringAtomicFormula.getIsHashedValue()).isFalse();
assertThat(stringAtomicFormula.getIsHashedValue()).isTrue();
}
@Test