-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create module for malicious sites protection (#5317)
Task/Issue URL: https://app.asana.com/0/0/1207943168535186/f ### Description ### Steps to test this PR _Feature 1_ - [ ] - [ ] ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)|
- Loading branch information
1 parent
c9b3f86
commit 928a82c
Showing
9 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
30 changes: 30 additions & 0 deletions
30
malicious-site-protection/malicious-site-protection-api/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2021 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
} | ||
|
||
apply from: "$rootProject.projectDir/gradle/android-library.gradle" | ||
|
||
android { | ||
namespace 'com.duckduckgo.malicioussiteprotection.api' | ||
} | ||
|
||
dependencies { | ||
implementation Kotlin.stdlib.jdk7 | ||
} |
19 changes: 19 additions & 0 deletions
19
...api/src/main/kotlin/com/duckduckgo/malicioussiteprotection/api/MaliciousSiteProtection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.malicioussiteprotection.api | ||
|
||
interface MaliciousSiteProtection |
76 changes: 76 additions & 0 deletions
76
malicious-site-protection/malicious-site-protection-impl/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2021 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
id 'com.squareup.anvil' | ||
id 'com.google.devtools.ksp' | ||
} | ||
|
||
apply from: "$rootProject.projectDir/gradle/android-library.gradle" | ||
|
||
dependencies { | ||
implementation project(":malicious-site-protection-api") | ||
|
||
anvil project(path: ':anvil-compiler') | ||
implementation project(path: ':anvil-annotations') | ||
implementation project(path: ':di') | ||
ksp AndroidX.room.compiler | ||
|
||
implementation KotlinX.coroutines.android | ||
implementation AndroidX.core.ktx | ||
implementation Google.dagger | ||
|
||
implementation project(path: ':common-utils') | ||
|
||
implementation "com.squareup.logcat:logcat:_" | ||
implementation JakeWharton.timber | ||
|
||
implementation Google.android.material | ||
|
||
testImplementation Testing.junit4 | ||
testImplementation "org.mockito.kotlin:mockito-kotlin:_" | ||
testImplementation project(path: ':common-test') | ||
testImplementation CashApp.turbine | ||
testImplementation Testing.robolectric | ||
testImplementation(KotlinX.coroutines.test) { | ||
// https://github.com/Kotlin/kotlinx.coroutines/issues/2023 | ||
// conflicts with mockito due to direct inclusion of byte buddy | ||
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug" | ||
} | ||
|
||
coreLibraryDesugaring Android.tools.desugarJdkLibs | ||
} | ||
|
||
android { | ||
namespace "com.duckduckgo.malicioussiteprotection.impl" | ||
anvil { | ||
generateDaggerFactories = true // default is false | ||
} | ||
lint { | ||
baseline file("lint-baseline.xml") | ||
} | ||
testOptions { | ||
unitTests { | ||
includeAndroidResources = true | ||
} | ||
} | ||
compileOptions { | ||
coreLibraryDesugaringEnabled = true | ||
} | ||
} | ||
|
4 changes: 4 additions & 0 deletions
4
malicious-site-protection/malicious-site-protection-impl/lint-baseline.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<issues format="6" by="lint 8.5.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.5.1)" variant="all" version="8.5.1"> | ||
|
||
</issues> |
38 changes: 38 additions & 0 deletions
38
...main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteProtectionFeature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.malicioussiteprotection.impl | ||
|
||
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.feature.toggles.api.Toggle | ||
|
||
@ContributesRemoteFeature( | ||
scope = AppScope::class, | ||
featureName = "maliciousSiteProtection", | ||
) | ||
/** | ||
* This is the class that represents the maliciousSiteProtection feature flags | ||
*/ | ||
interface MaliciousSiteProtectionFeature { | ||
/** | ||
* @return `true` when the remote config has the global "maliciousSiteProtection" feature flag enabled | ||
* If the remote feature is not present defaults to `false` | ||
*/ | ||
@Toggle.InternalAlwaysEnabled | ||
@Toggle.DefaultValue(false) | ||
fun self(): Toggle | ||
} |
65 changes: 65 additions & 0 deletions
65
...rc/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/RealMaliciousSiteProtection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.malicioussiteprotection.impl | ||
|
||
import com.duckduckgo.app.di.AppCoroutineScope | ||
import com.duckduckgo.app.di.IsMainProcess | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection | ||
import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import org.json.JSONObject | ||
|
||
@ContributesBinding(AppScope::class, MaliciousSiteProtection::class) | ||
@ContributesBinding(AppScope::class, PrivacyConfigCallbackPlugin::class) | ||
class RealMaliciousSiteProtection @Inject constructor( | ||
private val dispatchers: DispatcherProvider, | ||
private val maliciousSiteProtectionFeature: MaliciousSiteProtectionFeature, | ||
@IsMainProcess private val isMainProcess: Boolean, | ||
@AppCoroutineScope private val appCoroutineScope: CoroutineScope, | ||
) : MaliciousSiteProtection, PrivacyConfigCallbackPlugin { | ||
|
||
private var isFeatureEnabled = false | ||
private var hashPrefixUpdateFrequency = 20L | ||
private var filterSetUpdateFrequency = 720L | ||
|
||
init { | ||
if (isMainProcess) { | ||
loadToMemory() | ||
} | ||
} | ||
|
||
override fun onPrivacyConfigDownloaded() { | ||
loadToMemory() | ||
} | ||
|
||
private fun loadToMemory() { | ||
appCoroutineScope.launch(dispatchers.io()) { | ||
isFeatureEnabled = maliciousSiteProtectionFeature.self().isEnabled() | ||
maliciousSiteProtectionFeature.self().getSettings()?.let { | ||
JSONObject(it).let { settings -> | ||
hashPrefixUpdateFrequency = settings.getLong("hashPrefixUpdateFrequency") | ||
filterSetUpdateFrequency = settings.getLong("filterSetUpdateFrequency") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Feature Name | ||
|
||
In-browser feature to detect phishing and malware sites. | ||
|
||
## Who can help you better understand this feature? | ||
- ❓ Cris Barreiro | ||
|
||
## More information | ||
- [Asana: feature documentation](https://app.asana.com/0/1208717418466383/1199621914667995/f) |