update
This commit is contained in:
@@ -2089,6 +2089,20 @@ impl Render for ChatPanel {
|
|||||||
.children(self.render_attachment_list(window, cx))
|
.children(self.render_attachment_list(window, cx))
|
||||||
.children(self.render_pending_file_list(window, cx))
|
.children(self.render_pending_file_list(window, cx))
|
||||||
.children(self.render_reply_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(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.items_end()
|
.items_end()
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ pub fn init(window: &mut Window, cx: &mut App) {
|
|||||||
AppSettings::set_global(cx.new(|cx| AppSettings::new(window, cx)), cx)
|
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 {
|
macro_rules! setting_accessors {
|
||||||
($(pub $field:ident: $type:ty),* $(,)?) => {
|
($(pub $field:ident: $type:ty),* $(,)?) => {
|
||||||
impl AppSettings {
|
impl AppSettings {
|
||||||
@@ -138,7 +141,7 @@ impl Default for Settings {
|
|||||||
screening: true,
|
screening: true,
|
||||||
nip4e: false,
|
nip4e: false,
|
||||||
trusted_relays: vec![],
|
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| {
|
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
|
// Update settings
|
||||||
this.update_in(cx, |this, window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
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::aead::{Aead, AeadCore, KeyInit, OsRng};
|
||||||
use aes_gcm::aes::Aes256;
|
use aes_gcm::aes::Aes256;
|
||||||
use aes_gcm::{Aes256Gcm, AesGcm, Nonce};
|
use aes_gcm::{Aes256Gcm, AesGcm, Nonce};
|
||||||
@@ -121,8 +121,8 @@ impl FileAttachment {
|
|||||||
|
|
||||||
pub fn encrypt(data: &[u8]) -> Result<EncryptedFile, Error> {
|
pub fn encrypt(data: &[u8]) -> Result<EncryptedFile, Error> {
|
||||||
let key = Aes256Gcm::generate_key(OsRng);
|
let key = Aes256Gcm::generate_key(OsRng);
|
||||||
let nonce = Aes256Gcm::generate_nonce(OsRng);
|
let nonce = AesGcm::<Aes256, U16>::generate_nonce(OsRng);
|
||||||
let cipher = Aes256Gcm::new(&key);
|
let cipher = AesGcm::<Aes256, U16>::new(&key);
|
||||||
|
|
||||||
let data = cipher
|
let data = cipher
|
||||||
.encrypt(&nonce, data)
|
.encrypt(&nonce, data)
|
||||||
@@ -146,7 +146,6 @@ pub fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result<Vec<u8>, Error> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Amethyst uses 16 bytes nonces, everything else uses the standard 12
|
|
||||||
match nonce.len() {
|
match nonce.len() {
|
||||||
12 => Aes256Gcm::new_from_slice(&key)
|
12 => Aes256Gcm::new_from_slice(&key)
|
||||||
.map_err(|_| anyhow!("Invalid decryption key"))?
|
.map_err(|_| anyhow!("Invalid decryption key"))?
|
||||||
@@ -156,6 +155,10 @@ pub fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result<Vec<u8>, Error> {
|
|||||||
.map_err(|_| anyhow!("Invalid decryption key"))?
|
.map_err(|_| anyhow!("Invalid decryption key"))?
|
||||||
.decrypt(Nonce::<U16>::from_slice(&nonce), data)
|
.decrypt(Nonce::<U16>::from_slice(&nonce), data)
|
||||||
.map_err(|_| anyhow!("Failed to decrypt file")),
|
.map_err(|_| anyhow!("Failed to decrypt file")),
|
||||||
|
32 => AesGcm::<Aes256, U32>::new_from_slice(&key)
|
||||||
|
.map_err(|_| anyhow!("Invalid decryption key"))?
|
||||||
|
.decrypt(Nonce::<U32>::from_slice(&nonce), data)
|
||||||
|
.map_err(|_| anyhow!("Failed to decrypt file")),
|
||||||
len => bail!("Unsupported decryption nonce length: {len} bytes"),
|
len => bail!("Unsupported decryption nonce length: {len} bytes"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user