Skip to content

Commit

Permalink
feat: Add support for the new dehydrated device format
Browse files Browse the repository at this point in the history
Changelog: Added support for [MSC3814](matrix-org/matrix-spec-proposals#3814),
    allowing users to export an Olm Account in a serialized format. The
    serialized account can be uploaded to a server for safekeeping until
    needed.
  • Loading branch information
uhoreg authored and poljar committed Jan 17, 2025
1 parent bf01e8b commit 3d655ad
Show file tree
Hide file tree
Showing 13 changed files with 498 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ arrayvec = { version = "0.7.6", features = ["serde"] }
base64 = "0.22.1"
base64ct = { version = "1.6.0", features = ["std", "alloc"] }
cbc = { version = "0.1.2", features = ["std"] }
chacha20poly1305 = "0.10.1"
chacha20poly1305 = { version = "0.10.1", features = ["std"] }
curve25519-dalek = { version = "4.1.3", default-features = false, features = ["zeroize"] }
ed25519-dalek = { version = "2.1.1", default-features = false, features = ["rand_core", "std", "serde", "hazmat", "zeroize"] }
getrandom = "0.2.15"
Expand Down
15 changes: 15 additions & 0 deletions afl/rehydrate-device/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "rehydrate-device"
version = "0.1.0"
publish = false
edition = "2021"

[dependencies]
afl = "*"

[dependencies.vodozemac]
path = "../.."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]
Binary file added afl/rehydrate-device/in/dehydrated1
Binary file not shown.
Binary file added afl/rehydrate-device/in/dehydrated2
Binary file not shown.
2 changes: 2 additions & 0 deletions afl/rehydrate-device/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
8 changes: 8 additions & 0 deletions afl/rehydrate-device/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use afl::fuzz;
use vodozemac::olm::Account;

fn main() {
fuzz!(|data: &[u8]| {
let _ = Account::from_decrypted_dehydrated_device(data);
});
}
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ pub enum PickleError {

/// Error type describing the various ways libolm pickles can fail to be
/// decoded.
#[cfg(feature = "libolm-compat")]
#[derive(Debug, thiserror::Error)]
pub enum LibolmPickleError {
/// The pickle is missing a valid version.
Expand Down Expand Up @@ -262,6 +261,30 @@ pub enum LibolmPickleError {
Encode(#[from] matrix_pickle::EncodeError),
}

/// Error type describing the various ways dehydrated devices can fail to be
/// decoded.
#[derive(Debug, thiserror::Error)]
pub enum DehydratedDeviceError {
/// The pickle is missing a valid version.
#[error("The pickle doesn't contain a version")]
MissingVersion,
/// The pickle has a unsupported version.
#[error("The pickle uses an unsupported version, expected {0}, got {1}")]
Version(u32, u32),
/// Invalid nonce.
#[error("The nonce was invalid")]
InvalidNonce,
/// The pickle wasn't valid base64.
#[error("The pickle wasn't valid base64: {0}")]
Base64(#[from] Base64DecodeError),
/// The pickle could not have been decrypted.
#[error("The pickle couldn't be decrypted: {0}")]
Decryption(#[from] chacha20poly1305::aead::Error),
/// There was an error with the libolm pickle format
#[error(transparent)]
LibolmPickle(#[from] LibolmPickleError),
}

/// Error type describing the different ways message decoding can fail.
#[derive(Debug, thiserror::Error)]
pub enum DecodeError {
Expand Down
Loading

0 comments on commit 3d655ad

Please sign in to comment.