Skip to content

[BEEEP/RFC] Add noise IPC crypto provider #348

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ keywords = ["bitwarden"]

# Define dependencies that are expected to be consistent across all crates
[workspace.dependencies]
bitwarden = { path = "crates/bitwarden", version = "=1.0.0" }
bitwarden-api-api = { path = "crates/bitwarden-api-api", version = "=1.0.0" }
bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=1.0.0" }
bitwarden-cli = { path = "crates/bitwarden-cli", version = "=1.0.0" }
Expand All @@ -33,7 +32,6 @@ bitwarden-ipc = { path = "crates/bitwarden-ipc", version = "=1.0.0" }
bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
bitwarden-state = { path = "crates/bitwarden-state", version = "=1.0.0" }
bitwarden-threading = { path = "crates/bitwarden-threading", version = "=1.0.0" }
bitwarden-sm = { path = "bitwarden_license/bitwarden-sm", version = "=1.0.0" }
bitwarden-ssh = { path = "crates/bitwarden-ssh", version = "=1.0.0" }
bitwarden-uuid = { path = "crates/bitwarden-uuid", version = "=1.0.0" }
bitwarden-uuid-macro = { path = "crates/bitwarden-uuid-macro", version = "=1.0.0" }
Expand Down
4 changes: 4 additions & 0 deletions crates/bitwarden-ipc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ wasm = [
async-trait = { workspace = true }
bitwarden-error = { workspace = true }
bitwarden-threading = { workspace = true }
ciborium = "0.2.2"
erased-serde = ">=0.4.6, <0.5"
hex = "0.4.3"
js-sys = { workspace = true, optional = true }
log = { workspace = true }
serde = { workspace = true }
serde_bytes = "0.11.17"
serde_json = { workspace = true }
snow = "0.9.6"
thiserror = { workspace = true }
tokio = { features = ["sync", "time", "rt"], workspace = true }
tsify-next = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-ipc/src/crypto_provider/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod noise;
31 changes: 31 additions & 0 deletions crates/bitwarden-ipc/src/crypto_provider/noise/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use thiserror::Error;

#[derive(Debug, Error)]
pub(super) enum HandshakeError {
#[error("Invalid cipher suite, {0}")]
InvalidCipherSuite(String),
#[error("Crypto initialization failed")]
CryptoInitializationFailed,
#[error("Invalid handshake start message")]
InvalidHandshakeStart,
#[error("Invalid handshake finish message")]
InvalidHandshakeFinish,

#[error("Failed to send message")]
SendFailed,
#[error("Failed to receive message")]
ReceiveFailed,
}

#[derive(Debug, Error)]
pub(super) enum PayloadError {
#[error("Crypto uninitialized")]
CryptoUninitialized,
#[error("Failed to parse payload")]
ParseFailed,
#[error("Decryption failed")]
DecryptionFailed,

#[error("Failed to send payload")]
SendFailed,
}
29 changes: 29 additions & 0 deletions crates/bitwarden-ipc/src/crypto_provider/noise/messages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use serde::{Deserialize, Serialize};
use serde_bytes::ByteBuf;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub(super) enum BitwardenNoiseFrame {
HandshakeStart {
ciphersuite: String,
payload: ByteBuf,
},
HandshakeFinish {
payload: ByteBuf,
},
Payload {
payload: ByteBuf,
},
}

#[allow(unused)]
impl BitwardenNoiseFrame {
pub(super) fn to_cbor(&self) -> Vec<u8> {
let mut buffer = Vec::new();
ciborium::into_writer(self, &mut buffer).expect("Ciborium serialization should not fail");
buffer
}

pub(super) fn from_cbor(buffer: &[u8]) -> Result<Self, ()> {
ciborium::from_reader(buffer).map_err(|_| ())
}
}
3 changes: 3 additions & 0 deletions crates/bitwarden-ipc/src/crypto_provider/noise/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod error;
mod messages;
mod protocol;
Loading
Loading