Skip to content

Commit

Permalink
fix: Use Windows user agent on Android to please Cloudflare bot dete…
Browse files Browse the repository at this point in the history
…ction rules AChep#324
  • Loading branch information
AChep committed Jul 2, 2024
1 parent 3f81c44 commit c2a7b90
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ package com.artemchep.keyguard.platform.util
import com.artemchep.keyguard.platform.Platform

expect val Platform.userAgent: String

// Taken from:
// https://releases.electronjs.org/releases/stable
private const val CHROME_VERSION = "126.0.6478.114"

// Seems like desktop clients always use the Windows user-agents for
// privacy reasons.
val Platform.defaultUserAgent: String
get() = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/$CHROME_VERSION Safari/537.36"

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.artemchep.keyguard.common.util.int
import com.artemchep.keyguard.core.store.bitwarden.BitwardenToken
import com.artemchep.keyguard.platform.CurrentPlatform
import com.artemchep.keyguard.platform.Platform
import com.artemchep.keyguard.platform.util.defaultUserAgent
import com.artemchep.keyguard.platform.util.userAgent
import com.artemchep.keyguard.provider.bitwarden.ServerEnv
import com.artemchep.keyguard.provider.bitwarden.ServerTwoFactorToken
Expand Down Expand Up @@ -76,7 +77,7 @@ data class BitwardenPersona(
clientVersion = CLIENT_VERSION,
deviceType = "8",
deviceName = "linux",
userAgent = userAgent,
userAgent = defaultUserAgent,
)

private fun Platform.Desktop.MacOS.bitwardenPersona(
Expand All @@ -86,7 +87,7 @@ data class BitwardenPersona(
clientVersion = CLIENT_VERSION,
deviceType = "7",
deviceName = "macos",
userAgent = userAgent,
userAgent = defaultUserAgent,
)

private fun Platform.Desktop.Windows.bitwardenPersona(
Expand All @@ -96,7 +97,7 @@ data class BitwardenPersona(
clientVersion = CLIENT_VERSION,
deviceType = "6",
deviceName = "windows",
userAgent = userAgent,
userAgent = defaultUserAgent,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ import com.artemchep.keyguard.crypto.CryptoGeneratorJvm
import com.artemchep.keyguard.crypto.FileEncryptorImpl
import com.artemchep.keyguard.platform.CurrentPlatform
import com.artemchep.keyguard.platform.util.isRelease
import com.artemchep.keyguard.platform.util.userAgent
import com.artemchep.keyguard.provider.bitwarden.api.BitwardenPersona
import com.artemchep.keyguard.provider.bitwarden.usecase.CipherUrlCheckImpl
import com.artemchep.keyguard.provider.bitwarden.usecase.CipherUrlDuplicateCheckImpl
import io.ktor.client.HttpClient
Expand Down Expand Up @@ -1295,7 +1295,8 @@ fun globalModuleJvm() = DI.Module(
val okHttpClient: OkHttpClient = instance()
HttpClient(OkHttp) {
install(UserAgent) {
agent = CurrentPlatform.userAgent
agent = BitwardenPersona.of(CurrentPlatform)
.userAgent
}
engine {
preconfigured = okHttpClient
Expand Down

0 comments on commit c2a7b90

Please sign in to comment.