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

Experiment with ipc framework #77

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
4 changes: 4 additions & 0 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions crates/bitwarden-ipc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "bitwarden-ipc"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
homepage.workspace = true
repository.workspace = true
license-file.workspace = true
keywords.workspace = true

[dependencies]

[lints]
workspace = true
26 changes: 26 additions & 0 deletions crates/bitwarden-ipc/src/channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::rc::Rc;

use crate::{link::Link, providers::CryptoProvider};

/// An end-to-end channel between two IPC endpoints, possibly traversing multiple links across processes.
/// A channel is a stateful object that can provide a secure and trusted communication path between two endpoints.
pub struct Channel<C>
where
C: CryptoProvider,
{
link: Box<dyn Link>,
crypto: Rc<C>,
session: C::Session,
}

impl<C> Channel<C>
where
C: CryptoProvider,
{
fn send(&self, data: &[u8]) {
todo!()

Check warning on line 21 in crates/bitwarden-ipc/src/channel.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/channel.rs#L20-L21

Added lines #L20 - L21 were not covered by tests
}
fn receive(&self) -> Vec<u8> {
todo!()

Check warning on line 24 in crates/bitwarden-ipc/src/channel.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/channel.rs#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}
6 changes: 6 additions & 0 deletions crates/bitwarden-ipc/src/destination.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Destination {
Web,
Browser,
Desktop,
}
8 changes: 8 additions & 0 deletions crates/bitwarden-ipc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod channel;
mod destination;
mod link;
mod manager;
mod providers;
mod proxy;

pub use manager::Manager;
11 changes: 11 additions & 0 deletions crates/bitwarden-ipc/src/link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::destination::Destination;

/// A wrapper around a "physical" connection (e.g. a TCP connection) between two IPC endpoints.
/// This is a low-level struct that is used to send and receive data between two endpoints
/// it is not meant to be used directly by consumers of this library.
pub trait Link {
fn send(&self, data: &[u8]);
fn receive(&self) -> Vec<u8>;

fn available_destinations(&self) -> Vec<Destination>;
}
28 changes: 28 additions & 0 deletions crates/bitwarden-ipc/src/manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::rc::Rc;

use crate::{destination::Destination, link::Link, providers::CryptoProvider};

pub struct Manager<C>
where
C: CryptoProvider,
{
crypto: Rc<C>,
links: Vec<Box<dyn Link>>,
}

impl<C> Manager<C>
where
C: CryptoProvider,
{
pub fn new() -> Self {
todo!()

Check warning on line 18 in crates/bitwarden-ipc/src/manager.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/manager.rs#L17-L18

Added lines #L17 - L18 were not covered by tests
}

pub fn register_link(&mut self) {
todo!()

Check warning on line 22 in crates/bitwarden-ipc/src/manager.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/manager.rs#L21-L22

Added lines #L21 - L22 were not covered by tests
}

pub fn get_channel(&mut self, destination: Destination) {
todo!()

Check warning on line 26 in crates/bitwarden-ipc/src/manager.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/manager.rs#L25-L26

Added lines #L25 - L26 were not covered by tests
}
}
8 changes: 8 additions & 0 deletions crates/bitwarden-ipc/src/providers/crypto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub trait CryptoProvider {
type Session;

fn establish_session(&self) -> Self::Session;

fn encrypt(&self, data: &[u8]) -> Vec<u8>;
fn decrypt(&self, data: &[u8]) -> Vec<u8>;
}
3 changes: 3 additions & 0 deletions crates/bitwarden-ipc/src/providers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod crypto;

pub use crypto::CryptoProvider;
16 changes: 16 additions & 0 deletions crates/bitwarden-ipc/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::link::Link;

pub struct Proxy {
links: (Box<dyn Link>, Box<dyn Link>),
}

impl Proxy {
pub fn new(links: (Box<dyn Link>, Box<dyn Link>)) -> Self {
Self { links }
}

Check warning on line 10 in crates/bitwarden-ipc/src/proxy.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/proxy.rs#L8-L10

Added lines #L8 - L10 were not covered by tests

pub fn start(&self) {
let data = self.links.0.receive();
self.links.1.send(&data);
}

Check warning on line 15 in crates/bitwarden-ipc/src/proxy.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-ipc/src/proxy.rs#L12-L15

Added lines #L12 - L15 were not covered by tests
}
Loading