Skip to content

Commit 1e1ff2d

Browse files
committed
WIP: feat: Autocrypt2
1 parent d8d49cc commit 1e1ff2d

7 files changed

Lines changed: 619 additions & 10 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ format-flowed = { path = "./format-flowed" }
4242
ratelimit = { path = "./deltachat-ratelimit" }
4343

4444
anyhow = { workspace = true }
45+
astral-tokio-tar = { version = "0.6.2", default-features = false }
4546
async-broadcast = "0.7.2"
4647
async-channel = { workspace = true }
4748
async-imap = { version = "0.11.1", default-features = false, features = ["runtime-tokio", "compress"] }
@@ -61,6 +62,7 @@ fd-lock = "4"
6162
futures-lite = { workspace = true }
6263
futures = { workspace = true }
6364
hex = "0.4.0"
65+
hkdf = { version = "0.12", default-features = false }
6466
http-body-util = "0.1.3"
6567
humansize = "2"
6668
hyper = "1"
@@ -103,7 +105,6 @@ thiserror = { workspace = true }
103105
tokio-io-timeout = "1.2.1"
104106
tokio-rustls = { version = "0.26.2", default-features = false, features = ["aws-lc-rs", "tls12"] }
105107
tokio-stream = { version = "0.1.17", features = ["fs"] }
106-
astral-tokio-tar = { version = "0.6.2", default-features = false }
107108
tokio-util = { workspace = true }
108109
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
109110
toml = "0.9"

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ pub enum Config {
477477
/// and incoming unencrypted messages are not fetched and not processed.
478478
#[strum(props(default = "1"))]
479479
ForceEncryption,
480+
481+
/// Generate Autocrypt 2 instead of Autocrypt 1 key.
482+
#[strum(props(default = "1"))]
483+
Autocrypt2,
480484
}
481485

482486
impl Config {

src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,10 @@ impl Context {
10331033
.await?
10341034
.to_string(),
10351035
);
1036+
res.insert(
1037+
"autocrypt2",
1038+
self.get_config_bool(Config::Autocrypt2).await?.to_string(),
1039+
);
10361040

10371041
let elapsed = time_elapsed(&self.creation_time);
10381042
res.insert("uptime", duration_to_str(elapsed));

src/key.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ use pgp::packet::{
1717
SubpacketData,
1818
};
1919
use pgp::ser::Serialize;
20+
use pgp::types::Timestamp as PgpTimestamp;
2021
use pgp::types::{CompressionAlgorithm, KeyDetails, KeyVersion};
2122
use rand_old::thread_rng;
2223
use tokio::runtime::Handle;
2324

25+
use crate::config::Config;
2426
use crate::context::Context;
2527
use crate::events::EventType;
2628
use crate::log::LogExt;
@@ -147,7 +149,7 @@ pub(crate) fn secret_key_to_public_key(
147149
};
148150

149151
Ok(vec![
150-
Subpacket::regular(SubpacketData::SignatureCreationTime(timestamp))?,
152+
Subpacket::critical(SubpacketData::SignatureCreationTime(timestamp))?,
151153
Subpacket::regular(SubpacketData::IssuerFingerprint(
152154
signed_secret_key.fingerprint(),
153155
))?,
@@ -461,9 +463,16 @@ async fn generate_keypair(context: &Context) -> Result<SignedSecretKey> {
461463
None => {
462464
let start = tools::Time::now();
463465
info!(context, "Generating keypair.");
464-
let keypair = Handle::current()
465-
.spawn_blocking(move || crate::pgp::create_keypair(addr))
466-
.await??;
466+
let keypair = if context.get_config_bool(Config::Autocrypt2).await? {
467+
let now = PgpTimestamp::now();
468+
Handle::current()
469+
.spawn_blocking(move || crate::pgp::autocrypt2::create_autocrypt2_keypair(now))
470+
.await??
471+
} else {
472+
Handle::current()
473+
.spawn_blocking(move || crate::pgp::create_keypair(addr))
474+
.await??
475+
};
467476

468477
store_self_keypair(context, &keypair).await?;
469478
info!(

src/pgp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use tokio::runtime::Handle;
2727

2828
use crate::key::{DcKey, Fingerprint};
2929

30+
pub(crate) mod autocrypt2;
31+
3032
/// Preferred symmetric encryption algorithm.
3133
const SYMMETRIC_KEY_ALGORITHM: SymmetricKeyAlgorithm = SymmetricKeyAlgorithm::AES128;
3234

0 commit comments

Comments
 (0)