Skip to content

Commit 5f74578

Browse files
authored
Verify bloom checksum before load (#376)
1 parent e8210d9 commit 5f74578

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/BloomFilterTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BloomFilterTest {
5959
}
6060
}
6161

62-
val errorRate = falsePositives / testData.size
62+
val errorRate = falsePositives.toDouble() / testData.size.toDouble()
6363
assertEquals(0, falseNegatives)
6464
assertEquals(bloomData.size, truePositives)
6565
assertTrue(trueNegatives <= testData.size - bloomData.size)
@@ -73,9 +73,9 @@ class BloomFilterTest {
7373
}
7474

7575
companion object {
76-
const val FILTER_ELEMENT_COUNT = 1000
77-
const val ADDITIONAL_TEST_DATA_ELEMENT_COUNT = 9000
76+
const val FILTER_ELEMENT_COUNT = 5000
77+
const val ADDITIONAL_TEST_DATA_ELEMENT_COUNT = 5000
7878
const val TARGET_ERROR_RATE = 0.001
79-
const val ACCEPTABLE_ERROR_RATE = TARGET_ERROR_RATE * 1.1
79+
const val ACCEPTABLE_ERROR_RATE = TARGET_ERROR_RATE * 2
8080
}
8181
}

app/src/main/java/com/duckduckgo/app/httpsupgrade/api/HttpsBloomFilterFactory.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class HttpsBloomFilterFactoryImpl @Inject constructor(private val dao: HttpsBloo
4343
return null
4444
}
4545

46+
if (!binaryDataStore.verifyCheckSum(HTTPS_BINARY_FILE, specification.sha256)) {
47+
Timber.d("Https update data failed checksum, clearing")
48+
binaryDataStore.clearData(HTTPS_BINARY_FILE)
49+
return null
50+
}
51+
4652
val initialTimestamp = System.currentTimeMillis()
4753
Timber.d("Found https data at $dataPath, building filter")
4854
var bloomFilter = BloomFilter(dataPath, specification.totalEntries)

app/src/main/java/com/duckduckgo/app/httpsupgrade/api/HttpsUpgradeDataDownloader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class HttpsUpgradeDataDownloader @Inject constructor(
7979

8080
val bytes = response.body()!!.bytes()
8181
if (!binaryDataStore.verifyCheckSum(bytes, specification.sha256)) {
82-
throw IOException("Https binary has incorrect checksum, throwing away file")
82+
throw IOException("Https binary has incorrect sha, throwing away file")
8383
}
8484

8585
Timber.d("Updating https bloom data store with new data")

0 commit comments

Comments
 (0)