Skip to content

Commit fed532b

Browse files
Merge pull request #60 from unsafe9/fix/desktop-multi-safe-storage
Fix import-desktop extracting from wrong Slack installation on macOS
2 parents a0923fa + 5d143d6 commit fed532b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/auth/desktop.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,25 @@ async function extractTeamsFromSlackLevelDb(leveldbDir: string): Promise<Desktop
263263

264264
function getSafeStoragePasswords(prefix: string): string[] {
265265
if (IS_MACOS) {
266-
const services = ["Slack Safe Storage", "Chrome Safe Storage", "Chromium Safe Storage"];
266+
// Electron ("Slack Key") and Mac App Store ("Slack App Store Key") builds
267+
// store separate Safe Storage passwords under the same service name.
268+
// Query each known account explicitly, then fall back to service-only
269+
// lookups to catch unknown account names.
270+
const keychainQueries: { service: string; account?: string }[] = [
271+
{ service: "Slack Safe Storage", account: "Slack Key" },
272+
{ service: "Slack Safe Storage", account: "Slack App Store Key" },
273+
{ service: "Slack Safe Storage" },
274+
{ service: "Chrome Safe Storage" },
275+
{ service: "Chromium Safe Storage" },
276+
];
267277
const passwords: string[] = [];
268-
for (const service of services) {
278+
for (const q of keychainQueries) {
269279
try {
270-
const out = execFileSync("security", ["find-generic-password", "-w", "-s", service], {
280+
const args = ["-w", "-s", q.service];
281+
if (q.account) {
282+
args.push("-a", q.account);
283+
}
284+
const out = execFileSync("security", ["find-generic-password", ...args], {
271285
encoding: "utf8",
272286
stdio: ["ignore", "pipe", "ignore"],
273287
}).trim();
@@ -279,7 +293,7 @@ function getSafeStoragePasswords(prefix: string): string[] {
279293
}
280294
}
281295
if (passwords.length > 0) {
282-
return passwords;
296+
return [...new Set(passwords)];
283297
}
284298
}
285299

0 commit comments

Comments
 (0)