-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-9363] Disable cipher key encryption for older server versions (#4006
- Loading branch information
Showing
3 changed files
with
108 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/x8bit/bitwarden/data/platform/util/ServerVersionUtils.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,51 @@ | ||
package com.x8bit.bitwarden.data.platform.util | ||
|
||
import com.x8bit.bitwarden.data.platform.datasource.disk.model.ServerConfig | ||
import kotlin.text.split | ||
import kotlin.text.toIntOrNull | ||
|
||
private const val VERSION_SEPARATOR = "." | ||
private const val SUFFIX_SEPARATOR = "-" | ||
|
||
/** | ||
* Checks if the server version is greater than another provided version, returns true if it is. | ||
*/ | ||
fun isServerVersionAtLeast(serverConfig: ServerConfig?, version: String): Boolean { | ||
val serverVersion = serverConfig | ||
?.serverData | ||
?.version | ||
|
||
if (serverVersion.isNullOrEmpty() || version.isEmpty()) { | ||
return false | ||
} | ||
|
||
val serverVersionParts = getVersionComponents(serverVersion) | ||
val otherVersionParts = getVersionComponents(version) | ||
|
||
if (serverVersionParts.isNullOrEmpty() || otherVersionParts.isNullOrEmpty()) { | ||
return false | ||
} | ||
|
||
// Must iterate through all indices to establish if versions are equal | ||
for (i in serverVersionParts.indices) { | ||
val serverPart = serverVersionParts.getOrNull(i)?.toIntOrNull() ?: 0 | ||
val otherPart = otherVersionParts.getOrNull(i)?.toIntOrNull() ?: 0 | ||
|
||
if (serverPart > otherPart) { | ||
return true | ||
} else if (serverPart < otherPart) { | ||
return false | ||
} | ||
} | ||
|
||
// Versions are equal | ||
return true | ||
} | ||
|
||
/** | ||
* Extracts the version components from a version string, disregarding any suffixes. | ||
*/ | ||
private fun getVersionComponents(version: String?): List<String>? { | ||
val versionComponents = version?.split(SUFFIX_SEPARATOR)?.first() | ||
return versionComponents?.split(VERSION_SEPARATOR) | ||
} |
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