From cb41c91fb421aef7ef67c59b7745146f4e95ecc1 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Thu, 7 Sep 2023 14:28:51 +0200 Subject: [PATCH] Replaced rpgp with sequoia-pgp --- Cargo.lock | 717 +++++++++++++------------------ crates/jmap/Cargo.toml | 2 +- crates/jmap/src/email/crypto.rs | 169 ++++++-- tests/resources/test_config.toml | 7 +- 4 files changed, 435 insertions(+), 460 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72365aa5..d10953f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom", + "getrandom 0.2.10", "once_cell", "version_check", ] @@ -85,7 +85,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ "cfg-if", - "getrandom", + "getrandom 0.2.10", "once_cell", "serde", "version_check", @@ -206,6 +206,15 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + [[package]] name = "asn1-rs" version = "0.5.2" @@ -458,6 +467,26 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 1.0.109", +] + [[package]] name = "bindgen" version = "0.64.0" @@ -516,12 +545,6 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" -[[package]] -name = "bitfield" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" - [[package]] name = "bitflags" version = "1.3.2" @@ -630,33 +653,15 @@ dependencies = [ ] [[package]] -name = "blowfish" -version = "0.9.1" +name = "buffered-reader" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" +checksum = "66d3bea5bcc3ecc38fe5388e6bc35e6fe7bd665eb3ae9a44283e15b91ad3867d" dependencies = [ - "byteorder", - "cipher 0.4.4", -] - -[[package]] -name = "bstr" -version = "1.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a" -dependencies = [ - "memchr", - "serde", -] - -[[package]] -name = "buffer-redux" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2886ea01509598caac116942abd33ab5a88fa32acdf7e4abfa0fc489ca520c9" -dependencies = [ - "memchr", - "safemem", + "bzip2", + "flate2", + "lazy_static", + "libc", ] [[package]] @@ -704,25 +709,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "camellia" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3264e2574e9ef2b53ce6f536dea83a69ac0bc600b762d1523ff83fe07230ce30" -dependencies = [ - "byteorder", - "cipher 0.4.4", -] - -[[package]] -name = "cast5" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b07d673db1ccf000e90f54b819db9e75a8348d6eb056e9b8ab53231b7a9911" -dependencies = [ - "cipher 0.4.4", -] - [[package]] name = "cbc" version = "0.1.2" @@ -760,15 +746,6 @@ dependencies = [ "nom", ] -[[package]] -name = "cfb-mode" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "738b8d467867f80a71351933f70461f5b56f24d5c93e0cf216e59229c968d330" -dependencies = [ - "cipher 0.4.4", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -944,12 +921,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" -[[package]] -name = "crc24" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd121741cf3eb82c08dd3023eb55bf2665e5f60ec20f89760cf836ae4562e6a0" - [[package]] name = "crc32fast" version = "1.3.2" @@ -1025,7 +996,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" dependencies = [ "generic-array", - "rand_core", + "rand_core 0.6.4", "subtle", "zeroize", ] @@ -1037,7 +1008,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", - "rand_core", + "rand_core 0.6.4", "typenum", ] @@ -1081,69 +1052,6 @@ dependencies = [ "cipher 0.4.4", ] -[[package]] -name = "curve25519-dalek" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" -dependencies = [ - "cfg-if", - "cpufeatures", - "curve25519-dalek-derive", - "digest 0.10.7", - "fiat-crypto", - "platforms", - "rustc_version", - "subtle", - "zeroize", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] - -[[package]] -name = "darling" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" -dependencies = [ - "darling_core", - "quote", - "syn 1.0.109", -] - [[package]] name = "dashmap" version = "5.5.3" @@ -1197,46 +1105,6 @@ dependencies = [ "serde", ] -[[package]] -name = "derive_builder" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "derive_builder_macro" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" -dependencies = [ - "derive_builder_core", - "syn 1.0.109", -] - -[[package]] -name = "des" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdd80ce8ce993de27e9f063a444a4d53ce8e8db4c1f00cc03af5ad5a9867a1e" -dependencies = [ - "cipher 0.4.4", -] - [[package]] name = "dialoguer" version = "0.10.4" @@ -1249,6 +1117,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "digest" version = "0.9.0" @@ -1372,6 +1246,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "dyn-clone" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" + [[package]] name = "ecdsa" version = "0.16.8" @@ -1404,29 +1284,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "ed25519" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" -dependencies = [ - "pkcs8", - "signature", -] - -[[package]] -name = "ed25519-dalek" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" -dependencies = [ - "curve25519-dalek", - "ed25519", - "serde", - "sha2 0.10.7", - "zeroize", -] - [[package]] name = "either" version = "1.9.0" @@ -1451,12 +1308,21 @@ dependencies = [ "hkdf", "pem-rfc7468", "pkcs8", - "rand_core", + "rand_core 0.6.4", "sec1", "subtle", "zeroize", ] +[[package]] +name = "ena" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" +dependencies = [ + "log", +] + [[package]] name = "encode_unicode" version = "0.3.6" @@ -1580,16 +1446,10 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "rand_core", + "rand_core 0.6.4", "subtle", ] -[[package]] -name = "fiat-crypto" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" - [[package]] name = "filetime" version = "0.2.22" @@ -1690,7 +1550,7 @@ dependencies = [ "foundationdb-sys", "futures", "memchr", - "rand", + "rand 0.8.5", "serde", "serde_bytes", "serde_json", @@ -1864,6 +1724,19 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -1871,8 +1744,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -1904,7 +1779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -2200,20 +2075,15 @@ dependencies = [ ] [[package]] -name = "idea" -version = "0.5.1" +name = "idna" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "075557004419d7f2031b8bb7f44bb43e55a83ca7b63076a8fb8fe75753836477" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "cipher 0.4.4", + "unicode-bidi", + "unicode-normalization", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "idna" version = "0.4.0" @@ -2418,13 +2288,13 @@ dependencies = [ "mail-send", "mime", "p256", - "pgp", - "rand", + "rand 0.8.5", "rasn", "rasn-cms", "rasn-pkix", "reqwest", "rsa", + "sequoia-openpgp", "serde", "serde_json", "sha2 0.10.7", @@ -2493,15 +2363,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "keccak" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" -dependencies = [ - "cpufeatures", -] - [[package]] name = "konst" version = "0.3.6" @@ -2522,6 +2383,34 @@ dependencies = [ "typewit", ] +[[package]] +name = "lalrpop" +version = "0.19.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" +dependencies = [ + "ascii-canvas", + "bit-set", + "diff", + "ena", + "is-terminal", + "itertools", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax 0.6.29", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" + [[package]] name = "lazy_static" version = "1.4.0" @@ -2872,6 +2761,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memsec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa0916b001582d253822171bd23f4a0229d32b9507fae236f5da8cad515ba7c" + [[package]] name = "mime" version = "0.3.17" @@ -2920,6 +2815,39 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "nettle" +version = "7.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9fdccf3eae7b161910d2daa2f0155ca35041322e8fe5c5f1f2c9d0b12356336" +dependencies = [ + "getrandom 0.2.10", + "libc", + "nettle-sys", + "thiserror", + "typenum", +] + +[[package]] +name = "nettle-sys" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e81c347b9002da0b6b0c4060993c280e99eb14b42ecf65a2fefcd6eb3d8a73" +dependencies = [ + "bindgen 0.63.0", + "cc", + "libc", + "pkg-config", + "tempfile", + "vcpkg", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + [[package]] name = "nix" version = "0.26.4" @@ -2976,23 +2904,11 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand", - "serde", + "rand 0.8.5", "smallvec", "zeroize", ] -[[package]] -name = "num-derive" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e6a0fd4f737c707bd9086cc16c925f294943eb62eb71499e9fd4cf71f8b9f4e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -3222,7 +3138,7 @@ dependencies = [ "once_cell", "opentelemetry_api", "percent-encoding", - "rand", + "rand 0.8.5", "thiserror", "tokio", "tokio-stream", @@ -3256,18 +3172,6 @@ dependencies = [ "sha2 0.10.7", ] -[[package]] -name = "p384" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70786f51bcc69f6a4c0360e063a4cac5419ef7c5cd5b3c99ad70f3be5ba79209" -dependencies = [ - "ecdsa", - "elliptic-curve", - "primeorder", - "sha2 0.10.7", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3298,7 +3202,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -3309,7 +3213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" dependencies = [ "base64ct", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -3374,58 +3278,6 @@ dependencies = [ "indexmap 2.0.0", ] -[[package]] -name = "pgp" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27e1f8e085bfa9b85763fe3ddaacbe90a09cd847b3833129153a6cb063bbe132" -dependencies = [ - "aes", - "base64 0.21.3", - "bitfield", - "block-padding", - "blowfish 0.9.1", - "bstr", - "buffer-redux", - "byteorder", - "camellia", - "cast5", - "cfb-mode", - "chrono", - "cipher 0.4.4", - "crc24", - "curve25519-dalek", - "derive_builder", - "des", - "digest 0.10.7", - "ed25519-dalek", - "elliptic-curve", - "flate2", - "generic-array", - "hex", - "idea", - "log", - "md-5 0.10.5", - "nom", - "num-bigint-dig", - "num-derive", - "num-traits", - "p256", - "p384", - "rand", - "ripemd", - "rsa", - "sha1", - "sha2 0.10.7", - "sha3", - "signature", - "smallvec", - "thiserror", - "twofish", - "x25519-dalek", - "zeroize", -] - [[package]] name = "phf" version = "0.11.2" @@ -3433,7 +3285,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_macros", - "phf_shared", + "phf_shared 0.11.2", ] [[package]] @@ -3443,7 +3295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ "phf_generator", - "phf_shared", + "phf_shared 0.11.2", ] [[package]] @@ -3452,8 +3304,8 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ - "phf_shared", - "rand", + "phf_shared 0.11.2", + "rand 0.8.5", ] [[package]] @@ -3463,12 +3315,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ "phf_generator", - "phf_shared", + "phf_shared 0.11.2", "proc-macro2", "quote", "syn 2.0.29", ] +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + [[package]] name = "phf_shared" version = "0.11.2" @@ -3537,12 +3398,6 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" -[[package]] -name = "platforms" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" - [[package]] name = "polyval" version = "0.6.1" @@ -3567,6 +3422,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "prettyplease" version = "0.1.25" @@ -3689,11 +3550,11 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "419a3ad8fa9f9d445e69d9b185a24878ae6e6f55c96e4512f4a0e28cd3bc5c56" dependencies = [ - "blowfish 0.7.0", + "blowfish", "byteorder", "hmac 0.10.1", "md-5 0.9.1", - "rand", + "rand 0.8.5", "sha-1", "sha2 0.9.9", ] @@ -3749,6 +3610,19 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -3756,8 +3630,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] @@ -3767,7 +3651,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", ] [[package]] @@ -3776,7 +3669,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.10", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -3881,7 +3783,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom", + "getrandom 0.2.10", "redox_syscall 0.2.16", "thiserror", ] @@ -4013,15 +3915,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "roaring" version = "0.10.2" @@ -4069,7 +3962,7 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8", - "rand_core", + "rand_core 0.6.4", "signature", "spki", "subtle", @@ -4164,15 +4057,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rusticata-macros" version = "4.1.0" @@ -4272,12 +4156,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" -[[package]] -name = "safemem" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" - [[package]] name = "salsa20" version = "0.10.2" @@ -4371,10 +4249,34 @@ dependencies = [ ] [[package]] -name = "semver" -version = "1.0.18" +name = "sequoia-openpgp" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "30efff3f9930e85b4284e76bbdad741f36412dfb1e370efd0de5866ae1a11dfc" +dependencies = [ + "anyhow", + "base64 0.21.3", + "buffered-reader", + "bzip2", + "chrono", + "dyn-clone", + "flate2", + "getrandom 0.2.10", + "idna 0.3.0", + "lalrpop", + "lalrpop-util", + "lazy_static", + "libc", + "memsec", + "nettle", + "once_cell", + "rand 0.7.3", + "regex", + "regex-syntax 0.6.29", + "sha1collisiondetection", + "thiserror", + "xxhash-rust", +] [[package]] name = "serde" @@ -4477,6 +4379,16 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "sha1collisiondetection" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b20793cf8330b2c7da4c438116660fed24e380bcb8a1bcfff2581b5593a0b38e" +dependencies = [ + "digest 0.9.0", + "generic-array", +] + [[package]] name = "sha2" version = "0.9.9" @@ -4501,16 +4413,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest 0.10.7", - "keccak", -] - [[package]] name = "sharded-slab" version = "0.1.4" @@ -4562,7 +4464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ "digest 0.10.7", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -4606,7 +4508,7 @@ dependencies = [ "mail-send", "num_cpus", "parking_lot", - "rand", + "rand 0.8.5", "rayon", "regex", "reqwest", @@ -4836,7 +4738,7 @@ dependencies = [ "memchr", "once_cell", "percent-encoding", - "rand", + "rand 0.8.5", "rsa", "serde", "sha1", @@ -4875,7 +4777,7 @@ dependencies = [ "md-5 0.10.5", "memchr", "once_cell", - "rand", + "rand 0.8.5", "serde", "serde_json", "sha1", @@ -4944,7 +4846,7 @@ dependencies = [ "libc", "openssl", "pwhash", - "rand", + "rand 0.8.5", "reqwest", "rpassword", "rusqlite", @@ -4975,7 +4877,7 @@ dependencies = [ "num_cpus", "parking_lot", "r2d2", - "rand", + "rand 0.8.5", "rayon", "roaring", "rocksdb", @@ -4992,6 +4894,19 @@ dependencies = [ "xxhash-rust", ] +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", +] + [[package]] name = "stringprep" version = "0.1.3" @@ -5212,6 +5127,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinysegmenter" version = "0.1.1" @@ -5395,7 +5319,7 @@ dependencies = [ "indexmap 1.9.3", "pin-project", "pin-project-lite", - "rand", + "rand 0.8.5", "slab", "tokio", "tokio-util", @@ -5527,10 +5451,10 @@ dependencies = [ "futures-channel", "futures-io", "futures-util", - "idna", + "idna 0.4.0", "ipnet", "once_cell", - "rand", + "rand 0.8.5", "ring", "rustls 0.21.7", "rustls-pemfile", @@ -5556,7 +5480,7 @@ dependencies = [ "lru-cache", "once_cell", "parking_lot", - "rand", + "rand 0.8.5", "resolv-conf", "rustls 0.21.7", "smallvec", @@ -5592,7 +5516,7 @@ dependencies = [ "http", "httparse", "log", - "rand", + "rand 0.8.5", "rustls 0.21.7", "sha1", "thiserror", @@ -5613,22 +5537,13 @@ dependencies = [ "http", "httparse", "log", - "rand", + "rand 0.8.5", "sha1", "thiserror", "url", "utf-8", ] -[[package]] -name = "twofish" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a78e83a30223c757c3947cd144a31014ff04298d8719ae10d03c31c0448c8013" -dependencies = [ - "cipher 0.4.4", -] - [[package]] name = "typenum" version = "1.16.0" @@ -5718,7 +5633,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", - "idna", + "idna 0.4.0", "percent-encoding", ] @@ -5764,7 +5679,7 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -5794,6 +5709,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -6153,18 +6074,6 @@ dependencies = [ "tap", ] -[[package]] -name = "x25519-dalek" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96" -dependencies = [ - "curve25519-dalek", - "rand_core", - "serde", - "zeroize", -] - [[package]] name = "x509-parser" version = "0.15.1" @@ -6208,20 +6117,6 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] [[package]] name = "zip" diff --git a/crates/jmap/Cargo.toml b/crates/jmap/Cargo.toml index c1e0e8b8..001ae0e6 100644 --- a/crates/jmap/Cargo.toml +++ b/crates/jmap/Cargo.toml @@ -42,7 +42,7 @@ chrono = "0.4" dashmap = "5.4" aes = "0.8.3" cbc = { version = "0.1.2", features = ["alloc"] } -pgp = "0.10.2" +sequoia-openpgp = "1.16" rand = "0.8.5" rasn = "0.9.5" rasn-cms = "0.9.5" diff --git a/crates/jmap/src/email/crypto.rs b/crates/jmap/src/email/crypto.rs index 194d8ece..8cd57a83 100644 --- a/crates/jmap/src/email/crypto.rs +++ b/crates/jmap/src/email/crypto.rs @@ -21,13 +21,22 @@ * for more details. */ -use std::{borrow::Cow, collections::BTreeSet, fmt::Display}; +use std::{borrow::Cow, collections::BTreeSet, fmt::Display, io::Cursor}; +use crate::{ + api::{http::ToHttpResponse, HtmlResponse, HttpRequest, HttpResponse}, + auth::{oauth::FormData, rate_limit::RemoteAddress}, + JMAP, +}; use aes::cipher::{block_padding::Pkcs7, BlockEncryptMut, KeyIvInit}; use jmap_proto::types::{collection::Collection, property::Property}; use mail_builder::{encoders::base64::base64_encode_mime, mime::make_boundary}; use mail_parser::{decoders::base64::base64_decode, Message, MessageParser, MimeHeaders}; -use pgp::{composed, crypto::sym::SymmetricKeyAlgorithm, Deserializable, SignedPublicKey}; +use openpgp::{ + parse::Parse, + serialize::stream, + types::{KeyFlags, SymmetricAlgorithm}, +}; use rand::{rngs::StdRng, RngCore, SeedableRng}; use rasn::types::{ObjectIdentifier, OctetString}; use rasn_cms::{ @@ -38,17 +47,12 @@ use rasn_cms::{ CONTENT_ENVELOPED_DATA, }; use rsa::{pkcs1::DecodeRsaPublicKey, Pkcs1v15Encrypt, RsaPublicKey}; +use sequoia_openpgp as openpgp; use store::{ write::{BatchBuilder, ToBitmaps, F_CLEAR, F_VALUE}, Deserialize, Serialize, }; -use crate::{ - api::{http::ToHttpResponse, HtmlResponse, HttpRequest, HttpResponse}, - auth::{oauth::FormData, rate_limit::RemoteAddress}, - JMAP, -}; - const CRYPT_HTML_HEADER: &str = include_str!("../../../../resources/htx/crypto_header.htx"); const CRYPT_HTML_FOOTER: &str = include_str!("../../../../resources/htx/crypto_footer.htx"); const CRYPT_HTML_FORM: &str = include_str!("../../../../resources/htx/crypto_form.htx"); @@ -56,6 +60,8 @@ const CRYPT_HTML_SUCCESS: &str = include_str!("../../../../resources/htx/crypto_ const CRYPT_HTML_DISABLED: &str = include_str!("../../../../resources/htx/crypto_disabled.htx"); const CRYPT_HTML_ERROR: &str = include_str!("../../../../resources/htx/crypto_error.htx"); +const P: openpgp::policy::StandardPolicy<'static> = openpgp::policy::StandardPolicy::new(); + #[derive(Debug)] pub enum EncryptMessageError { AlreadyEncrypted, @@ -132,7 +138,7 @@ impl EncryptMessage for Message<'_> { outer_message.extend_from_slice(boundary.as_bytes()); outer_message.extend_from_slice( concat!( - "\r\nContent-Type: application/pgp-encrypted\r\n", + "\r\nContent-Type: application/pgp-encrypted\r\n\r\n", "Version: 1\r\n\r\n--" ) .as_bytes(), @@ -146,42 +152,85 @@ impl EncryptMessage for Message<'_> { .as_bytes(), ); - // Parse public key - let mut keys = Vec::with_capacity(params.certs.len()); - for cert in ¶ms.certs { - keys.push(SignedPublicKey::from_bytes(&cert[..]).map_err(|err| { + let certs = params + .certs + .iter() + .map(openpgp::Cert::from_bytes) + .collect::, _>>() + .map_err(|err| { EncryptMessageError::Error(format!( "Failed to parse OpenPGP public key: {}", err )) - })?); - } + })?; // Encrypt contents (TODO: use rayon) let algo = params.algo; let encrypted_contents = tokio::task::spawn_blocking(move || { - composed::message::Message::new_literal_bytes("none", &inner_message) - .encrypt_to_keys( - &mut StdRng::from_entropy(), - match algo { - Algorithm::Aes128 => SymmetricKeyAlgorithm::AES128, - Algorithm::Aes256 => SymmetricKeyAlgorithm::AES256, - }, - &keys.iter().collect::>(), - ) + // Parse public key + let mut keys = Vec::with_capacity(certs.len()); + let policy = openpgp::policy::StandardPolicy::new(); + + for cert in &certs { + for key in cert + .keys() + .with_policy(&policy, None) + .supported() + .alive() + .revoked(false) + .key_flags(&KeyFlags::empty().set_transport_encryption()) + { + keys.push(key); + } + } + + // Compose a writer stack corresponding to the output format and + // packet structure we want. + let mut sink = Vec::with_capacity(inner_message.len()); + + // Stream an OpenPGP message. + let message = stream::Armorer::new(stream::Message::new(&mut sink)) + .build() .map_err(|err| { + EncryptMessageError::Error(format!("Failed to create armorer: {}", err)) + })?; + let message = stream::Encryptor::for_recipients(message, keys) + .symmetric_algo(match algo { + Algorithm::Aes128 => SymmetricAlgorithm::AES128, + Algorithm::Aes256 => SymmetricAlgorithm::AES256, + }) + .build() + .map_err(|err| { + EncryptMessageError::Error(format!( + "Failed to build encryptor: {}", + err + )) + })?; + let mut message = + stream::LiteralWriter::new(message).build().map_err(|err| { + EncryptMessageError::Error(format!( + "Failed to create literal writer: {}", + err + )) + })?; + std::io::copy(&mut Cursor::new(inner_message), &mut message).map_err( + |err| { EncryptMessageError::Error(format!( "Failed to encrypt message: {}", err )) - })? - .to_armored_string(None) - .map_err(|err| { - EncryptMessageError::Error(format!( - "Failed to convert to armored string: {}", - err - )) - }) + }, + )?; + message.finalize().map_err(|err| { + EncryptMessageError::Error(format!("Failed to finalize message: {}", err)) + })?; + + String::from_utf8(sink).map_err(|err| { + EncryptMessageError::Error(format!( + "Failed to convert encrypted message to UTF-8: {}", + err + )) + }) }) .await .map_err(|err| { @@ -382,26 +431,43 @@ pub fn try_parse_certs(bytes: Vec) -> Result<(EncryptionMethod, Vec> Ok(result) } else if rasn::der::decode::(&bytes[..]).is_ok() { Ok((EncryptionMethod::SMIME, vec![bytes])) - } else if SignedPublicKey::from_bytes(&bytes[..]).is_ok() { - Ok((EncryptionMethod::PGP, vec![bytes])) + } else if let Ok(cert) = openpgp::Cert::from_bytes(&bytes[..]) { + if !has_pgp_keys(cert) { + Ok((EncryptionMethod::PGP, vec![bytes])) + } else { + Err("Could not find any suitable keys in certificate".to_string()) + } } else { Err("Could not find any valid certificates".to_string()) } } +fn has_pgp_keys(cert: openpgp::Cert) -> bool { + cert.keys() + .with_policy(&P, None) + .supported() + .alive() + .revoked(false) + .key_flags(&KeyFlags::empty().set_transport_encryption()) + .next() + .is_some() +} + #[allow(clippy::type_complexity)] -fn try_parse_pem(bytes: &[u8]) -> Result>)>, String> { - let mut bytes = bytes.iter(); +fn try_parse_pem(bytes_: &[u8]) -> Result>)>, String> { + let mut bytes = bytes_.iter().enumerate(); let mut buf = vec![]; let mut method = None; let mut certs = vec![]; loop { // Find start of PEM block - for &ch in bytes.by_ref() { + let mut start_pos = 0; + for (pos, &ch) in bytes.by_ref() { if ch.is_ascii_whitespace() { continue; } else if ch == b'-' { + start_pos = pos; break; } else { return Ok(None); @@ -409,7 +475,7 @@ fn try_parse_pem(bytes: &[u8]) -> Result>) } // Find block type - for &ch in bytes.by_ref() { + for (_, &ch) in bytes.by_ref() { match ch { b'-' => (), b'\n' => break, @@ -443,7 +509,7 @@ fn try_parse_pem(bytes: &[u8]) -> Result>) } else { // Ignore block let mut found_end = false; - for &ch in bytes.by_ref() { + for (_, &ch) in bytes.by_ref() { if ch == b'-' { found_end = true; } else if ch == b'\n' && found_end { @@ -457,13 +523,15 @@ fn try_parse_pem(bytes: &[u8]) -> Result>) // Collect base64 buf.clear(); let mut found_end = false; - for &ch in bytes.by_ref() { + let mut end_pos = 0; + for (pos, &ch) in bytes.by_ref() { match ch { b'-' => { found_end = true; } b'\n' => { if found_end { + end_pos = pos; break; } } @@ -479,18 +547,29 @@ fn try_parse_pem(bytes: &[u8]) -> Result>) let cert = base64_decode(&buf) .ok_or_else(|| "Failed to decode base64 certificate.".to_string())?; match method.unwrap() { - EncryptionMethod::PGP => { - if let Err(err) = SignedPublicKey::from_bytes(&cert[..]) { - return Err(format!("Failed to decode OpenPGP public key: {}", err)); + EncryptionMethod::PGP => match openpgp::Cert::from_bytes(bytes_) { + Ok(cert) => { + if !has_pgp_keys(cert) { + return Err( + "Could not find any suitable keys in OpenPGP public key".to_string() + ); + } + certs.push( + bytes_ + .get(start_pos..end_pos + 1) + .unwrap_or_default() + .to_vec(), + ); } - } + Err(err) => return Err(format!("Failed to decode OpenPGP public key: {}", err)), + }, EncryptionMethod::SMIME => { if let Err(err) = rasn::der::decode::(&cert) { return Err(format!("Failed to decode X509 certificate: {}", err)); } + certs.push(cert); } } - certs.push(cert); buf.clear(); } diff --git a/tests/resources/test_config.toml b/tests/resources/test_config.toml index 7956f576..c6fdfbf0 100644 --- a/tests/resources/test_config.toml +++ b/tests/resources/test_config.toml @@ -8,7 +8,7 @@ protocol = "jmap" max-connections = 8192 [server.listener.imap] -bind = ["0.0.0.0:143"] +bind = ["0.0.0.0:9991"] protocol = "imap" max-connections = 8192 @@ -31,7 +31,7 @@ protocol = 'smtp' tls.implicit = true [server.listener.smtp] -bind = ['0.0.0.0:587'] +bind = ['0.0.0.0:9995'] greeting = 'Test SMTP instance' protocol = 'smtp' tls.implicit = false @@ -46,7 +46,8 @@ certificate = "default" [global.tracing] method = "stdout" -level = "trace" +#level = "trace" +level = "info" [session.ehlo] reject-non-fqdn = false