Просмотр исходного кода

bin/tau, bin/ircd: update crypto_box crate

Dastan-glitch 4 лет назад
Родитель
Сommit
62caeff37c

+ 40 - 31
Cargo.lock

@@ -25,12 +25,12 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
 
 [[package]]
 name = "aead"
-version = "0.4.3"
+version = "0.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877"
+checksum = "5c192eb8f11fc081b0fe4259ba5af04217d4e0faddd02417310a927911abd7c8"
 dependencies = [
+ "crypto-common",
  "generic-array",
- "rand_core 0.6.3",
 ]
 
 [[package]]
@@ -621,21 +621,20 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "chacha20"
-version = "0.8.2"
+version = "0.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6"
+checksum = "c7fc89c7c5b9e7a02dfe45cd2367bae382f9ed31c61ca8debe5f827c420a2f08"
 dependencies = [
  "cfg-if 1.0.0",
  "cipher",
  "cpufeatures",
- "zeroize",
 ]
 
 [[package]]
 name = "chacha20poly1305"
-version = "0.9.1"
+version = "0.10.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5"
+checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35"
 dependencies = [
  "aead",
  "chacha20",
@@ -660,11 +659,13 @@ dependencies = [
 
 [[package]]
 name = "cipher"
-version = "0.3.0"
+version = "0.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
+checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e"
 dependencies = [
- "generic-array",
+ "crypto-common",
+ "inout",
+ "zeroize",
 ]
 
 [[package]]
@@ -1033,6 +1034,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
 dependencies = [
  "generic-array",
+ "rand_core 0.6.3",
  "typenum",
 ]
 
@@ -1053,13 +1055,13 @@ dependencies = [
 
 [[package]]
 name = "crypto_box"
-version = "0.7.2"
+version = "0.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41d2bcbd5e4fc3ad3de2d0e75509f870a6fa9f488e0e2c9a8ce49721a52efc4e"
+checksum = "a09449badf787570305d9c659caa70249c92d57aa5cf31c1d8d3d628a6a57918"
 dependencies = [
+ "aead",
  "chacha20",
  "chacha20poly1305",
- "rand_core 0.6.3",
  "salsa20",
  "x25519-dalek",
  "xsalsa20poly1305",
@@ -1127,9 +1129,9 @@ dependencies = [
 
 [[package]]
 name = "curve25519-dalek"
-version = "3.2.1"
+version = "3.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0"
+checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61"
 dependencies = [
  "byteorder",
  "digest 0.9.0",
@@ -2273,6 +2275,15 @@ dependencies = [
  "unicode-width",
 ]
 
+[[package]]
+name = "inout"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
+dependencies = [
+ "generic-array",
+]
+
 [[package]]
 name = "instant"
 version = "0.1.12"
@@ -2971,9 +2982,9 @@ dependencies = [
 
 [[package]]
 name = "poly1305"
-version = "0.7.2"
+version = "0.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede"
+checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
 dependencies = [
  "cpufeatures",
  "opaque-debug",
@@ -3451,12 +3462,11 @@ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
 
 [[package]]
 name = "salsa20"
-version = "0.9.0"
+version = "0.10.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0c0fbb5f676da676c260ba276a8f43a8dc67cf02d1438423aeb1c677a7212686"
+checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213"
 dependencies = [
  "cipher",
- "zeroize",
 ]
 
 [[package]]
@@ -4355,11 +4365,11 @@ checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
 
 [[package]]
 name = "universal-hash"
-version = "0.4.1"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
+checksum = "7d3160b73c9a19f7e2939a2fdad446c57c1bbbbf4d919d3213ff1267a580d8b5"
 dependencies = [
- "generic-array",
+ "crypto-common",
  "subtle",
 ]
 
@@ -5039,9 +5049,9 @@ dependencies = [
 
 [[package]]
 name = "x25519-dalek"
-version = "1.2.0"
+version = "1.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2392b6b94a576b4e2bf3c5b2757d63f10ada8020a2e4d08ac849ebcf6ea8e077"
+checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f"
 dependencies = [
  "curve25519-dalek",
  "rand_core 0.5.1",
@@ -5050,13 +5060,12 @@ dependencies = [
 
 [[package]]
 name = "xsalsa20poly1305"
-version = "0.8.0"
+version = "0.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e68bcb965d6c650091450b95cea12f07dcd299a01c15e2f9433b0813ea3c0886"
+checksum = "472c385ee974833d7e59979eeb74175d56774be3768b5bcc581337e21396bda3"
 dependencies = [
  "aead",
  "poly1305",
- "rand_core 0.6.3",
  "salsa20",
  "subtle",
  "zeroize",
@@ -5085,9 +5094,9 @@ dependencies = [
 
 [[package]]
 name = "zeroize"
-version = "1.3.0"
+version = "1.5.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd"
+checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f"
 dependencies = [
  "zeroize_derive",
 ]

+ 1 - 1
bin/ircd/Cargo.toml

@@ -24,7 +24,7 @@ async-executor = "1.4.1"
 easy-parallel = "3.2.0"
 
 # Crypto
-crypto_box = "0.7.2"
+crypto_box = "0.8.0"
 rand = "0.8.5"
 
 # Misc

+ 10 - 7
bin/ircd/src/crypto.rs

@@ -1,4 +1,7 @@
-use crypto_box::aead::Aead;
+use crypto_box::{
+    aead::{Aead, AeadCore},
+    SalsaBox,
+};
 use fxhash::FxHashMap;
 use rand::rngs::OsRng;
 
@@ -6,7 +9,7 @@ use crate::{privmsg::Privmsg, settings::ChannelInfo, MAXIMUM_LENGTH_OF_NICKNAME}
 
 /// Try decrypting a message given a NaCl box and a base58 string.
 /// The format we're using is nonce+ciphertext, where nonce is 24 bytes.
-fn try_decrypt_message(salt_box: &crypto_box::Box, ciphertext: &str) -> Option<String> {
+fn try_decrypt_message(salt_box: &SalsaBox, ciphertext: &str) -> Option<String> {
     let bytes = match bs58::decode(ciphertext).into_vec() {
         Ok(v) => v,
         Err(_) => return None,
@@ -34,8 +37,8 @@ fn try_decrypt_message(salt_box: &crypto_box::Box, ciphertext: &str) -> Option<S
 
 /// Encrypt a message given a NaCl box and a plaintext string.
 /// The format we're using is nonce+ciphertext, where nonce is 24 bytes.
-pub fn encrypt_message(salt_box: &crypto_box::Box, plaintext: &str) -> String {
-    let nonce = crypto_box::generate_nonce(&mut OsRng);
+pub fn encrypt_message(salt_box: &SalsaBox, plaintext: &str) -> String {
+    let nonce = SalsaBox::generate_nonce(&mut OsRng);
     let mut ciphertext = salt_box.encrypt(&nonce, plaintext.as_bytes()).unwrap();
 
     let mut concat = vec![];
@@ -48,7 +51,7 @@ pub fn encrypt_message(salt_box: &crypto_box::Box, plaintext: &str) -> String {
 pub fn decrypt_target(
     privmsg: &mut Privmsg,
     configured_chans: FxHashMap<String, ChannelInfo>,
-    configured_contacts: FxHashMap<String, crypto_box::Box>,
+    configured_contacts: FxHashMap<String, SalsaBox>,
 ) {
     for chan_name in configured_chans.keys() {
         let chan_info = configured_chans.get(chan_name).unwrap();
@@ -85,7 +88,7 @@ pub fn decrypt_target(
 }
 
 /// Decrypt PrivMsg nickname and message
-pub fn decrypt_privmsg(salt_box: &crypto_box::Box, privmsg: &mut Privmsg) {
+pub fn decrypt_privmsg(salt_box: &SalsaBox, privmsg: &mut Privmsg) {
     let decrypted_nick = try_decrypt_message(&salt_box.clone(), &privmsg.nickname);
     let decrypted_msg = try_decrypt_message(&salt_box.clone(), &privmsg.message);
 
@@ -101,7 +104,7 @@ pub fn decrypt_privmsg(salt_box: &crypto_box::Box, privmsg: &mut Privmsg) {
 }
 
 /// Encrypt PrivMsg
-pub fn encrypt_privmsg(salt_box: &crypto_box::Box, privmsg: &mut Privmsg) {
+pub fn encrypt_privmsg(salt_box: &SalsaBox, privmsg: &mut Privmsg) {
     privmsg.nickname = encrypt_message(salt_box, &privmsg.nickname);
     privmsg.target = encrypt_message(salt_box, &privmsg.target);
     privmsg.message = encrypt_message(salt_box, &privmsg.message);

+ 2 - 2
bin/ircd/src/main.rs

@@ -56,7 +56,7 @@ struct Ircd {
     // channels
     autojoin_chans: Vec<String>,
     configured_chans: FxHashMap<String, ChannelInfo>,
-    configured_contacts: FxHashMap<String, crypto_box::Box>,
+    configured_contacts: FxHashMap<String, crypto_box::SalsaBox>,
     // p2p
     p2p: net::P2pPtr,
     senders: SubscriberPtr<Privmsg>,
@@ -68,7 +68,7 @@ impl Ircd {
         privmsgs_buffer: PrivmsgsBuffer,
         autojoin_chans: Vec<String>,
         configured_chans: FxHashMap<String, ChannelInfo>,
-        configured_contacts: FxHashMap<String, crypto_box::Box>,
+        configured_contacts: FxHashMap<String, crypto_box::SalsaBox>,
         p2p: net::P2pPtr,
     ) -> Self {
         let senders = Subscriber::new();

+ 2 - 2
bin/ircd/src/server.rs

@@ -34,7 +34,7 @@ pub struct IrcServerConnection<C: AsyncRead + AsyncWrite + Send + Unpin + 'stati
     nickname: String,
     auto_channels: Vec<String>,
     pub configured_chans: FxHashMap<String, ChannelInfo>,
-    pub configured_contacts: FxHashMap<String, crypto_box::Box>,
+    pub configured_contacts: FxHashMap<String, crypto_box::SalsaBox>,
     capabilities: FxHashMap<String, bool>,
     // p2p
     p2p: P2pPtr,
@@ -51,7 +51,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C>
         privmsgs_buffer: PrivmsgsBuffer,
         auto_channels: Vec<String>,
         configured_chans: FxHashMap<String, ChannelInfo>,
-        configured_contacts: FxHashMap<String, crypto_box::Box>,
+        configured_contacts: FxHashMap<String, crypto_box::SalsaBox>,
         p2p: P2pPtr,
         senders: SubscriberPtr<Privmsg>,
         subscriber_id: u64,

+ 5 - 4
bin/ircd/src/settings.rs

@@ -1,3 +1,4 @@
+use crypto_box::SalsaBox;
 use fxhash::FxHashMap;
 use log::info;
 use serde::Deserialize;
@@ -68,7 +69,7 @@ pub struct ChannelInfo {
     /// Optional topic for the channel
     pub topic: Option<String>,
     /// Optional NaCl box for the channel, used for {en,de}cryption.
-    pub salt_box: Option<crypto_box::Box>,
+    pub salt_box: Option<SalsaBox>,
     /// Flag indicates whether the user has joined the channel or not
     pub joined: bool,
     /// All nicknames which are visible on the channel
@@ -81,11 +82,11 @@ impl ChannelInfo {
     }
 }
 
-fn salt_box_from_shared_secret(s: &str) -> Result<crypto_box::Box> {
+fn salt_box_from_shared_secret(s: &str) -> Result<SalsaBox> {
     let bytes: [u8; 32] = bs58::decode(s).into_vec()?.try_into().unwrap();
     let secret = crypto_box::SecretKey::from(bytes);
     let public = secret.public_key();
-    Ok(crypto_box::Box::new(&public, &secret))
+    Ok(SalsaBox::new(&public, &secret))
 }
 
 /// Parse a TOML string for any configured contact list and return
@@ -95,7 +96,7 @@ fn salt_box_from_shared_secret(s: &str) -> Result<crypto_box::Box> {
 /// [contact."7CkVuFgwTUpJn5Sv67Q3fyEDpa28yrSeL5Hg2GqQ4jfM"]
 /// nicks = ["sneed", "chuck"]
 /// ```
-pub fn parse_configured_contacts(data: &str) -> Result<FxHashMap<String, crypto_box::Box>> {
+pub fn parse_configured_contacts(data: &str) -> Result<FxHashMap<String, SalsaBox>> {
     let mut ret = FxHashMap::default();
 
     if let Value::Table(map) = toml::from_str(data)? {

+ 1 - 1
bin/tau/taud/Cargo.toml

@@ -37,7 +37,7 @@ serde = {version = "1.0.142", features = ["derive"]}
 serde_json = "1.0.83"
 structopt = "0.3.26"
 structopt-toml = "0.5.1"
-crypto_box = {version = "0.7.2", features = ["std"]}
+crypto_box = {version = "0.8.0", features = ["std"]}
 hex = "0.4.3"
 bs58 = "0.4.0"
 toml = "0.5.9"

+ 7 - 4
bin/tau/taud/src/main.rs

@@ -2,7 +2,10 @@ use async_std::sync::{Arc, Mutex};
 use std::{env, fs::create_dir_all};
 
 use async_executor::Executor;
-use crypto_box::{aead::Aead, Box, SecretKey};
+use crypto_box::{
+    aead::{Aead, AeadCore},
+    SalsaBox, SecretKey,
+};
 use futures::{select, FutureExt};
 use fxhash::FxHashMap;
 use log::{debug, error, info, warn};
@@ -47,12 +50,12 @@ pub struct EncryptedTask {
 fn encrypt_task(
     task: &TaskInfo,
     workspace: &String,
-    salsa_box: &Box,
+    salsa_box: &SalsaBox,
     rng: &mut crypto_box::rand_core::OsRng,
 ) -> TaudResult<EncryptedTask> {
     debug!("start encrypting task");
 
-    let nonce = crypto_box::generate_nonce(rng);
+    let nonce = SalsaBox::generate_nonce(rng);
     let payload = &serialize(task)[..];
     let payload = salsa_box.encrypt(&nonce, payload)?;
 
@@ -60,7 +63,7 @@ fn encrypt_task(
     Ok(EncryptedTask { workspace: workspace.to_string(), nonce, payload })
 }
 
-fn decrypt_task(encrypt_task: &EncryptedTask, salsa_box: &Box) -> TaudResult<TaskInfo> {
+fn decrypt_task(encrypt_task: &EncryptedTask, salsa_box: &SalsaBox) -> TaudResult<TaskInfo> {
     debug!("start decrypting task");
 
     let nonce = encrypt_task.nonce.as_slice();

+ 2 - 2
bin/tau/taud/src/util.rs

@@ -7,7 +7,7 @@ use darkfi::Result;
 
 #[derive(Clone)]
 pub struct Workspace {
-    pub encryption: Option<crypto_box::Box>,
+    pub encryption: Option<crypto_box::SalsaBox>,
 }
 
 impl Workspace {
@@ -34,7 +34,7 @@ pub fn parse_workspaces(config_file: &PathBuf) -> Result<FxHashMap<String, Works
                     let bytes: [u8; 32] = bs58::decode(s).into_vec()?.try_into().unwrap();
                     let secret = crypto_box::SecretKey::from(bytes);
                     let public = secret.public_key();
-                    let msg_box = crypto_box::Box::new(&public, &secret);
+                    let msg_box = crypto_box::SalsaBox::new(&public, &secret);
                     workspace_info.encryption = Some(msg_box);
                     info!("Instantiated NaCl box for workspace {}", ws.0);
                 }