aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-15 22:08:57 -0700
committerAllan Wang <me@allanwang.ca>2019-08-15 22:08:57 -0700
commit39d07d946b753f197d200fa07792670e37435a95 (patch)
tree56444cfe379a491e14db26608dd7c4572aedad55 /app/src/main/kotlin/com
parentf12762c4175e37a6f887ca17a07ddb4fc7508849 (diff)
parente47d5d47c0997b9a696f4f8881f4a057e2a5f934 (diff)
downloadfrost-39d07d946b753f197d200fa07792670e37435a95.tar.gz
frost-39d07d946b753f197d200fa07792670e37435a95.tar.bz2
frost-39d07d946b753f197d200fa07792670e37435a95.zip
Merge obfuscator
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt37
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt7
3 files changed, 42 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
index 40e3827c..3416c420 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
@@ -17,9 +17,11 @@
package com.pitchedapps.frost.injectors
import android.webkit.WebView
+import androidx.annotation.VisibleForTesting
+import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.web.FrostWebViewClient
import org.apache.commons.text.StringEscapeUtils
-import java.util.Locale
+import kotlin.random.Random
class JsBuilder {
private val css = StringBuilder()
@@ -38,7 +40,7 @@ class JsBuilder {
}
fun single(tag: String): JsBuilder {
- this.tag = "_frost_${tag.toLowerCase(Locale.CANADA)}"
+ this.tag = TagObfuscator.obfuscateTag(tag)
return this
}
@@ -107,3 +109,34 @@ class JsInjector(val function: String) : InjectorContract {
override fun inject(webView: WebView) =
webView.evaluateJavascript(function, null)
}
+
+/**
+ * Helper object to obfuscate window tags for JS injection.
+ */
+@VisibleForTesting
+internal object TagObfuscator {
+
+ fun obfuscateTag(tag: String): String {
+ val rnd = Random(tag.hashCode() + salt)
+ val obfuscated = buildString {
+ append(prefix)
+ append('_')
+ appendRandomChars(rnd, 16)
+ }
+ L.v { "TagObfuscator: Obfuscating tag '$tag' to '$obfuscated'" }
+ return obfuscated
+ }
+
+ private val salt: Long = System.currentTimeMillis()
+
+ private val prefix: String by lazy {
+ val rnd = Random(System.currentTimeMillis())
+ buildString { appendRandomChars(rnd, 8) }
+ }
+
+ private fun Appendable.appendRandomChars(random: Random, count: Int) {
+ for (i in 1..count) {
+ append('a' + random.nextInt(26))
+ }
+ }
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
index 1ab53a56..ba5b839b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
@@ -83,13 +83,6 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = {
descRes = R.string.exit_confirmation_desc
}
- checkbox(R.string.web_only, Prefs::webOnly, {
- Prefs.webOnly = it
- shouldRestartMain()
- }) {
- descRes = R.string.web_only_desc
- }
-
checkbox(R.string.analytics, Prefs::analytics, { Prefs.analytics = it }) {
descRes = R.string.analytics_desc
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt
index 7aac7526..d0963665 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt
@@ -43,6 +43,13 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = {
// Experimental content starts here ------------------
+ checkbox(R.string.web_only, Prefs::webOnly, {
+ Prefs.webOnly = it
+ shouldRestartMain()
+ }) {
+ descRes = R.string.web_only_desc
+ }
+
// Experimental content ends here --------------------
checkbox(R.string.verbose_logging, Prefs::verboseLogging, {