diff --git a/crates/chat_ui/src/lib.rs b/crates/chat_ui/src/lib.rs index 221b1e8c..afd44aec 100644 --- a/crates/chat_ui/src/lib.rs +++ b/crates/chat_ui/src/lib.rs @@ -2089,6 +2089,20 @@ impl Render for ChatPanel { .children(self.render_attachment_list(window, cx)) .children(self.render_pending_file_list(window, cx)) .children(self.render_reply_list(window, cx)) + .when( + !self.input.read(cx).value().trim().is_empty(), + |this| { + this.child( + div() + .px_1() + .text_xs() + .text_color(cx.theme().text_warning) + .child( + "Attachments added while typing are uploaded without encryption", + ), + ) + }, + ) .child( h_flex() .items_end() diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index 150ae199..df86e28a 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -12,6 +12,9 @@ pub fn init(window: &mut Window, cx: &mut App) { AppSettings::set_global(cx.new(|cx| AppSettings::new(window, cx)), cx) } +const DEFAULT_FILE_SERVER: &str = "https://nostr.download/"; +const LEGACY_FILE_SERVER: &str = "blossom.band"; + macro_rules! setting_accessors { ($(pub $field:ident: $type:ty),* $(,)?) => { impl AppSettings { @@ -138,7 +141,7 @@ impl Default for Settings { screening: true, nip4e: false, trusted_relays: vec![], - file_server: Url::parse("https://blossom.band/").unwrap(), + file_server: Url::parse(DEFAULT_FILE_SERVER).unwrap(), } } } @@ -217,7 +220,12 @@ impl AppSettings { }); cx.spawn_in(window, async move |this, cx| { - let settings = task.await.unwrap_or(Settings::default()); + let mut settings = task.await.unwrap_or(Settings::default()); + + // Move settings still pointed at the old default file server over to the new one + if settings.file_server.host_str() == Some(LEGACY_FILE_SERVER) { + settings.file_server = Url::parse(DEFAULT_FILE_SERVER).unwrap(); + } // Update settings this.update_in(cx, |this, window, cx| { diff --git a/crates/state/src/file.rs b/crates/state/src/file.rs index 06ae44d5..7ef69b88 100644 --- a/crates/state/src/file.rs +++ b/crates/state/src/file.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use aes_gcm::aead::consts::{U12, U16}; +use aes_gcm::aead::consts::{U12, U16, U32}; use aes_gcm::aead::{Aead, AeadCore, KeyInit, OsRng}; use aes_gcm::aes::Aes256; use aes_gcm::{Aes256Gcm, AesGcm, Nonce}; @@ -121,8 +121,8 @@ impl FileAttachment { pub fn encrypt(data: &[u8]) -> Result { let key = Aes256Gcm::generate_key(OsRng); - let nonce = Aes256Gcm::generate_nonce(OsRng); - let cipher = Aes256Gcm::new(&key); + let nonce = AesGcm::::generate_nonce(OsRng); + let cipher = AesGcm::::new(&key); let data = cipher .encrypt(&nonce, data) @@ -146,7 +146,6 @@ pub fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result, Error> { ); } - // Amethyst uses 16 bytes nonces, everything else uses the standard 12 match nonce.len() { 12 => Aes256Gcm::new_from_slice(&key) .map_err(|_| anyhow!("Invalid decryption key"))? @@ -156,6 +155,10 @@ pub fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result, Error> { .map_err(|_| anyhow!("Invalid decryption key"))? .decrypt(Nonce::::from_slice(&nonce), data) .map_err(|_| anyhow!("Failed to decrypt file")), + 32 => AesGcm::::new_from_slice(&key) + .map_err(|_| anyhow!("Invalid decryption key"))? + .decrypt(Nonce::::from_slice(&nonce), data) + .map_err(|_| anyhow!("Failed to decrypt file")), len => bail!("Unsupported decryption nonce length: {len} bytes"), } }