-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PM-9363] Disable cipher key encryption for older server versions #4006
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.x8bit.bitwarden.data.platform.util | ||
|
||
import com.x8bit.bitwarden.data.platform.repository.ServerConfigRepository | ||
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: ServerConfigRepository, version: String): Boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐จ Can we change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up using |
||
val serverVersion = serverConfig | ||
.getLocalServerConfig() | ||
?.serverData | ||
?.version | ||
|
||
val serverVersionParts = getVersionComponents(serverVersion) | ||
val otherVersionParts = getVersionComponents(version) | ||
|
||
if (serverVersionParts == null || otherVersionParts == null) { | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test |
||
} | ||
|
||
for (i in serverVersionParts.indices) { | ||
val serverPart = serverVersionParts.getOrNull(i)?.toIntOrNull() ?: 0 | ||
val otherPart = otherVersionParts.getOrNull(i)?.toIntOrNull() ?: 0 | ||
|
||
if (serverPart > otherPart) { | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we lift the return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to walk through the entire loop to know if the version parts are the same. Added a comment for clarity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, missed that |
||
} else if (serverPart < otherPart) { | ||
return false | ||
} | ||
} | ||
|
||
return true // Versions are equal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment should be above the return not on the same line. Can we also add a test for this case |
||
} | ||
|
||
/** | ||
* 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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
โ๏ธ Making "2024.2.0" a constant with a descriptive name would be helpful. "CIPHER_KEY_ENC_MIN_SERVER_VERSION" maybe?