-
-
Notifications
You must be signed in to change notification settings - Fork 110
QR codes and symmetric encryption for broadcast channels #7268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hocuri
wants to merge
73
commits into
main
Choose a base branch
from
hoc/channels-encryption-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
9694ba3
[WIP] QR codes and symmetric encryption for broadcast channels
Hocuri 10091a7
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 62d7441
test: Fix test_broadcast_multidev
Hocuri a434e6e
Fix some things, so that all tests pass sometimes. Some tests are sti…
Hocuri 7f3d0cc
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 17fdac2
clippy
Hocuri 8b3b597
test: Fix the flaky tests. All tests pass now!
Hocuri 915bad9
refactor: Remove unused MarkVerified sync action
Hocuri d755f61
improve comment
Hocuri e001067
Some things I noticed while self-reviewing
Hocuri c602586
Small comment improvements
Hocuri 7d92fcd
fix: Don't invent a secret when receiving an outgoing broadcast message
Hocuri faa149a
small comment improvement
Hocuri 5a91887
more comment improvements
Hocuri 41b4953
more tweaks
Hocuri 6114a6a
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 27d1d35
small tweaks
Hocuri 89f1e52
clippy
Hocuri 7fcbf39
Simon's review
Hocuri e00db35
Merge branch 'main' into hoc/channels-encryption-3
Hocuri a3a932a
clippy
Hocuri 7bd1ced
Update src/securejoin/bob.rs
Hocuri 07a6062
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri e6bb254
Update golden tests
Hocuri 24cbcbe
fix: Don't add duplicate member-added message
Hocuri 691887f
iequidoo's review
Hocuri e74f312
clippy
Hocuri fcc3363
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri f336add
iequidoo's review
Hocuri 24d5335
Fix compilation error
Hocuri a836775
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 8a4044e
Another compilation error
Hocuri 1d671d2
Fix test
Hocuri cafc2c7
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri efc323f
fix: Show an error message when trying to send into an old channel
Hocuri ab1844d
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 9776cd7
refactor: rename broadcast_shared_secret -> broadcast_secret
Hocuri 745d38c
refactor: inline handle_sync_create_chat()
Hocuri 1029707
Bail if added/removed member is missing
Hocuri 205ca0f
refactor: Rename src/internals_for_benchmarks.rs -> src/internals_for…
Hocuri 4d615d6
comments
Hocuri 9f87a53
Make some code shorter
Hocuri c101f2a
Small changes from iequidoo's review
Hocuri 93b8763
more of iequidoo's suggestions
Hocuri ea82fe9
Rename encryption_keys -> encryption_pubkeys
Hocuri 0e0c534
clippy
Hocuri 9e9ed67
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 501b5a7
remaining review comments
Hocuri 9e0ff87
more review
Hocuri 717d6bb
review, again
Hocuri 0a69a55
Make all rust tests pass again
Hocuri 7fdee26
clippy
Hocuri 1a85ad7
Update src/test_utils.rs
Hocuri 05cacc0
small test improvements
Hocuri 9048977
feat: Add and use stock string "You joined the channel"
Hocuri bd12139
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri c3be22f
Update src/mimefactory.rs
Hocuri bc116bd
fix compilation
Hocuri d9e38c6
Try to fix Python tests
Hocuri c71f698
fix: Delete broadcast secret when leaving or being removed from channel
Hocuri dd3cffd
don't prematurely optimize SQL statement
Hocuri 7be7ba0
feat: If someone who is not the admin tries to send into brodacast, a…
Hocuri 1d3ae6d
small fixes
Hocuri 327e0cc
test: Fix test flakiness
Hocuri af20e3e
fix: Delete request-with-auth messages immediately; some tests still …
Hocuri ca986cc
Update src/receive_imf.rs
Hocuri 644d6e5
fix: stop using `leftgrps` table
link2xt 1bbd3ec
feat(backwards-compat): For now, send Chat-Verified header (instead o…
Hocuri 3723cd1
fix remaining test failures
Hocuri c1b53b1
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri c0aa31c
fix: Set chat_created = true when creating outgoing broadcast
Hocuri 2409431
Merge remote-tracking branch 'origin/main' into hoc/channels-encrypti…
Hocuri 28d1ca9
fix: Use Chat-List-Id rather than List-Id header
Hocuri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| //! Benchmarks for message decryption, | ||
| //! comparing decryption of symmetrically-encrypted messages | ||
| //! to decryption of asymmetrically-encrypted messages. | ||
| //! | ||
| //! Call with | ||
| //! | ||
| //! ```text | ||
| //! cargo bench --bench benchmark_decrypting --features="internals" | ||
| //! ``` | ||
| //! | ||
| //! or, if you want to only run e.g. the 'Decrypt a symmetrically encrypted message' benchmark: | ||
| //! | ||
| //! ```text | ||
| //! cargo bench --bench benchmark_decrypting --features="internals" -- 'Decrypt a symmetrically encrypted message' | ||
| //! ``` | ||
| //! | ||
| //! You can also pass a substring. | ||
| //! So, you can run all 'Decrypt and parse' benchmarks with: | ||
| //! | ||
| //! ```text | ||
| //! cargo bench --bench benchmark_decrypting --features="internals" -- 'Decrypt and parse' | ||
| //! ``` | ||
| //! | ||
| //! Symmetric decryption has to try out all known secrets, | ||
| //! You can benchmark this by adapting the `NUM_SECRETS` variable. | ||
|
|
||
| use std::hint::black_box; | ||
|
|
||
| use criterion::{Criterion, criterion_group, criterion_main}; | ||
| use deltachat::internals_for_benchmarks::create_broadcast_shared_secret; | ||
| use deltachat::internals_for_benchmarks::create_dummy_keypair; | ||
| use deltachat::internals_for_benchmarks::save_broadcast_shared_secret; | ||
| use deltachat::{ | ||
| Events, | ||
| chat::ChatId, | ||
| config::Config, | ||
| context::Context, | ||
| internals_for_benchmarks::key_from_asc, | ||
| internals_for_benchmarks::parse_and_get_text, | ||
| internals_for_benchmarks::store_self_keypair, | ||
| pgp::{KeyPair, decrypt, pk_encrypt, symm_encrypt_message}, | ||
| stock_str::StockStrings, | ||
| }; | ||
| use rand::{Rng, thread_rng}; | ||
| use tempfile::tempdir; | ||
|
|
||
| const NUM_SECRETS: usize = 500; | ||
|
|
||
| async fn create_context() -> Context { | ||
| let dir = tempdir().unwrap(); | ||
| let dbfile = dir.path().join("db.sqlite"); | ||
| let context = Context::new(dbfile.as_path(), 100, Events::new(), StockStrings::new()) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| context | ||
| .set_config(Config::ConfiguredAddr, Some("[email protected]")) | ||
| .await | ||
| .unwrap(); | ||
| let secret = key_from_asc(include_str!("../test-data/key/bob-secret.asc")).unwrap(); | ||
| let public = secret.signed_public_key(); | ||
| let key_pair = KeyPair { public, secret }; | ||
| store_self_keypair(&context, &key_pair) | ||
| .await | ||
| .expect("Failed to save key"); | ||
|
|
||
| context | ||
| } | ||
|
|
||
| fn criterion_benchmark(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("Decrypt"); | ||
|
|
||
| // =========================================================================================== | ||
| // Benchmarks for decryption only, without any other parsing | ||
| // =========================================================================================== | ||
|
|
||
| group.sample_size(10); | ||
|
|
||
| group.bench_function("Decrypt a symmetrically encrypted message", |b| { | ||
| let plain = generate_plaintext(); | ||
| let secrets = generate_secrets(); | ||
| let encrypted = tokio::runtime::Runtime::new().unwrap().block_on(async { | ||
| let secret = secrets[NUM_SECRETS / 2].clone(); | ||
| symm_encrypt_message( | ||
| plain.clone(), | ||
| black_box(&secret), | ||
| create_dummy_keypair("[email protected]").unwrap().secret, | ||
| true, | ||
| ) | ||
| .await | ||
| .unwrap() | ||
| }); | ||
|
|
||
| b.iter(|| { | ||
| let mut msg = | ||
| decrypt(encrypted.clone().into_bytes(), &[], black_box(&secrets)).unwrap(); | ||
| let decrypted = msg.as_data_vec().unwrap(); | ||
|
|
||
| assert_eq!(black_box(decrypted), plain); | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("Decrypt a public-key encrypted message", |b| { | ||
| let plain = generate_plaintext(); | ||
| let key_pair = create_dummy_keypair("[email protected]").unwrap(); | ||
| let secrets = generate_secrets(); | ||
| let encrypted = tokio::runtime::Runtime::new().unwrap().block_on(async { | ||
| pk_encrypt( | ||
| plain.clone(), | ||
| vec![black_box(key_pair.public.clone())], | ||
| Some(key_pair.secret.clone()), | ||
| true, | ||
| ) | ||
| .await | ||
| .unwrap() | ||
| }); | ||
|
|
||
| b.iter(|| { | ||
| let mut msg = decrypt( | ||
| encrypted.clone().into_bytes(), | ||
| std::slice::from_ref(&key_pair.secret), | ||
| black_box(&secrets), | ||
| ) | ||
| .unwrap(); | ||
| let decrypted = msg.as_data_vec().unwrap(); | ||
|
|
||
| assert_eq!(black_box(decrypted), plain); | ||
| }); | ||
| }); | ||
|
|
||
| // =========================================================================================== | ||
| // Benchmarks for the whole parsing pipeline, incl. decryption (but excl. receive_imf()) | ||
| // =========================================================================================== | ||
|
|
||
| let rt = tokio::runtime::Runtime::new().unwrap(); | ||
| let mut secrets = generate_secrets(); | ||
|
|
||
| // "secret" is the shared secret that was used to encrypt text_symmetrically_encrypted.eml. | ||
| // Put it into the middle of our secrets: | ||
| secrets[NUM_SECRETS / 2] = "secret".to_string(); | ||
|
|
||
| let context = rt.block_on(async { | ||
| let context = create_context().await; | ||
| for (i, secret) in secrets.iter().enumerate() { | ||
| save_broadcast_shared_secret(&context, ChatId::new(10 + i as u32), secret) | ||
| .await | ||
| .unwrap(); | ||
| } | ||
| context | ||
| }); | ||
|
|
||
| group.bench_function("Decrypt and parse a symmetrically encrypted message", |b| { | ||
| b.to_async(&rt).iter(|| { | ||
| let ctx = context.clone(); | ||
| async move { | ||
| let text = parse_and_get_text( | ||
| &ctx, | ||
| include_bytes!("../test-data/message/text_symmetrically_encrypted.eml"), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(text, "Symmetrically encrypted message"); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("Decrypt and parse a public-key encrypted message", |b| { | ||
| b.to_async(&rt).iter(|| { | ||
| let ctx = context.clone(); | ||
| async move { | ||
| let text = parse_and_get_text( | ||
| &ctx, | ||
| include_bytes!("../test-data/message/text_from_alice_encrypted.eml"), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(text, "hi"); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| fn generate_secrets() -> Vec<String> { | ||
| let secrets: Vec<String> = (0..NUM_SECRETS) | ||
| .map(|_| create_broadcast_shared_secret()) | ||
| .collect(); | ||
| secrets | ||
| } | ||
|
|
||
| fn generate_plaintext() -> Vec<u8> { | ||
| let mut plain: Vec<u8> = vec![0; 500]; | ||
| thread_rng().fill(&mut plain[..]); | ||
| plain | ||
| } | ||
|
|
||
| criterion_group!(benches, criterion_benchmark); | ||
| criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.