Skip to content

Commit bd61682

Browse files
committed
resolved old token handling
1 parent 613f034 commit bd61682

6 files changed

Lines changed: 48 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ name = "encrypted_upload_test"
7777
path = "examples/encrypted_upload_test.rs"
7878

7979
[workspace.package]
80-
version = "0.3.5"
80+
version = "0.3.6"
8181
edition = "2021"
8282
license = "MIT OR Apache-2.0"
8383
repository = "https://github.com/functionland/fula-api"

crates/fula-client/src/encryption.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6086,13 +6086,27 @@ impl EncryptedClient {
60866086
.map_err(ClientError::Encryption)?;
60876087

60886088
let aead = Aead::new_default(&accepted_share.dek);
6089-
let version = accepted_share.encryption_version.unwrap_or(2);
6090-
let plaintext = if version >= 4 {
6091-
let aad = format!("fula:v4:content:{}", storage_key).into_bytes();
6092-
aead.decrypt_with_aad(&nonce, &data, &aad)
6093-
} else {
6094-
aead.decrypt(&nonce, &data)
6095-
}.map_err(ClientError::Encryption)?;
6089+
// `encryption_version` is Option<u8>: Some when the share creator
6090+
// explicitly stamped the token (new fula-flutter builds), None for
6091+
// tokens created between 1b82b95 (inline-nonce support, Jan 2026)
6092+
// and the flutter-side fix (which omit the field). For None, we
6093+
// try v4 AAD first (current upload format) and fall back to the
6094+
// pre-AAD v2 format so legacy tokens still decrypt.
6095+
let aad = format!("fula:v4:content:{}", storage_key).into_bytes();
6096+
let plaintext = match accepted_share.encryption_version {
6097+
Some(v) if v >= 4 => aead
6098+
.decrypt_with_aad(&nonce, &data, &aad)
6099+
.map_err(ClientError::Encryption)?,
6100+
Some(_) => aead
6101+
.decrypt(&nonce, &data)
6102+
.map_err(ClientError::Encryption)?,
6103+
None => match aead.decrypt_with_aad(&nonce, &data, &aad) {
6104+
Ok(pt) => pt,
6105+
Err(_) => aead
6106+
.decrypt(&nonce, &data)
6107+
.map_err(ClientError::Encryption)?,
6108+
},
6109+
};
60966110

60976111
return Ok(Bytes::from(plaintext));
60986112
}

crates/fula-flutter/src/api/sharing.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ pub async fn create_share_token(
8383
builder = builder.nonce(nonce_str);
8484
}
8585

86+
// Stamp the content encryption version so the recipient knows whether to
87+
// expect AAD binding (v4+) or bare AEAD (v2). Without this, fula-client
88+
// has to guess for single-object shares, which can mis-handle edge cases.
89+
if let Some(v) = enc_metadata["version"].as_u64() {
90+
builder = builder.encryption_version(v as u8);
91+
}
92+
8693
// Include chunked metadata for large files (> 768KB)
8794
if enc_metadata.get("chunked").is_some() {
8895
let chunked_json = serde_json::to_string(&enc_metadata["chunked"])
@@ -190,6 +197,15 @@ pub async fn create_share_token_with_mode(
190197
builder
191198
};
192199

200+
// Stamp the content encryption version so the recipient knows whether to
201+
// expect AAD binding (v4+) or bare AEAD (v2). Without this, fula-client
202+
// has to guess for single-object shares, which can mis-handle edge cases.
203+
let builder = if let Some(v) = enc_metadata["version"].as_u64() {
204+
builder.encryption_version(v as u8)
205+
} else {
206+
builder
207+
};
208+
193209
// Include chunked metadata for large files (> 768KB)
194210
let builder = if enc_metadata.get("chunked").is_some() {
195211
let chunked_json = serde_json::to_string(&enc_metadata["chunked"])

packages/fula_client/ios/fula_client.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Pod::Spec.new do |s|
88
s.name = 'fula_client'
9-
s.version = '0.3.5'
9+
s.version = '0.3.6'
1010
s.summary = 'Flutter SDK for Fula decentralized storage'
1111
s.description = <<-DESC
1212
A Flutter plugin providing client-side encryption, metadata privacy,

packages/fula_client/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: fula_client
22
description: Flutter SDK for Fula decentralized storage with client-side encryption, metadata privacy, and secure sharing.
3-
version: 0.3.5
3+
version: 0.3.6
44
homepage: https://fx.land
55
repository: https://github.com/functionland/fula-api
66
issue_tracker: https://github.com/functionland/fula-api/issues

0 commit comments

Comments
 (0)