diff options
| author | 2024-10-22 07:38:13 +0000 | |
|---|---|---|
| committer | 2024-10-22 07:38:13 +0000 | |
| commit | e37b8ffd8fb18d9debc05fc1fd8acb9eae15afa9 (patch) | |
| tree | 14b940d2c1e231b7ef421780fe2371df8d7df1a4 | |
| parent | 6faa37113c69eef5b0f1b49e4ba84db7927241e2 (diff) | |
| parent | 359075db1568990e3a22ea7265317bb1f4395333 (diff) | |
Merge "Remove the updateRuleSet actions to stop writing the rules into AOSP component when the method is called." into main
2 files changed, 11 insertions, 142 deletions
diff --git a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java index d1576c5cca4f..509fa3e1c9ba 100644 --- a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java +++ b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java @@ -127,42 +127,18 @@ public class AppIntegrityManagerServiceImpl extends IAppIntegrityManager.Stub { @BinderThread public void updateRuleSet( String version, ParceledListSlice<Rule> rules, IntentSender statusReceiver) { - String ruleProvider = getCallerPackageNameOrThrow(Binder.getCallingUid()); - if (DEBUG_INTEGRITY_COMPONENT) { - Slog.i(TAG, String.format("Calling rule provider name is: %s.", ruleProvider)); + Intent intent = new Intent(); + intent.putExtra(EXTRA_STATUS, STATUS_SUCCESS); + try { + statusReceiver.sendIntent( + mContext, + /* code= */ 0, + intent, + /* onFinished= */ null, + /* handler= */ null); + } catch (Exception e) { + Slog.e(TAG, "Error sending status feedback.", e); } - - mHandler.post( - () -> { - boolean success = true; - try { - mIntegrityFileManager.writeRules(version, ruleProvider, rules.getList()); - } catch (Exception e) { - Slog.e(TAG, "Error writing rules.", e); - success = false; - } - - if (DEBUG_INTEGRITY_COMPONENT) { - Slog.i( - TAG, - String.format( - "Successfully pushed rule set to version '%s' from '%s'", - version, ruleProvider)); - } - - Intent intent = new Intent(); - intent.putExtra(EXTRA_STATUS, success ? STATUS_SUCCESS : STATUS_FAILURE); - try { - statusReceiver.sendIntent( - mContext, - /* code= */ 0, - intent, - /* onFinished= */ null, - /* handler= */ null); - } catch (Exception e) { - Slog.e(TAG, "Error sending status feedback.", e); - } - }); } @Override @@ -209,21 +185,6 @@ public class AppIntegrityManagerServiceImpl extends IAppIntegrityManager.Stub { verificationId, PackageManagerInternal.INTEGRITY_VERIFICATION_ALLOW); } - /** We will use the SHA256 digest of a package name if it is more than 32 bytes long. */ - private String getPackageNameNormalized(String packageName) { - if (packageName.length() <= 32) { - return packageName; - } - - try { - MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); - byte[] hashBytes = messageDigest.digest(packageName.getBytes(StandardCharsets.UTF_8)); - return getHexDigest(hashBytes); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("SHA-256 algorithm not found", e); - } - } - private String getCallerPackageNameOrThrow(int callingUid) { String callerPackageName = getCallingRulePusherPackageName(callingUid); if (callerPackageName == null) { diff --git a/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java b/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java index 9c6412b81b34..a2e6d4c7bfed 100644 --- a/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java +++ b/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java @@ -191,98 +191,6 @@ public class AppIntegrityManagerServiceImplTest { } @Test - public void updateRuleSet_notAuthorized() throws Exception { - makeUsSystemApp(); - Rule rule = - new Rule( - new AtomicFormula.BooleanAtomicFormula(AtomicFormula.PRE_INSTALLED, true), - Rule.DENY); - TestUtils.assertExpectException( - SecurityException.class, - "Only system packages specified in config_integrityRuleProviderPackages are" - + " allowed to call this method.", - () -> - mService.updateRuleSet( - VERSION, - new ParceledListSlice<>(Arrays.asList(rule)), - /* statusReceiver= */ null)); - } - - @Test - public void updateRuleSet_notSystemApp() throws Exception { - allowlistUsAsRuleProvider(); - makeUsSystemApp(false); - Rule rule = - new Rule( - new AtomicFormula.BooleanAtomicFormula(AtomicFormula.PRE_INSTALLED, true), - Rule.DENY); - TestUtils.assertExpectException( - SecurityException.class, - "Only system packages specified in config_integrityRuleProviderPackages are" - + " allowed to call this method.", - () -> - mService.updateRuleSet( - VERSION, - new ParceledListSlice<>(Arrays.asList(rule)), - /* statusReceiver= */ null)); - } - - @Test - public void updateRuleSet_authorized() throws Exception { - allowlistUsAsRuleProvider(); - makeUsSystemApp(); - Rule rule = - new Rule( - new AtomicFormula.BooleanAtomicFormula(AtomicFormula.PRE_INSTALLED, true), - Rule.DENY); - - // no SecurityException - mService.updateRuleSet( - VERSION, new ParceledListSlice<>(Arrays.asList(rule)), mock(IntentSender.class)); - } - - @Test - public void updateRuleSet_correctMethodCall() throws Exception { - allowlistUsAsRuleProvider(); - makeUsSystemApp(); - IntentSender mockReceiver = mock(IntentSender.class); - List<Rule> rules = - Arrays.asList( - new Rule( - IntegrityFormula.Application.packageNameEquals(PACKAGE_NAME), - Rule.DENY)); - - mService.updateRuleSet(VERSION, new ParceledListSlice<>(rules), mockReceiver); - runJobInHandler(); - - verify(mIntegrityFileManager).writeRules(VERSION, TEST_FRAMEWORK_PACKAGE, rules); - ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); - verify(mockReceiver).sendIntent(any(), anyInt(), intentCaptor.capture(), any(), any()); - assertEquals(STATUS_SUCCESS, intentCaptor.getValue().getIntExtra(EXTRA_STATUS, -1)); - } - - @Test - public void updateRuleSet_fail() throws Exception { - allowlistUsAsRuleProvider(); - makeUsSystemApp(); - doThrow(new IOException()).when(mIntegrityFileManager).writeRules(any(), any(), any()); - IntentSender mockReceiver = mock(IntentSender.class); - List<Rule> rules = - Arrays.asList( - new Rule( - IntegrityFormula.Application.packageNameEquals(PACKAGE_NAME), - Rule.DENY)); - - mService.updateRuleSet(VERSION, new ParceledListSlice<>(rules), mockReceiver); - runJobInHandler(); - - verify(mIntegrityFileManager).writeRules(VERSION, TEST_FRAMEWORK_PACKAGE, rules); - ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); - verify(mockReceiver).sendIntent(any(), anyInt(), intentCaptor.capture(), any(), any()); - assertEquals(STATUS_FAILURE, intentCaptor.getValue().getIntExtra(EXTRA_STATUS, -1)); - } - - @Test public void broadcastReceiverRegistration() throws Exception { allowlistUsAsRuleProvider(); makeUsSystemApp(); |