Skip to content

Commit 6edfeee

Browse files
authored
Update bundled CRL to latest Google status (#14)
* Update bundled CRL to latest Google status * Fix locale string resolution in HomeAdapter * Fix conflicting app declaration in HomeAdapter * Fix schema migration bug for legacy CRL caches
1 parent 200d6a7 commit 6edfeee

4 files changed

Lines changed: 139 additions & 104 deletions

File tree

app/src/main/java/io/github/vvb2060/keyattestation/attestation/RevocationList.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,41 @@ private static StatusResult getStatus() {
129129

130130
// 1. Network Check
131131
NetworkResult networkResult = fetchFromNetwork(statusUrl, cachedTime);
132-
if (networkResult != null) {
133-
if (networkResult.responseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
134-
try (var fis = AppApplication.app.openFileInput(CACHE_FILE)) {
135-
var cacheJson = parseStatus(fis);
136-
publishTime = new Date(cachedTime);
137-
return new StatusResult(cacheJson.getJSONObject("entries"), DataSource.NETWORK_UP_TO_DATE);
138-
} catch (Exception e) {
139-
Log.w(TAG, "Failed to read cache despite 304 response. Falling back.", e);
132+
133+
if (networkResult != null && networkResult.responseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
134+
try (var fis = AppApplication.app.openFileInput(CACHE_FILE)) {
135+
var cacheJson = parseStatus(fis);
136+
publishTime = new Date(cachedTime);
137+
return new StatusResult(cacheJson.getJSONObject("entries"), DataSource.NETWORK_UP_TO_DATE);
138+
} catch (Exception e) {
139+
Log.w(TAG, "Legacy cache format detected. Clearing and forcing fresh fetch.", e);
140+
141+
// 1. Wipe the old, incompatible cache file
142+
AppApplication.app.deleteFile(CACHE_FILE);
143+
144+
// 2. Wipe the saved timestamp so we don't send If-Modified-Since again
145+
prefs.edit().remove(KEY_PUBLISH_TIME).apply();
146+
147+
// 3. Immediately force a fresh 200 OK download
148+
NetworkResult retryResult = fetchFromNetwork(statusUrl, 0);
149+
150+
if (retryResult != null && retryResult.json() != null) {
151+
saveToCache(retryResult.json());
152+
153+
try {
154+
return new StatusResult(retryResult.json().getJSONObject("entries"), DataSource.NETWORK_UPDATE);
155+
} catch (JSONException je) {
156+
Log.e(TAG, "Failed to parse entries from fresh fallback fetch", je);
157+
}
140158
}
141-
} else if (networkResult.json() != null) {
142-
saveToCache(networkResult.json());
143-
try {
144-
return new StatusResult(networkResult.json().getJSONObject("entries"), DataSource.NETWORK_UPDATE);
145-
} catch (JSONException ignored) {}
146159
}
160+
} else if (networkResult != null && networkResult.json() != null) {
161+
saveToCache(networkResult.json());
162+
try {
163+
return new StatusResult(networkResult.json().getJSONObject("entries"), DataSource.NETWORK_UPDATE);
164+
} catch (JSONException ignored) {}
147165
}
148-
166+
149167
// 2. Cache
150168
try (var fis = AppApplication.app.openFileInput(CACHE_FILE)) {
151169
var cacheJson = parseStatus(fis);

app/src/main/java/io/github/vvb2060/keyattestation/home/HomeAdapter.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,21 @@ class HomeAdapter(listener: Listener) : IdBasedRecyclerViewAdapter() {
102102
val dateStr = publishTime?.let {
103103
io.github.vvb2060.keyattestation.attestation.AuthorizationList.formatDate(it)
104104
} ?: ""
105-
105+
106+
val locales = androidx.appcompat.app.AppCompatDelegate.getApplicationLocales()
107+
val context = if (!locales.isEmpty) {
108+
val config = android.content.res.Configuration(app.resources.configuration)
109+
config.setLocale(locales[0])
110+
app.createConfigurationContext(config)
111+
} else {
112+
app
113+
}
114+
106115
val statusLine = when (source) {
107-
RevocationList.DataSource.NETWORK_UPDATE -> app.getString(R.string.revocation_status_new_fetch)
108-
RevocationList.DataSource.NETWORK_UP_TO_DATE -> app.getString(R.string.revocation_status_up_to_date)
109-
RevocationList.DataSource.CACHE -> app.getString(R.string.revocation_status_offline_cached)
110-
RevocationList.DataSource.BUNDLED -> app.getString(R.string.revocation_status_offline_bundled)
116+
RevocationList.DataSource.NETWORK_UPDATE -> context.getString(R.string.revocation_status_new_fetch)
117+
RevocationList.DataSource.NETWORK_UP_TO_DATE -> context.getString(R.string.revocation_status_up_to_date)
118+
RevocationList.DataSource.CACHE -> context.getString(R.string.revocation_status_offline_cached)
119+
RevocationList.DataSource.BUNDLED -> context.getString(R.string.revocation_status_offline_bundled)
111120
else -> ""
112121
}
113122

0 commit comments

Comments
 (0)