Skip to content

Commit 3d655ad

Browse files
uhoregpoljar
authored andcommitted
feat: Add support for the new dehydrated device format
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.
1 parent bf01e8b commit 3d655ad

File tree

13 files changed

+498
-17
lines changed

13 files changed

+498
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ arrayvec = { version = "0.7.6", features = ["serde"] }
4949
base64 = "0.22.1"
5050
base64ct = { version = "1.6.0", features = ["std", "alloc"] }
5151
cbc = { version = "0.1.2", features = ["std"] }
52-
chacha20poly1305 = "0.10.1"
52+
chacha20poly1305 = { version = "0.10.1", features = ["std"] }
5353
curve25519-dalek = { version = "4.1.3", default-features = false, features = ["zeroize"] }
5454
ed25519-dalek = { version = "2.1.1", default-features = false, features = ["rand_core", "std", "serde", "hazmat", "zeroize"] }
5555
getrandom = "0.2.15"

afl/rehydrate-device/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "rehydrate-device"
3+
version = "0.1.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[dependencies]
8+
afl = "*"
9+
10+
[dependencies.vodozemac]
11+
path = "../.."
12+
13+
# Prevent this from interfering with workspaces
14+
[workspace]
15+
members = ["."]

afl/rehydrate-device/in/dehydrated1

425 Bytes
Binary file not shown.

afl/rehydrate-device/in/dehydrated2

425 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

afl/rehydrate-device/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use afl::fuzz;
2+
use vodozemac::olm::Account;
3+
4+
fn main() {
5+
fuzz!(|data: &[u8]| {
6+
let _ = Account::from_decrypted_dehydrated_device(data);
7+
});
8+
}

src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ pub enum PickleError {
232232

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

264+
/// Error type describing the various ways dehydrated devices can fail to be
265+
/// decoded.
266+
#[derive(Debug, thiserror::Error)]
267+
pub enum DehydratedDeviceError {
268+
/// The pickle is missing a valid version.
269+
#[error("The pickle doesn't contain a version")]
270+
MissingVersion,
271+
/// The pickle has a unsupported version.
272+
#[error("The pickle uses an unsupported version, expected {0}, got {1}")]
273+
Version(u32, u32),
274+
/// Invalid nonce.
275+
#[error("The nonce was invalid")]
276+
InvalidNonce,
277+
/// The pickle wasn't valid base64.
278+
#[error("The pickle wasn't valid base64: {0}")]
279+
Base64(#[from] Base64DecodeError),
280+
/// The pickle could not have been decrypted.
281+
#[error("The pickle couldn't be decrypted: {0}")]
282+
Decryption(#[from] chacha20poly1305::aead::Error),
283+
/// There was an error with the libolm pickle format
284+
#[error(transparent)]
285+
LibolmPickle(#[from] LibolmPickleError),
286+
}
287+
265288
/// Error type describing the different ways message decoding can fail.
266289
#[derive(Debug, thiserror::Error)]
267290
pub enum DecodeError {

0 commit comments

Comments
 (0)