[PM-18991] Create Rust<->C# OPAQUE bindings#104
Draft
dani-garcia wants to merge 92 commits intomainfrom
Draft
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…build to be used even in release mode
dani-garcia
commented
Mar 24, 2025
Member
Author
There was a problem hiding this comment.
We have some future plans to move this module to the bitwarden-crypto crate, which would considerably simplify the rust code for this crate. For now it lives here, though
|
Member
|
@dani-garcia I converted this to Draft since we will likely need to revisit this when we introduce OPAQUE. I'm cleaning up old PRs that have Justin assigned. Let me know if you disagree. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



🎟️ Tracking
📔 Objective
Created bindings in C# for the OPAQUE-KE rust crate.
This PR is entirely new additions, so it might be easier to review from a local clone. The added things are:
.github/workflows:pack-and-release.ymlto obtain the cross compiled librariesprerelease.ymlto use thepack-and-release.ymlfrom the branch instead of main, can be reverted before mergingstart-release.ymlto add another option to the selection in workflow_dispatch.vscode/settings.json: Added reference to the rust project so rust analyzer worksbitwarden-dotnet.sln: Added reference to the new C# projectextensions/Bitwarden.Opaque/rust: The rust project, which compiles to a library with a C APIsrc/opaque: Contains safe wrapper code around theopaque-kecrate. This crate uses a lot of type generics in it's API, which makes it fairly hard to wrap efficiently in FFI. In this case we're using a customOpaqueImpltrait to implement a sort of dynamic dispatch system on top of theopaque-kecrate, and using a macro to implement it. I the future this might be moved to thebitwarden_cryptocrate, and removed from here instead.src/ffi: Contains unsafe C FFI code, using the previous mentioned wrapper. Most of the unsafety is hidden behind customBufferandResponsetypes, which are C-like structs passed through FFI.src: The C# project, which links against the Rust C API and offers a safe more idiomatic C# APIBitwardenLibrary.cs: This is an internal module with the interface for the C API. It also contains theFFIHandlerclass, which contains utilities for safely converting the requests and responses back and forth, and freeing the memory as needed.Bitwarden[Client/Server].cs: This is the actual public API of the OPAQUE API, mostly just wrapping the C API inExecuteFFIFunction, and storing the results in aptly named structs. Note that we also provide a Client implementation even though we don't make use of it, because it simplifies the testing considerably.tests: A small test project to ensure the bindings work correctlyperf: A small benchmark to measure the performance of the implementation, run it withdotnet run --project extensions/Bitwarden.Opaque/perf/Bitwarden.Opaque.Benchmarks.csproj -c Release -p:BuildOpaqueLib=trueHow to make a new release
VersionPrefixand thePreReleaseVersionIterationinBitwarden.Opaque.csprojas needed.Start release workflowfrom your branch, selectBitwarden.Opaquerelease/Bitwaden.Opaque/x.y, it may open a version bump PR, you can merge it or ignore itPerform prerelaseaction has triggered automatically in the new branch. If not, push a commit to the branch to trigger it. This may also open a version bump PR, you can ignore it⏰ Reminders before review
🦮 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