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。

fix(import): decrypt Navicat passwords over HTTP

t8y29c95f0af34f9
diff --git a/apps/desktop/src/lib/__tests__/imports/navicatImport.spec.ts b/apps/desktop/src/lib/__tests__/imports/navicatImport.spec.ts
index e2729ff3b5..309fa172b1 100644
--- a/apps/desktop/src/lib/__tests__/imports/navicatImport.spec.ts
+++ b/apps/desktop/src/lib/__tests__/imports/navicatImport.spec.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { parseNavicatConnections } from "@/lib/imports/navicatImport";
class TestElement {
@@ -75,6 +75,10 @@ if (!globalThis.DOMParser) {
globalThis.DOMParser = TestDOMParser as typeof DOMParser;
}
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
describe("parseNavicatConnections", () => {
it("imports SQLite DatabaseFile as the host without treating it as a schema", async () => {
const [connection] = await parseNavicatConnections(`<Connections>
@@ -155,6 +159,17 @@ describe("parseNavicatConnections", () => {
]);
});
+ it("decrypts Navicat passwords without SubtleCrypto in insecure HTTP contexts", async () => {
+ const databasePassword = await encryptNavicatPassword("database-secret");
+ vi.stubGlobal("crypto", {});
+
+ const [connection] = await parseNavicatConnections(`<Connections>
+ <Connection ConnType="ORACLE" ConnectionName="oracle-http" Host="db.internal" UserName="app" Password="${databasePassword}" />
+</Connections>`);
+
+ expect(connection?.password).toBe("database-secret");
+ });
+
it("imports key-authenticated SSH field variants with the default port", async () => {
const keyPassphrase = await encryptNavicatPassword("key-secret");
const [connection] = await parseNavicatConnections(`<Connections>
diff --git a/apps/desktop/src/lib/imports/navicatImport.ts b/apps/desktop/src/lib/imports/navicatImport.ts
index b2b50c44c3..05554cf2b0 100644
--- a/apps/desktop/src/lib/imports/navicatImport.ts
+++ b/apps/desktop/src/lib/imports/navicatImport.ts
@@ -44,6 +44,7 @@ const typeMap: Record<string, { dbType: DatabaseType; profile: string; label: st
};
const unsupportedTypes = new Set(["http", "https", "ftp", "sftp", "ssh"]);
+let navicatCipherModule: Promise<typeof import("@noble/ciphers/aes.js")> | undefined;
function normalizeKey(value: string) {
return value.toLowerCase().replace(/[^a-z0-9]/g, "");
@@ -96,14 +97,24 @@ async function decryptNavicatPassword(value: string) {
const key = new TextEncoder().encode("libcckeylibcckey");
const iv = new TextEncoder().encode("libcciv libcciv ");
try {
- const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
- const decrypted = new Uint8Array(await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, encrypted));
+ const subtle = globalThis.crypto?.subtle;
+ const decrypted = subtle ? await decryptNavicatPasswordWithWebCrypto(subtle, encrypted, key, iv) : await decryptNavicatPasswordWithoutWebCrypto(encrypted, key, iv);
return new TextDecoder().decode(stripPkcs7(decrypted));
} catch {
return "";
}
}
+async function decryptNavicatPasswordWithWebCrypto(subtle: SubtleCrypto, encrypted: Uint8Array<ArrayBuffer>, key: Uint8Array<ArrayBuffer>, iv: Uint8Array<ArrayBuffer>) {
+ const cryptoKey = await subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
+ return new Uint8Array(await subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, encrypted));
+}
+
+async function decryptNavicatPasswordWithoutWebCrypto(encrypted: Uint8Array<ArrayBuffer>, key: Uint8Array<ArrayBuffer>, iv: Uint8Array<ArrayBuffer>) {
+ const { cbc } = await (navicatCipherModule ??= import("@noble/ciphers/aes.js"));
+ return cbc(key, iv).decrypt(encrypted);
+}
+
function parseNavicatPort(value: string, fallback: number) {
const port = Number(value);
return Number.isInteger(port) && port > 0 && port <= 65535 ? port : fallback;
diff --git a/package.json b/package.json
index 2b492032ad..981c0f4956 100644
--- a/package.json
+++ b/package.json
@@ -59,6 +59,7 @@
"@lezer/highlight": "^1.2.3",
"@lucide/vue": "1.17.0",
"@msgpack/msgpack": "^3.1.3",
+ "@noble/ciphers": "2.2.0",
"@replit/codemirror-vim": "^6.3.0",
"@tauri-apps/api": "^2.11.0",
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 04da636603..fa55647e68 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -65,6 +65,9 @@ importers:
'@msgpack/msgpack':
specifier: ^3.1.3
version: 3.1.3
+ '@noble/ciphers':
+ specifier: 2.2.0
+ version: 2.2.0
'@replit/codemirror-vim':
specifier: ^6.3.0
version: 6.3.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])
@@ -912,6 +915,10 @@ packages:
resolution: {integrity: sha512-47XIizs9XZXvuJgoaJUIE2lFoID8ugvc0jzSHP+Ptfk8nTbnR8g788wv48N03Kx0UkAv559HWRQ3yzOgzlRNUA==}
engines: {node: '>= 18'}
+ '@noble/[email protected]':
+ resolution: {integrity: sha512-Z6pjIZ/8IJcCGzb2S/0Px5J81yij85xASuk1teLNeg75bfT07MV3a/O2Mtn1I2se43k3lkVEcFaR10N4cgQcZA==}
+ engines: {node: '>= 20.19.0'}
+
'@napi-rs/[email protected]':
resolution: {integrity: sha512-3NQNNgA1YSlJb/kMH1ildASP9HW7/7kYnRI2szWJaofaS1hWmbGI4H+d3+22aGzXXN9IJ+n+GiFVcGipJP18ow==}
peerDependencies:
@@ -4529,6 +4536,8 @@ snapshots:
'@msgpack/[email protected]': {}
+ '@noble/[email protected]': {}
+
dependencies:
'@emnapi/core': 1.10.0