-
Notifications
You must be signed in to change notification settings - Fork 3
[PM-18991] Create Rust<->C# OPAQUE bindings #104
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
base: main
Are you sure you want to change the base?
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
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.
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
|
@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. |
🎟️ 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.yml
to obtain the cross compiled librariesprerelease.yml
to use thepack-and-release.yml
from the branch instead of main, can be reverted before mergingstart-release.yml
to 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-ke
crate. 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 customOpaqueImpl
trait to implement a sort of dynamic dispatch system on top of theopaque-ke
crate, and using a macro to implement it. I the future this might be moved to thebitwarden_crypto
crate, and removed from here instead.src/ffi
: Contains unsafe C FFI code, using the previous mentioned wrapper. Most of the unsafety is hidden behind customBuffer
andResponse
types, 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 theFFIHandler
class, 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=true
How to make a new release
VersionPrefix
and thePreReleaseVersionIteration
inBitwarden.Opaque.csproj
as needed.Start release workflow
from your branch, selectBitwarden.Opaque
release/Bitwaden.Opaque/x.y
, it may open a version bump PR, you can merge it or ignore itPerform prerelase
action 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