Skip to content

Commit

Permalink
pre-select gnome-libsecret safeStorage backend
Browse files Browse the repository at this point in the history
if no explicit backend is given, we default to trying gnome-libsecret
since that was what we required before.
the code that keytar used to do its thing is virtually identical to
what chromium is doing when using gnome-libsecret.
  • Loading branch information
ganthern committed Dec 12, 2023
1 parent 75c45af commit 92c6ed2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/desktop/DesktopMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DesktopTray } from "./tray/DesktopTray"
import { log } from "./DesktopLog"
import { UpdaterWrapper } from "./UpdaterWrapper"
import { ElectronNotificationFactory } from "./NotificatonFactory"
import { buildSecretStorage } from "./sse/SecretStorage"
import { buildSecretStorage, preselectGnomeLibsecret } from "./sse/SecretStorage"
import fs from "node:fs"
import { DesktopIntegrator, getDesktopIntegratorForPlatform } from "./integration/DesktopIntegrator"
import net from "node:net"
Expand Down Expand Up @@ -60,7 +60,6 @@ import { DefaultDateProvider } from "../calendar/date/CalendarUtils.js"
import { OfflineDbRefCounter } from "./db/OfflineDbRefCounter.js"
import { WorkerSqlCipher } from "./db/WorkerSqlCipher.js"
import { TempFs } from "./files/TempFs.js"
import { WASMArgon2idFacade } from "../api/worker/facades/Argon2idFacade.js"

/**
* Should be injected during build time.
Expand Down Expand Up @@ -136,6 +135,7 @@ if (opts.registerAsMailHandler && opts.unregisterAsMailHandler) {
async function createComponents(): Promise<Components> {
const en = (await import("../translations/en.js")).default
lang.init(en)
preselectGnomeLibsecret(electron)
const secretStorage = await buildSecretStorage(electron, fs, path)
const keyStoreFacade = new DesktopKeyStoreFacade(secretStorage, desktopCrypto)
const configMigrator = new DesktopConfigMigrator(desktopCrypto, keyStoreFacade, electron)
Expand Down
15 changes: 15 additions & 0 deletions src/desktop/sse/SecretStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ import type { default as Keytar } from "keytar"
import os from "node:os"
import { ProgrammingError } from "../../api/common/error/ProgrammingError.js"

export function preselectGnomeLibsecret(electron: typeof Electron.CrossProcessExports) {
// this is how chromium selects a backend:
// https://chromium.googlesource.com/chromium/src/+/main/components/os_crypt/sync/key_storage_util_linux.cc
// also for DE detection, which happens before:
// https://chromium.googlesource.com/chromium/src/+/main/base/nix/xdg_util.cc
// I'm 90% sure that it's the deprecated "GNOME_DESKTOP_SESSION_ID" env var that's set once you have logged into gnome
// and back out that makes it suddenly work with i3 since chromium falls back to that if none of the more modern vars
// contain something it recognizes.
// if no explicit backend is given, we default to trying gnome-libsecret since that was what we required before.
// the code that keytar used to do its thing is virtually identical to what chromium is doing when using gnome-libsecret.
if (process.platform === "linux" && !process.argv.some((a) => a.startsWith("--password-store="))) {
electron.app.commandLine.appendSwitch("password-store", "gnome-libsecret")
}
}

export async function buildSecretStorage(electron: typeof Electron.CrossProcessExports, fs: typeof FsModule, path: typeof PathModule): Promise<SecretStorage> {
const mode = determineNativeBackendMode()
switch (mode) {
Expand Down

0 comments on commit 92c6ed2

Please sign in to comment.