generated from bitwarden/template
-
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
Draft
dani-garcia
wants to merge
92
commits into
main
Choose a base branch
from
innovation/opaque/rust
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
60ffccd
Create initial Rust<->OPAQUE bindings
dani-garcia fd6fc5d
Add project to SLN
dani-garcia 450b5e0
Also load Opaque tests
dani-garcia 9a5b8f6
Build Rust on csproj and CI
dani-garcia 8ab505c
Debug file
dani-garcia cf7e77a
Remove debug file
dani-garcia c15ffe7
Some small build improvements
dani-garcia 2643fd6
Test cross compile in CI
dani-garcia 053bcc4
Temp fix tests
dani-garcia 691c9a7
Fix wrong path and ignore first build error
dani-garcia d3be32b
Enable LTO
dani-garcia b766361
Force build module directly
dani-garcia d3689e9
Rename invalid artifact names
dani-garcia 2bce8e4
Remove zig
dani-garcia c9524bd
Just build dynlibs
dani-garcia 2888c3b
Try cross
dani-garcia a40959b
Build ARM and fix linux arm64 path
dani-garcia 6a8d8b6
Only run cross platform from other workflows
dani-garcia d2aa864
Only upload opaque
dani-garcia 049e9bf
More ARM builds
dani-garcia cee3ba8
Ignore missing files
dani-garcia dd3cb31
Fix armv6
dani-garcia bacd05c
Fix dotnet test not building binaries
dani-garcia c12061d
Remove workaround
dani-garcia c5c5268
Collect all bindings in one artifact
dani-garcia fd8fa35
Fix upload
dani-garcia 646739b
Use full path
dani-garcia 3c9a39b
upload doesn't support globs
dani-garcia 7a80f05
Debug
dani-garcia 650b7e0
Path
dani-garcia b9bdf2f
Remove debug logs
dani-garcia 9381bd7
Remove copy
dani-garcia b5908d2
Try multiple paths
dani-garcia 0fffd25
Simplify library copies
dani-garcia 8205bc2
Use matrix to download artifacts
dani-garcia 749829b
Revert "Use matrix to download artifacts"
dani-garcia 88a6f39
Use dotnet RIDs for artifacts
dani-garcia 744c3d9
Download all artifacts in one go
dani-garcia a241a22
Move files to the correct path
dani-garcia e4a716a
Update workflows
dani-garcia 194dd03
Make rust-analyzer load correctly
dani-garcia c82b0c6
Docs & better code organization
dani-garcia a7aef23
Implement dynamic dispatch for opaque crate, add server setup param
dani-garcia 64d9977
Implement login
dani-garcia 68146e2
Implement login
dani-garcia c217c7f
Extract KSF trait
dani-garcia f0e8d17
Add possible idea for a future macro so I don't forget
dani-garcia bdca321
Simplify code a bit with some util trait
dani-garcia 218d26c
Fix comment
dani-garcia b2d8e89
Fix package path on debug mode
dani-garcia 5142a6c
Simplify FFI parsing with a macro, fail on null buffers, properly pasโฆ
dani-garcia f6a24e3
Fix some naming and serializing
dani-garcia e4d674b
Fix lint
dani-garcia 8f57dd5
Add session key equal test
dani-garcia e0ee86b
OPAQUE -> Opaque
dani-garcia ecdf967
Update release workflow
dani-garcia 66687c3
Rename files
dani-garcia 3f14fb2
Fix suffix
dani-garcia e7414db
Bump Bitwarden.Opaque version to 0.0.1-beta.2
invalid-email-address b34c5b0
Improve how the type conversions are done and add missing docs
dani-garcia 8dd4d1e
Optimize rust build, try to build windows arm
dani-garcia eff7d46
Fix condition
dani-garcia 4a5ce35
Try native build
dani-garcia 6854737
Update pack action to cross build libs
dani-garcia 3a2009e
Bump Bitwarden.Opaque version to 0.1.0 (#107)
github-actions[bot] e47cec7
Temp fix for prerelease
dani-garcia abdb9f2
Add seeded registration
quexten 74135c7
Merge branch 'innovation/opaque/rust' of github.com:bitwarden/dotnet-โฆ
quexten 26f3f09
Fix build
quexten d7fbc2c
Replace osrng
quexten 7b7f76f
Fix number of return values, make RNG non-optional and return a resulโฆ
dani-garcia cf4d77e
Use mutable functions in trait to avoid refcell
dani-garcia 6bc9f99
Merge branch 'innovation-opaque-seeded-generation' into innovation/opโฆ
dani-garcia 11d336a
Try to catch panics at the FFI layer if possible
dani-garcia 69adec5
Use opaque_ke Identity instead
dani-garcia 41dc822
Avoid cloning Rng
dani-garcia 95c5808
Implement dyn dispatch for Argon and identity
dani-garcia 72c5fe5
Update safety checks and comments
dani-garcia 001d441
Missed doc
dani-garcia 4094158
Remove unused deps and force unwind
dani-garcia dcb0e2d
Update version
dani-garcia 8a42128
Add FFI panic, tested locally with miri
dani-garcia 0596a2f
Restore build/test/scan.yml
dani-garcia 5cdbab3
Remove unused json converter
dani-garcia eab7685
Reduce visibilities
dani-garcia 79b091a
Simplify response creation
dani-garcia 03202fd
Improve rust response handling
dani-garcia 6d6ade8
Fix lints, simplify macro, add toolchain
dani-garcia c684531
Merge branch 'main' into innovation/opaque/rust
dani-garcia 49dee36
Expand tests, always build native in release mode, also allow csproj โฆ
dani-garcia b0de1de
Add simple benchmarks
dani-garcia 1990a32
Formatting
dani-garcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
name: Build Rust Cross Platform | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
build_rust: | ||
name: Build for ${{ matrix.settings.os }} ${{ matrix.settings.target }} | ||
runs-on: ${{ matrix.settings.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
settings: | ||
- os: macos-13 | ||
target: x86_64-apple-darwin | ||
dotnet_rid: osx-x64 | ||
- os: macos-13 | ||
target: aarch64-apple-darwin | ||
dotnet_rid: osx-arm64 | ||
- os: windows-2022 | ||
target: i686-pc-windows-msvc | ||
dotnet_rid: win-x86 | ||
- os: windows-2022 | ||
target: x86_64-pc-windows-msvc | ||
dotnet_rid: win-x64 | ||
- os: windows-2022 | ||
target: aarch64-pc-windows-msvc | ||
dotnet_rid: win-arm64 | ||
# caution: updating the linux runner OS version for GNU | ||
# targets will likely break the library for older OS versions. | ||
# prefer using oldest supported runner for for these targets | ||
- os: ubuntu-22.04 | ||
target: x86_64-unknown-linux-gnu | ||
dotnet_rid: linux-x64 | ||
- os: ubuntu-22.04 | ||
target: aarch64-unknown-linux-gnu | ||
dotnet_rid: linux-arm64 | ||
use_cross: true | ||
- os: ubuntu-22.04 | ||
target: armv7-unknown-linux-gnueabihf | ||
dotnet_rid: linux-arm | ||
use_cross: true | ||
- os: ubuntu-22.04 | ||
target: arm-unknown-linux-gnueabihf | ||
dotnet_rid: linux-armv6 | ||
use_cross: true | ||
- os: ubuntu-22.04 | ||
target: armv5te-unknown-linux-gnueabi | ||
dotnet_rid: linux-armel | ||
use_cross: true | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Install rust | ||
uses: dtolnay/rust-toolchain@c5a29ddb4d9d194e7c84ec8c3fba61b1c31fee8c # stable | ||
with: | ||
toolchain: stable | ||
|
||
- name: Cache cargo registry | ||
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5 | ||
|
||
- name: Install cross | ||
if: ${{ startsWith(matrix.settings.os, 'ubuntu') && !startsWith(matrix.settings.target, 'x86_64') }} | ||
run: cargo install cross --git https://github.com/cross-rs/cross --rev 36c0d7810ddde073f603c82d896c2a6c886ff7a4 | ||
|
||
- name: Add build architecture | ||
run: rustup target add ${{ matrix.settings.target }} | ||
|
||
# Build Rust natively | ||
- name: Build Rust native for - ${{ matrix.settings.target }} | ||
if: ${{ matrix.settings.use_cross != true }} | ||
env: | ||
RUSTFLAGS: "-D warnings" | ||
MACOSX_DEPLOYMENT_TARGET: "10.14" # allows using new macos runner versions while still supporting older systems | ||
run: cargo build --target ${{ matrix.settings.target }} --release | ||
working-directory: extensions/Bitwarden.Opaque/rust | ||
|
||
# Build Rust using cross | ||
- name: Build Rust cross for - ${{ matrix.settings.target }} | ||
if: ${{ matrix.settings.use_cross == true }} | ||
env: | ||
RUSTFLAGS: "-D warnings" | ||
run: cross build --target ${{ matrix.settings.target }} --release | ||
working-directory: extensions/Bitwarden.Opaque/rust | ||
|
||
- name: Upload Artifact | ||
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 | ||
with: | ||
name: libopaque_ke_binding_files-${{ matrix.settings.dotnet_rid }} | ||
# We only need these until the next step, so delete them as soon as possible | ||
retention-days: 1 | ||
if-no-files-found: error | ||
path: | | ||
extensions/Bitwarden.Opaque/rust/target/${{ matrix.settings.target }}/release/opaque_ke_binding.dll | ||
extensions/Bitwarden.Opaque/rust/target/${{ matrix.settings.target }}/release/libopaque_ke_binding.so | ||
extensions/Bitwarden.Opaque/rust/target/${{ matrix.settings.target }}/release/libopaque_ke_binding.dylib | ||
|
||
collect_artifacts: | ||
name: Collect and Upload All Artifacts | ||
runs-on: ubuntu-22.04 | ||
needs: build_rust | ||
steps: | ||
- name: Download all artifacts | ||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | ||
with: | ||
pattern: libopaque_ke_binding_files-* | ||
path: downloaded_runtimes/ | ||
|
||
- name: Move files to the correct directory | ||
run: | | ||
for file in downloaded_runtimes/libopaque_ke_binding_files-*; do | ||
echo "Processing $file" | ||
platform="${file#downloaded_runtimes/libopaque_ke_binding_files-}" | ||
echo "Platform: $platform" | ||
mkdir -p runtimes/${platform}/native | ||
mv $file/* runtimes/${platform}/native | ||
done | ||
|
||
- name: Upload Combined Artifact | ||
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 | ||
with: | ||
name: libopaque_ke_binding_all_files | ||
if-no-files-found: error | ||
path: | | ||
runtimes/**/* |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": ["extensions/Bitwarden.Opaque/rust/Cargo.toml"], | ||
} |
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
19 changes: 19 additions & 0 deletions
19
extensions/Bitwarden.Opaque/perf/Bitwarden.Opaque.Benchmarks.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
๏ปฟ<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Bitwarden.Opaque.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Bitwarden.Opaque.Benchmarks; | ||
|
||
// dotnet run --project extensions/Bitwarden.Opaque/perf/Bitwarden.Opaque.Benchmarks.csproj -c Release -p:BuildOpaqueLib=true | ||
|
||
[MemoryDiagnoser] | ||
public class OpaqueBench | ||
{ | ||
public BitwardenOpaqueServer server = new(); | ||
public BitwardenOpaqueClient client = new(); | ||
public CipherConfiguration config = CipherConfiguration.Default; | ||
|
||
public string username = "demo_username"; | ||
public string password = "demo_password"; | ||
|
||
|
||
public byte[] serverSetup = null!; | ||
public byte[] serverRegistration = null!; | ||
|
||
public byte[] clientRegistrationRequest = null!; | ||
public byte[] clientRegistrationUpload = null!; | ||
|
||
public byte[] clientLoginCredentialRequest = null!; | ||
public byte[] serverLoginState = null!; | ||
public byte[] clientLoginCredentialFinalization = null!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
// Use the complete benchmarks to extract the data for the partial benchmarks | ||
var registration = CompleteRegistration(); | ||
serverSetup = registration.Item1; | ||
serverRegistration = registration.Item2; | ||
clientRegistrationRequest = registration.Item3; | ||
clientRegistrationUpload = registration.Item4; | ||
|
||
var login = CompleteLogin(); | ||
clientLoginCredentialRequest = login.Item1; | ||
serverLoginState = login.Item2; | ||
clientLoginCredentialFinalization = login.Item3; | ||
} | ||
|
||
[Benchmark] | ||
public (byte[], byte[]) SeededFakeRegistration() | ||
{ | ||
var seed = new byte[32]; | ||
return server.SeededFakeRegistration(seed); | ||
} | ||
|
||
[Benchmark] | ||
public (byte[], byte[], byte[], byte[]) CompleteRegistration() | ||
{ | ||
var clientRegisterStartResult = client.StartRegistration(config, password); | ||
var serverRegisterStartResult = server.StartRegistration(config, null, clientRegisterStartResult.registrationRequest, username); | ||
var clientRegisterFinishResult = client.FinishRegistration(config, clientRegisterStartResult.state, serverRegisterStartResult.registrationResponse, password); | ||
var serverRegisterFinishResult = server.FinishRegistration(config, clientRegisterFinishResult.registrationUpload); | ||
return ( | ||
serverRegisterStartResult.serverSetup, | ||
serverRegisterFinishResult.serverRegistration, | ||
clientRegisterStartResult.registrationRequest, | ||
clientRegisterFinishResult.registrationUpload | ||
); | ||
} | ||
|
||
[Benchmark] | ||
public (byte[], byte[], byte[], byte[]) CompleteLogin() | ||
{ | ||
var clientLoginStartResult = client.StartLogin(config, password); | ||
var serverLoginStartResult = server.StartLogin(config, serverSetup, serverRegistration, clientLoginStartResult.credentialRequest, username); | ||
var clientLoginFinishResult = client.FinishLogin(config, clientLoginStartResult.state, serverLoginStartResult.credentialResponse, password); | ||
var serverLoginFinishResult = server.FinishLogin(config, serverLoginStartResult.state, clientLoginFinishResult.credentialFinalization); | ||
return ( | ||
clientLoginStartResult.credentialRequest, | ||
serverLoginStartResult.state, | ||
clientLoginFinishResult.credentialFinalization, | ||
serverLoginFinishResult.sessionKey | ||
); | ||
} | ||
|
||
[Benchmark] | ||
public (byte[], byte[]) StartServerRegistration() | ||
{ | ||
var result = server.StartRegistration(config, null, clientRegistrationRequest, username); | ||
return (result.registrationResponse, result.serverSetup); | ||
} | ||
|
||
[Benchmark] | ||
public byte[] FinishServerRegistration() | ||
{ | ||
var result = server.FinishRegistration(config, clientRegistrationUpload); | ||
return result.serverRegistration; | ||
} | ||
|
||
|
||
[Benchmark] | ||
public (byte[], byte[]) StartServerLogin() | ||
{ | ||
var result = server.StartLogin(config, serverSetup, serverRegistration, clientLoginCredentialRequest, username); | ||
return (result.credentialResponse, result.state); | ||
} | ||
|
||
[Benchmark] | ||
public byte[] FinishServerLogin() | ||
{ | ||
var result = server.FinishLogin(config, serverLoginState, clientLoginCredentialFinalization); | ||
return result.sessionKey; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Reflection; | ||
using BenchmarkDotNet.Running; | ||
|
||
BenchmarkRunner.Run(Assembly.GetExecutingAssembly()); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
dist |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
I'm using this to ensure my modified pack-and-release workflow gets run instead of the one in main, we can revert this before merging.