Skip to content

Commit

Permalink
[Android] Reorganize trusted signatures initialization
Browse files Browse the repository at this point in the history
Move runtime trusted signatures config initialization from ConduitService to ConduitStateService and rename methods to better reflect their purpose
  • Loading branch information
efryntov committed Nov 26, 2024
1 parent 29efb05 commit e5b17b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,8 @@ private void processTrustedApps(JSONObject params) {
trustedSignatures.put(packageName, signatureSet);
}

// Save the trusted signatures to storage and load them right away
PackageHelper.saveTrustedSignatures(getApplicationContext(), trustedSignatures);
PackageHelper.loadTrustedSignatures(trustedSignatures);
// Save the trusted signatures to file
PackageHelper.saveTrustedSignaturesToFile(getApplicationContext(), trustedSignatures);
} catch (JSONException e) {
MyLog.e(TAG, "Failed to parse trusted apps signatures: " + e);
}
Expand All @@ -327,9 +326,6 @@ private void processTrustedApps(JSONObject params) {
public void onCreate() {
super.onCreate();
MyLog.init(getApplicationContext());

// Load existing trusted signatures from storage
PackageHelper.loadTrustedSignatures(PackageHelper.getTrustedSignatures(getApplicationContext()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public void unregisterClient(IConduitStateCallback client) {
public void onCreate() {
MyLog.init(getApplicationContext());

// Load runtime trusted signatures configuration from file
PackageHelper.configureRuntimeTrustedSignatures(PackageHelper.readTrustedSignaturesFromFile(getApplicationContext()));

conduitServiceInteractor = new ConduitServiceInteractor(getApplicationContext());
conduitServiceInteractor.onStart(getApplicationContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static boolean isPackageInstalled(PackageManager packageManager, String p

// Save the map of package signatures to a file
// Avoid calling this method from different processes simultaneously to ensure single-writer safety
public static synchronized void saveTrustedSignatures(Context context, Map<String, Set<String>> signatures) {
public static synchronized void saveTrustedSignaturesToFile(Context context, Map<String, Set<String>> signatures) {
File tempFile = new File(context.getFilesDir(), "trusted_signatures_temp.json");
File finalFile = new File(context.getFilesDir(), SIGNATURES_JSON_FILE);
try (FileWriter writer = new FileWriter(tempFile)) {
Expand All @@ -147,7 +147,7 @@ public static synchronized void saveTrustedSignatures(Context context, Map<Strin
}

// Read the map of package signatures from a file, can be called from any process
public static Map<String, Set<String>> getTrustedSignatures(Context context) {
public static Map<String, Set<String>> readTrustedSignaturesFromFile(Context context) {
File file = new File(context.getFilesDir(), SIGNATURES_JSON_FILE);
Map<String, Set<String>> signatures = new HashMap<>();

Expand Down Expand Up @@ -179,7 +179,8 @@ public static Map<String, Set<String>> getTrustedSignatures(Context context) {
return signatures;
}

public static void loadTrustedSignatures(Map<String, Set<String>> signatures) {
// Load runtime trusted signatures configuration
public static void configureRuntimeTrustedSignatures(Map<String, Set<String>> signatures) {
RUNTIME_TRUSTED_PACKAGES.clear();
RUNTIME_TRUSTED_PACKAGES.putAll(signatures);
MyLog.i(TAG, "Loaded runtime signatures for " + signatures.size() + " packages");
Expand Down

0 comments on commit e5b17b2

Please sign in to comment.