Skip to content
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

Merged
merged 5 commits into from
Oct 3, 2024

Conversation

mpbw2
Copy link
Contributor

@mpbw2 mpbw2 commented Oct 1, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-9363

📔 Objective

Disable cipher key encryption in SDK if server version < 2024.2.0

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
Contributor

github-actions bot commented Oct 1, 2024

Logo
Checkmarx One – Scan Summary & Detailsf025e10a-e28a-45d2-9a31-9d389fd1a82e

No New Or Fixed Issues Found

@@ -16,7 +17,8 @@ class FeatureFlagManagerImpl(
) : FeatureFlagManager {

override val sdkFeatureFlags: Map<String, Boolean>
get() = mapOf(CIPHER_KEY_ENCRYPTION_KEY to true)
get() = mapOf(CIPHER_KEY_ENCRYPTION_KEY to
isServerVersionAtLeast(serverConfigRepository, "2024.2.0"))
Copy link
Contributor

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?

/**
* Checks if the server version is greater than another provided version, returns true if it is.
*/
fun isServerVersionAtLeast(serverConfig: ServerConfigRepository, version: String): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 Can we change serverConfig argument to type ServerConfig? or possibly even serverVersion: String? instead of passing the repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up using ServerConfig? instead of another string since I kept second guessing myself on which string was which regardless of the names

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 88.83%. Comparing base (b3e885b) to head (f47edb3).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
...bitwarden/data/platform/util/ServerVersionUtils.kt 52.63% 1 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4006      +/-   ##
==========================================
- Coverage   88.85%   88.83%   -0.02%     
==========================================
  Files         425      426       +1     
  Lines       35050    35073      +23     
  Branches     5138     5149      +11     
==========================================
+ Hits        31144    31158      +14     
- Misses       2112     2113       +1     
- Partials     1794     1802       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

get() = mapOf(
CIPHER_KEY_ENCRYPTION_KEY to
isServerVersionAtLeast(
serverConfigRepository.getLocalServerConfig(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just access it via the stateFlow directly?

serverConfigRepository.serverConfigStateFlow.value

val otherPart = otherVersionParts.getOrNull(i)?.toIntOrNull() ?: 0

if (serverPart > otherPart) {
return true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we lift the return

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, missed that

val otherVersionParts = getVersionComponents(version)

if (serverVersionParts == null || otherVersionParts == null) {
return false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test

}
}

return true // Versions are equal
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

get() = mapOf(
CIPHER_KEY_ENCRYPTION_KEY to
isServerVersionAtLeast(
serverConfigRepository.serverConfigStateFlow.value,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

/**
* Checks if the server version is greater than another provided version, returns true if it is.
*/
fun isServerVersionAtLeast(serverConfig: ServerConfig?, version: String?): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last question, why would the version ever be null?

Copy link
Contributor Author

@mpbw2 mpbw2 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be, but I felt weird skipping the null check further down just to satisfy the IDE so I made it nullable. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make version nonnull and just do the empty check

@mpbw2 mpbw2 merged commit 1d84479 into main Oct 3, 2024
7 checks passed
@mpbw2 mpbw2 deleted the pm-9363/cipher-key-server-version branch October 3, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants