feat: prepare 3.0.5 with refreshed icons and dependency updates

This commit is contained in:
Kevin Yue committed 2026-10-13 16:34:10 +08:00
1 parent 10139e0f2c
commit 18ed6bac1a
31 files changed
+354 -219

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ uzers = { workspace = true, optional = true }
tauri = { workspace = true, optional = true }
regex = { workspace = true, optional = true }
tokio-util = { workspace = true, optional = true }
html-escape = { version = "0.2.13", optional = true }
html-escape = { version = "0.3", optional = true }
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
webkit2gtk = { version = "2", optional = true }
+40 -19
View File
@@ -1,8 +1,9 @@
use std::{ffi::OsStr, os::raw::c_void, path::PathBuf, thread, time::Duration};
use std::{ffi::OsStr, os::raw::c_void, path::PathBuf, sync::mpsc};
use anyhow::{Context, bail};
use block2::RcBlock;
use objc2_app_kit::NSWorkspace;
use objc2_foundation::{NSBundle, NSString, NSURL};
use objc2_foundation::{NSBundle, NSDate, NSError, NSRunLoop, NSString, NSURL};
const CALLBACK_SCHEME: &str = "globalprotectcallback";
const CALLBACK_URL: &str = "globalprotectcallback:";
@@ -15,18 +16,19 @@ unsafe extern "C" {
}
pub(super) fn ensure_auth_callback_handler() -> anyhow::Result<()> {
set_auth_callback_handler().map_err(|error| {
log::warn!("Failed to set up browser sign-in: {error:#}");
anyhow::anyhow!("Couldn’t set up browser sign-in. Please try again.")
})
}
fn set_auth_callback_handler() -> anyhow::Result<()> {
let workspace = NSWorkspace::sharedWorkspace();
let app_paths = callback_app_paths();
let selected_handler = current_handler(&workspace);
match selected_handler.as_ref() {
Some((handler, path))
if handler == HANDLER_BUNDLE_ID && app_paths.iter().any(|candidate| same_path(candidate, path)) =>
{
return Ok(());
}
Some((handler, _)) if handler == HANDLER_BUNDLE_ID => {}
None => {}
Some((handler, _)) => bail!("The globalprotectcallback URL scheme is owned by {handler}"),
if current_handler(&workspace).is_some_and(|(handler, path)| {
handler == HANDLER_BUNDLE_ID && app_paths.iter().any(|candidate| same_path(candidate, &path))
}) {
return Ok(());
}
let app_path = app_paths
@@ -34,21 +36,40 @@ pub(super) fn ensure_auth_callback_handler() -> anyhow::Result<()> {
.context("GP Connect Login.app is required for external-browser authentication; install GP Connect")?;
let app_url = file_url(app_path);
register_app(&app_url)?;
let (sender, receiver) = mpsc::channel();
let completion = RcBlock::new(move |error: *mut NSError| {
// The error is valid for the duration of Apple's completion callback.
let result = match unsafe { error.as_ref() } {
Some(error) => Err(anyhow::anyhow!("{}", error.localizedDescription())),
None => Ok(()),
};
let _ = sender.send(result);
});
workspace.setDefaultApplicationAtURL_toOpenURLsWithScheme_completionHandler(
&app_url,
&NSString::from_str(CALLBACK_SCHEME),
None,
Some(&completion),
);
for _ in 0..50 {
if current_handler(&workspace)
.is_some_and(|(handler, path)| handler == HANDLER_BUNDLE_ID && same_path(app_path, &path))
{
return Ok(());
// macOS may ask for consent. Keep its run loop active until the operation
// completes rather than imposing a deadline on the user's response.
let run_loop = NSRunLoop::currentRunLoop();
loop {
match receiver.try_recv() {
Ok(result) => {
result?;
break;
}
Err(mpsc::TryRecvError::Empty) => run_loop.runUntilDate(&NSDate::dateWithTimeIntervalSinceNow(0.1)),
Err(mpsc::TryRecvError::Disconnected) => bail!("The URL handler setup completion was lost"),
}
thread::sleep(Duration::from_millis(100));
}
if current_handler(&workspace)
.is_some_and(|(handler, path)| handler == HANDLER_BUNDLE_ID && same_path(app_path, &path))
{
return Ok(());
}
bail!("The globalprotectcallback URL handler registration did not take effect")
}
+3 -3
View File
@@ -20,13 +20,13 @@ xmltree.workspace = true
serde.workspace = true
specta = { workspace = true, features = ["derive", "uuid"] }
urlencoding.workspace = true
tokio = { workspace = true, features = ["process", "signal", "macros"] }
tokio = { workspace = true, features = ["fs", "process", "signal", "macros"] }
tokio-util.workspace = true
serde_json.workspace = true
whoami.workspace = true
tempfile.workspace = true
thiserror.workspace = true
chacha20poly1305 = { version = "0.10", features = ["std"] }
chacha20poly1305 = { version = "0.11", features = ["zeroize"] }
redact-engine.workspace = true
url.workspace = true
regex.workspace = true
@@ -34,7 +34,7 @@ uzers.workspace = true
serde_urlencoded.workspace = true
md5.workspace = true
sha256.workspace = true
sha2 = "0.10"
sha2 = { version = "0.11", default-features = false }
uuid = { workspace = true, features = ["v4", "v5", "serde"] }
chrono.workspace = true
humantime.workspace = true
+28 -7
View File
@@ -1,11 +1,11 @@
use chacha20poly1305::{
AeadCore, ChaCha20Poly1305, Key, KeyInit,
aead::{Aead, OsRng},
ChaCha20Poly1305, Key, KeyInit, Nonce,
aead::{Aead, Generate},
};
use serde::{Serialize, de::DeserializeOwned};
pub fn generate_key() -> Key {
ChaCha20Poly1305::generate_key(&mut OsRng)
Key::generate()
}
pub fn encrypt<T>(key: &Key, value: &T) -> anyhow::Result<Vec<u8>>
@@ -13,7 +13,7 @@ where
T: Serialize,
{
let cipher = ChaCha20Poly1305::new(key);
let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng);
let nonce = Nonce::generate();
let data = serde_json::to_vec(value)?;
let cipher_text = cipher.encrypt(&nonce, data.as_ref())?;
@@ -34,7 +34,7 @@ where
let nonce = &encrypted[..12];
let cipher_text = &encrypted[12..];
let plaintext = cipher.decrypt(nonce.into(), cipher_text)?;
let plaintext = cipher.decrypt(nonce.try_into()?, cipher_text)?;
let value = serde_json::from_slice(&plaintext)?;
@@ -52,14 +52,14 @@ impl Crypto {
pub fn encrypt<T: Serialize>(&self, plain: T) -> anyhow::Result<Vec<u8>> {
let key: &[u8] = &self.key;
let encrypted_data = encrypt(key.into(), &plain)?;
let encrypted_data = encrypt(key.try_into()?, &plain)?;
Ok(encrypted_data)
}
pub fn decrypt<T: DeserializeOwned>(&self, encrypted: Vec<u8>) -> anyhow::Result<T> {
let key: &[u8] = &self.key;
decrypt(key.into(), encrypted)
decrypt(key.try_into()?, encrypted)
}
pub fn encrypt_to<T: Serialize>(&self, path: &std::path::Path, plain: T) -> anyhow::Result<()> {
@@ -105,4 +105,25 @@ mod tests {
Ok(())
}
#[test]
fn decrypts_settings_written_with_chacha20poly1305_0_10() -> anyhow::Result<()> {
// Fixed key and ciphertext are test data produced with version 0.10.1.
let key = [7_u8; 32];
let encrypted =
crate::utils::base64::decode_to_vec("AwMDAwMDAwMDAwMDkIQjBvvxesN7T/Suv8tEE53zfpGGup/QlB6Dbj1ah+NIXCDMOv/4eg==")?;
let user: User = decrypt((&key).into(), encrypted.clone())?;
assert_eq!(user.name, "test");
assert_eq!(user.age, 18);
// The nonce prefix and appended authentication tag retain their existing format.
let cipher = ChaCha20Poly1305::new((&key).into());
let ciphertext = cipher.encrypt(encrypted[..12].try_into()?, serde_json::to_vec(&user)?.as_slice())?;
assert_eq!(ciphertext, encrypted[12..]);
let mut tampered = encrypted;
*tampered.last_mut().unwrap() ^= 1;
assert!(decrypt::<User>((&key).into(), tampered).is_err());
Ok(())
}
}