Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat: add SSL/TLS support for Redis connections and update related configurations

t8y2b325cc50c454
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index c286c7a39c..73e3711757 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -1123,6 +1123,7 @@ dependencies = [
"portpicker",
"redis",
"reqwest 0.12.28",
+ "rustls",
"serde",
"serde_json",
"sqlx",
@@ -4371,10 +4372,13 @@ dependencies = [
"num-bigint",
"percent-encoding",
"pin-project-lite",
+ "rustls",
+ "rustls-native-certs",
"ryu",
"sha1_smol",
"socket2",
"tokio",
+ "tokio-rustls",
"tokio-util",
"url",
]
@@ -4723,6 +4727,18 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "rustls-native-certs"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63"
+dependencies = [
+ "openssl-probe",
+ "rustls-pki-types",
+ "schannel",
+ "security-framework",
+]
+
[[package]]
name = "rustls-pemfile"
version = "2.2.0"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index d909cab74f..07bff8647f 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -35,7 +35,8 @@ chrono = { version = "0.4", features = ["serde"] }
tauri-plugin-dialog = "2.7.0"
tauri-plugin-fs = "2.5.0"
tauri-plugin-shell = "2"
-redis = { version = "0.32.2", features = ["tokio-comp"] }
+redis = { version = "0.32.2", features = ["tokio-comp", "tls-rustls", "tokio-rustls-comp"] }
+rustls = { version = "0.23", features = ["aws-lc-rs"] }
portpicker = "0.1.1"
duckdb = { version = "1.3.2", features = ["bundled"] }
tiberius = { version = "0.12.3", features = ["tds73", "chrono"] }
diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rs
index d167a95420..2a59df6a46 100644
--- a/src-tauri/src/commands/connection.rs
+++ b/src-tauri/src/commands/connection.rs
@@ -179,6 +179,7 @@ pub async fn load_connections(app: AppHandle) -> Result<Vec<ConnectionConfig>, S
#[tauri::command]
pub async fn test_connection(config: ConnectionConfig) -> Result<String, String> {
let url = config.connection_url();
+ log::info!("[test_connection] db_type={:?} url={}", config.db_type, &url[..url.len().min(80)]);
match config.db_type {
DatabaseType::Mysql => {
let pool = db::mysql::connect(&url).await?;
diff --git a/src-tauri/src/db/redis_driver.rs b/src-tauri/src/db/redis_driver.rs
index 3f47bc1616..e9cf6b76c3 100644
--- a/src-tauri/src/db/redis_driver.rs
+++ b/src-tauri/src/db/redis_driver.rs
@@ -18,10 +18,13 @@ pub struct RedisValue {
pub async fn connect(url: &str) -> Result<redis::aio::MultiplexedConnection, String> {
let client = redis::Client::open(url).map_err(|e| format!("Redis connection failed: {e}"))?;
- client
- .get_multiplexed_async_connection()
- .await
- .map_err(|e| format!("Redis connection failed: {e}"))
+ tokio::time::timeout(
+ std::time::Duration::from_secs(10),
+ client.get_multiplexed_async_connection(),
+ )
+ .await
+ .map_err(|_| "Redis connection timed out (10s)".to_string())?
+ .map_err(|e| format!("Redis connection failed: {e}"))
}
pub async fn list_databases(con: &mut redis::aio::MultiplexedConnection) -> Result<Vec<u32>, String> {
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 15f1326bba..8806375248 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -7,6 +7,10 @@ use std::sync::Arc;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
+ rustls::crypto::aws_lc_rs::default_provider()
+ .install_default()
+ .expect("Failed to install rustls crypto provider");
+
let state = Arc::new(AppState::new());
tauri::Builder::default()
diff --git a/src-tauri/src/models/connection.rs b/src-tauri/src/models/connection.rs
index f0c12d90aa..db7c3017d7 100644
--- a/src-tauri/src/models/connection.rs
+++ b/src-tauri/src/models/connection.rs
@@ -23,6 +23,8 @@ pub struct ConnectionConfig {
pub ssh_password: String,
#[serde(default)]
pub ssh_key_path: String,
+ #[serde(default)]
+ pub ssl: bool,
}
fn default_ssh_port() -> u16 { 22 }
@@ -66,10 +68,13 @@ impl ConnectionConfig {
format!("{}?mode=rwc", self.host)
}
DatabaseType::Redis => {
- if self.password.is_empty() {
- format!("redis://{host}:{port}/")
+ let scheme = if self.ssl { "rediss" } else { "redis" };
+ if self.username.is_empty() && self.password.is_empty() {
+ format!("{scheme}://{host}:{port}/")
+ } else if self.username.is_empty() {
+ format!("{scheme}://:{password}@{host}:{port}/")
} else {
- format!("redis://:{password}@{host}:{port}/")
+ format!("{scheme}://{username}:{password}@{host}:{port}/")
}
}
DatabaseType::Mysql => format!(
@@ -126,6 +131,7 @@ mod tests {
ssh_user: String::new(),
ssh_password: String::new(),
ssh_key_path: String::new(),
+ ssl: false,
}
}
diff --git a/src/components/connection/ConnectionDialog.vue b/src/components/connection/ConnectionDialog.vue
index 2cf618825c..4793fa4f44 100644
--- a/src/components/connection/ConnectionDialog.vue
+++ b/src/components/connection/ConnectionDialog.vue
@@ -42,6 +42,7 @@ const defaultForm = (): Omit<ConnectionConfig, "id"> => ({
ssh_user: "",
ssh_password: "",
ssh_key_path: "",
+ ssl: false,
});
const form = ref(defaultForm());
@@ -64,6 +65,7 @@ watch(() => props.editConfig, (config) => {
ssh_user: config.ssh_user || "",
ssh_password: config.ssh_password || "",
ssh_key_path: config.ssh_key_path || "",
+ ssl: config.ssl || false,
};
selectedType.value = config.db_type;
} else {
@@ -156,22 +158,34 @@ async function testConnection() {
}
}
-async function save() {
- if (editingId.value) {
- const updated: ConnectionConfig = { ...form.value, id: editingId.value };
- store.updateConnection(updated);
- open.value = false;
- } else {
- const config: ConnectionConfig = { ...form.value, id: crypto.randomUUID() };
- store.addConnection(config);
- await store.connect(config);
- open.value = false;
- }
+function resetForm() {
editingId.value = null;
form.value = defaultForm();
+ selectedType.value = "mysql";
testResult.value = null;
}
+watch(open, (value) => {
+ if (!value) resetForm();
+});
+
+async function save() {
+ try {
+ if (editingId.value) {
+ const updated: ConnectionConfig = { ...form.value, id: editingId.value };
+ store.updateConnection(updated);
+ store.stopEditing();
+ } else {
+ const config: ConnectionConfig = { ...form.value, id: crypto.randomUUID() };
+ store.addConnection(config);
+ await store.connect(config);
+ }
+ open.value = false;
+ } catch (e) {
+ console.error("[save] error:", e);
+ }
+}
+
const dialogTitle = ref("");
watch([() => editingId.value, () => open.value], () => {
dialogTitle.value = editingId.value ? t('connection.editTitle') : t('connection.title');
@@ -239,17 +253,28 @@ watch([() => editingId.value, () => open.value], () => {
</div>
</template>
- <!-- Redis: host, port, password -->
+ <!-- Redis: host, port, user, password, ssl -->
<template v-else-if="form.db_type === 'redis'">
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right">{{ t('connection.host') }}</Label>
<Input v-model="form.host" class="col-span-2" />
<Input v-model.number="form.port" type="number" class="col-span-1" />
</div>
+ <div class="grid grid-cols-4 items-center gap-4">
+ <Label class="text-right">{{ t('connection.user') }}</Label>
+ <Input v-model="form.username" class="col-span-3" placeholder="default" />
+ </div>
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right">{{ t('connection.password') }}</Label>
<Input v-model="form.password" type="password" class="col-span-3" :placeholder="t('connection.databasePlaceholder')" />
</div>
+ <div class="grid grid-cols-4 items-center gap-4">
+ <Label class="text-right text-xs">SSL/TLS</Label>
+ <div class="col-span-3">
+ <input type="checkbox" v-model="form.ssl" class="mr-2" />
+ <span class="text-xs text-muted-foreground">{{ t('connection.sshEnable') }}</span>
+ </div>
+ </div>
</template>
<!-- MySQL / PostgreSQL: host, port, user, password, database -->
diff --git a/src/types/database.ts b/src/types/database.ts
index cf59ce9e20..504d818d7d 100644
--- a/src/types/database.ts
+++ b/src/types/database.ts
@@ -15,6 +15,7 @@ export interface ConnectionConfig {
ssh_user?: string;
ssh_password?: string;
ssh_key_path?: string;
+ ssl?: boolean;
}
export interface DatabaseInfo {