Avoid storing download IDs in the ct.preferences file
We are trying to reduce the usage of the DataStore, as it has caused the occasional headache in the past (see for example ag/32804820). This CL removes the storing download IDs on disk. Storing the download IDs is unnecessary anyway, we schedule a new download on a system_server or device reboot anyway. Bug: 407940468 Test: atest NetworkSecurityUnitTests Flag: com.android.net.ct.flags.certificate_transparency_service Change-Id: I18bc752aa26978f877f669d343d5432f83a36ae4
This commit is contained in:
parent
dc230f157a
commit
0394ebba3b
3 changed files with 10 additions and 20 deletions
|
|
@ -33,6 +33,8 @@ import com.android.server.net.ct.DownloadHelper.DownloadStatus;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Helper class to download certificate transparency log files. */
|
||||
|
|
@ -42,22 +44,21 @@ class CertificateTransparencyDownloader extends BroadcastReceiver {
|
|||
private static final String TAG = "CertificateTransparencyDownloader";
|
||||
|
||||
private final Context mContext;
|
||||
private final DataStore mDataStore;
|
||||
private final DownloadHelper mDownloadHelper;
|
||||
private final SignatureVerifier mSignatureVerifier;
|
||||
private final CertificateTransparencyLogger mLogger;
|
||||
private final Collection<CompatibilityVersion> mCompatVersions;
|
||||
|
||||
private final Map<String, Long> mDownloadIds = new HashMap<>();
|
||||
|
||||
CertificateTransparencyDownloader(
|
||||
Context context,
|
||||
DataStore dataStore,
|
||||
DownloadHelper downloadHelper,
|
||||
SignatureVerifier signatureVerifier,
|
||||
CertificateTransparencyLogger logger,
|
||||
Collection<CompatibilityVersion> compatVersions) {
|
||||
mContext = context;
|
||||
mSignatureVerifier = signatureVerifier;
|
||||
mDataStore = dataStore;
|
||||
mDownloadHelper = downloadHelper;
|
||||
mLogger = logger;
|
||||
mCompatVersions = compatVersions;
|
||||
|
|
@ -66,8 +67,7 @@ class CertificateTransparencyDownloader extends BroadcastReceiver {
|
|||
long startPublicKeyDownload() {
|
||||
long downloadId = download(Config.URL_PUBLIC_KEY);
|
||||
if (downloadId != -1) {
|
||||
mDataStore.setPropertyLong(Config.PUBLIC_KEY_DOWNLOAD_ID, downloadId);
|
||||
mDataStore.store();
|
||||
mDownloadIds.put(Config.PUBLIC_KEY_DOWNLOAD_ID, downloadId);
|
||||
}
|
||||
return downloadId;
|
||||
}
|
||||
|
|
@ -75,8 +75,7 @@ class CertificateTransparencyDownloader extends BroadcastReceiver {
|
|||
private long startMetadataDownload(CompatibilityVersion compatVersion) {
|
||||
long downloadId = download(compatVersion.getMetadataUrl());
|
||||
if (downloadId != -1) {
|
||||
mDataStore.setPropertyLong(compatVersion.getMetadataPropertyName(), downloadId);
|
||||
mDataStore.store();
|
||||
mDownloadIds.put(compatVersion.getMetadataPropertyName(), downloadId);
|
||||
}
|
||||
return downloadId;
|
||||
}
|
||||
|
|
@ -96,8 +95,7 @@ class CertificateTransparencyDownloader extends BroadcastReceiver {
|
|||
long startContentDownload(CompatibilityVersion compatVersion) {
|
||||
long downloadId = download(compatVersion.getContentUrl());
|
||||
if (downloadId != -1) {
|
||||
mDataStore.setPropertyLong(compatVersion.getContentPropertyName(), downloadId);
|
||||
mDataStore.store();
|
||||
mDownloadIds.put(compatVersion.getContentPropertyName(), downloadId);
|
||||
}
|
||||
return downloadId;
|
||||
}
|
||||
|
|
@ -235,19 +233,17 @@ class CertificateTransparencyDownloader extends BroadcastReceiver {
|
|||
|
||||
@VisibleForTesting
|
||||
long getPublicKeyDownloadId() {
|
||||
return mDataStore.getPropertyLong(Config.PUBLIC_KEY_DOWNLOAD_ID, /* defaultValue= */ -1);
|
||||
return mDownloadIds.getOrDefault(Config.PUBLIC_KEY_DOWNLOAD_ID, -1L);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
long getMetadataDownloadId(CompatibilityVersion compatVersion) {
|
||||
return mDataStore.getPropertyLong(
|
||||
compatVersion.getMetadataPropertyName(), /* defaultValue */ -1);
|
||||
return mDownloadIds.getOrDefault(compatVersion.getMetadataPropertyName(), -1L);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
long getContentDownloadId(CompatibilityVersion compatVersion) {
|
||||
return mDataStore.getPropertyLong(
|
||||
compatVersion.getContentPropertyName(), /* defaultValue= */ -1);
|
||||
return mDownloadIds.getOrDefault(compatVersion.getContentPropertyName(), -1L);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ public class CertificateTransparencyService extends ICertificateTransparencyMana
|
|||
dataStore,
|
||||
new CertificateTransparencyDownloader(
|
||||
context,
|
||||
dataStore,
|
||||
new DownloadHelper(context),
|
||||
signatureVerifier,
|
||||
new CertificateTransparencyLoggerImpl(dataStore),
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ public class CertificateTransparencyDownloaderTest {
|
|||
private PrivateKey mPrivateKey;
|
||||
private PublicKey mPublicKey;
|
||||
private Context mContext;
|
||||
private DataStore mDataStore;
|
||||
private SignatureVerifier mSignatureVerifier;
|
||||
private CompatibilityVersion mCompatVersion;
|
||||
private CertificateTransparencyDownloader mCertificateTransparencyDownloader;
|
||||
|
|
@ -93,7 +92,6 @@ public class CertificateTransparencyDownloaderTest {
|
|||
mPublicKey = keyPair.getPublic();
|
||||
|
||||
mContext = InstrumentationRegistry.getInstrumentation().getContext();
|
||||
mDataStore = new DataStore(File.createTempFile("datastore-test", ".properties"));
|
||||
mSignatureVerifier = new SignatureVerifier(mContext);
|
||||
|
||||
CompatibilityVersion.setRootDirectoryForTesting(mContext.getFilesDir());
|
||||
|
|
@ -105,7 +103,6 @@ public class CertificateTransparencyDownloaderTest {
|
|||
mCertificateTransparencyDownloader =
|
||||
new CertificateTransparencyDownloader(
|
||||
mContext,
|
||||
mDataStore,
|
||||
new DownloadHelper(mDownloadManager),
|
||||
mSignatureVerifier,
|
||||
mLogger,
|
||||
|
|
@ -113,14 +110,12 @@ public class CertificateTransparencyDownloaderTest {
|
|||
|
||||
prepareDownloadManager();
|
||||
mSignatureVerifier.addAllowedKey(mPublicKey);
|
||||
mDataStore.load();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mSignatureVerifier.resetPublicKey();
|
||||
mCompatVersion.delete();
|
||||
mDataStore.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue