Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoesters committed Dec 18, 2024
0 parents commit eaf7da8
Show file tree
Hide file tree
Showing 15 changed files with 828 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

name: Build and test Rust code

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
rust-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install cargo-machete
uses: taiki-e/install-action@cargo-machete
- name: Run cargo-machete
run: cargo machete

- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy, rustfmt

- name: Rustfmt
run: cargo fmt -- --check

- name: Clippy
run: cargo clippy --locked --all-targets -- -D warnings

- name: Build
run: cargo build --verbose

- name: Tests
run: cargo test --verbose
21 changes: 21 additions & 0 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

name: REUSE Compliance Check

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: REUSE Compliance Check
uses: fsfe/reuse-action@v5
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

*/target
*/Cargo.lock
*/test
target
.DS_Store
.vscode
.ruby-version
.env
74 changes: 74 additions & 0 deletions Cargo.lock

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

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

[package]
name = "mimi-protocol"
version = "0.1.0"
edition = "2021"

[dependencies]
serde_bytes = "0.11.15"
235 changes: 235 additions & 0 deletions LICENSES/AGPL-3.0-or-later.txt

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions LICENSES/CC-BY-4.0.txt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!--
SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
SPDX-License-Identifier: CC-BY-4.0
-->

# MIMI Message Content

This repository contains the code for a Rust implementation of the [MIMI protocol draft](https://datatracker.ietf.org/doc/draft-ietf-mimi-protocol/).

## Licensing

All crates in this repository are licensed under the [AGPL 3.0](https://www.gnu.org/licenses/agpl-3.0.html). This README file is licensed under [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/).
10 changes: 10 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

version = 1

[[annotations]]
path = ["Cargo.lock"]
SPDX-FileCopyrightText = "2024 Phoenix R&D GmbH <[email protected]>"
SPDX-License-Identifier = "AGPL-3.0-or-later"
41 changes: 41 additions & 0 deletions src/group_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use serde_bytes::ByteBuf;

use super::{CipherSuite, GroupInfo, RatchetTreeOption};

// "to-be-signed"
#[repr(u8)]
pub enum GroupInfoRequestTBS {
Mls10 {
cipher_suite: CipherSuite,
requesting_signature_key: SignaturePublicKey,
requesting_credential: Credential,
group_info_public_key: HPKEPublicKey,
joining_code: Option<String>, // TODO: Or ByteBuf?
} = 1,
}

// TODO: The signed variant's joining code is not optional?

// "to-be-encrypted"
pub struct GroupInfoRatchetTreeTBE {
group_info: GroupInfo,
ratchet_tree_option: RatchetTreeOption,
}

// "to-be-signed"
#[repr(u8)]
pub enum GroupInfoResponseTBS {
Mls10 {
status: GroupInfoCode,
cipher_suite: CipherSuite,
room_id: ByteBuf,
hub_sender: ExternalSender,
encrypted_groupinfo_and_tree: ByteBuf,
} = 1,
}

// TODO: How to get signed/encrypted structs? Macros?
54 changes: 54 additions & 0 deletions src/key_material.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use super::{Capabilities, CipherSuite, IdentifierUri, KeyPackage, RequiredCapabilities};

#[repr(u8)]
pub enum KeyMaterialRequest {
Mls10 {
requesting_user: IdentifierUri,
target_user: IdentifierUri,
room_id: IdentifierUri,
acceptable_ciphersuites: Vec<CipherSuite>,
required_capabilities: RequiredCapabilities,
} = 1,
}

#[repr(u8)]
pub enum KeyMaterialUserCode {
Success = 0,
PartialSuccess = 1,
IncompatibleProtocol = 2,
NoCompatibleMaterial = 3,
UserUnknown = 4,
NoConsent = 5,
NoConsentForThisRoom = 6,
UserDeleted = 7,
Custom(u8),
}

#[repr(u8)]
pub enum Mls10ClientKeyMaterial {
Success {
// TODO: Ask if field order of client_status and client_uri can be swapped
client_uri: IdentifierUri,
key_package: KeyPackage,
} = 0,
KeyMaterialExhausted {
client_uri: IdentifierUri,
} = 1,
NothingCompatible {
client_uri: IdentifierUri,
client_capabilities: Option<Capabilities>,
} = 2,
}

#[repr(u8)]
pub enum KeyMaterialResponse {
Mls10 {
user_status: KeyMaterialUserCode,
user_uri: IdentifierUri,
clients: Vec<Mls10ClientKeyMaterial>,
} = 1,
}
44 changes: 44 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

mod group_info;
mod key_material;
mod notify;
mod submit_message;
mod update;

// TODO: Import this from mls crate
#[repr(u16)]
pub enum CipherSuite {
Reserved = 0,
MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 = 1,
Custom(u16),
}
// TODO: Import this from mls crate
pub type RequiredCapabilities = ();
// TODO: Import this from mls crate
pub type Capabilities = ();
// TODO: Import this from mls crate
pub type KeyPackage = ();
// TODO: Import this from mls crate
pub type MlsMessage = ();
// TODO: Import this from mls crate
pub type Welcome = ();
// TODO: Import this from mls crate
pub type GroupInfo = ();
// TODO: Import this from mls crate
pub type PartialGroupInfo = ();
// TODO: Import this from mls crate
pub type RatchetTreeOption = ();
// TODO: Import this from mls crate
pub type ProposalRef = ();

#[repr(u8)]
pub enum Protocol {
Reserved = 0,
Mls10 = 1,
Custom(u8),
}

pub struct IdentifierUri(String); // TODO: Or ByteBuf?
24 changes: 24 additions & 0 deletions src/notify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use super::{MlsMessage, RatchetTreeOption};

struct Frank {
franking_tag: [u8; 32], // TODO: The RFC starts mixing camelCase and snake_case
server_frank: [u8; 32],
server_frank_context_hash: [u8; 32],
}

enum Mls10FanoutMessage {
Application {
timestamp: u64,
message: MlsMessage, // Must have wire_format = Application
frank: Option<Frank>, // In RFC, optional doesn't have the <>
},
Welcome {
timestamp: u64,
message: MlsMessage, // Must have wire_format = Welcome
ratchet_tree_option: RatchetTreeOption,
},
}
31 changes: 31 additions & 0 deletions src/submit_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use super::{IdentifierUri, MlsMessage};

#[repr(u8)]
pub enum SubmitMessageRequest {
Mls10 {
app_message: MlsMessage,
sending_uri: IdentifierUri,
} = 1,
}

#[repr(u8)]
pub enum SubmitResponseStatus {
Success {
// TODO: RFC also calls this "Accepted"
accepted_timestamp: u64,
server_frank: Option<[u8; 32]>,
} = 0,
NotAllowed {} = 1,
EpochTooOld {
current_epoch: u64,
} = 2,
}

#[repr(u8)]
pub enum SubmitMessageResponse {
Mls10 { status: SubmitResponseStatus } = 1,
}
Loading

0 comments on commit eaf7da8

Please sign in to comment.