1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-29 22:31:29 +01:00

Fix ssh agent initializiation (#12779)

This commit is contained in:
Bernd Schoolmann 2025-01-09 16:37:16 +01:00 committed by GitHub
parent 1a80ae8968
commit 20c8eda986
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,8 @@ export class SshAgentService implements OnDestroy {
SSH_VAULT_UNLOCK_REQUEST_TIMEOUT = 60_000; SSH_VAULT_UNLOCK_REQUEST_TIMEOUT = 60_000;
SSH_REQUEST_UNLOCK_POLLING_INTERVAL = 100; SSH_REQUEST_UNLOCK_POLLING_INTERVAL = 100;
private isFeatureFlagEnabled = false;
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>();
constructor( constructor(
@ -65,18 +67,19 @@ export class SshAgentService implements OnDestroy {
.getFeatureFlag$(FeatureFlag.SSHAgent) .getFeatureFlag$(FeatureFlag.SSHAgent)
.pipe( .pipe(
concatMap(async (enabled) => { concatMap(async (enabled) => {
if (enabled && !(await ipc.platform.sshAgent.isLoaded())) { this.isFeatureFlagEnabled = enabled;
return this.initSshAgent(); if (!(await ipc.platform.sshAgent.isLoaded()) && enabled) {
await ipc.platform.sshAgent.init();
} }
}), }),
takeUntil(this.destroy$), takeUntil(this.destroy$),
) )
.subscribe(); .subscribe();
await this.initListeners();
} }
private async initSshAgent() { private async initListeners() {
await ipc.platform.sshAgent.init();
this.messageListener this.messageListener
.messages$(new CommandDefinition("sshagent.signrequest")) .messages$(new CommandDefinition("sshagent.signrequest"))
.pipe( .pipe(
@ -179,18 +182,30 @@ export class SshAgentService implements OnDestroy {
this.accountService.activeAccount$.pipe(skip(1), takeUntil(this.destroy$)).subscribe({ this.accountService.activeAccount$.pipe(skip(1), takeUntil(this.destroy$)).subscribe({
next: (account) => { next: (account) => {
if (!this.isFeatureFlagEnabled) {
return;
}
this.logService.info("Active account changed, clearing SSH keys"); this.logService.info("Active account changed, clearing SSH keys");
ipc.platform.sshAgent ipc.platform.sshAgent
.clearKeys() .clearKeys()
.catch((e) => this.logService.error("Failed to clear SSH keys", e)); .catch((e) => this.logService.error("Failed to clear SSH keys", e));
}, },
error: (e: unknown) => { error: (e: unknown) => {
if (!this.isFeatureFlagEnabled) {
return;
}
this.logService.error("Error in active account observable", e); this.logService.error("Error in active account observable", e);
ipc.platform.sshAgent ipc.platform.sshAgent
.clearKeys() .clearKeys()
.catch((e) => this.logService.error("Failed to clear SSH keys", e)); .catch((e) => this.logService.error("Failed to clear SSH keys", e));
}, },
complete: () => { complete: () => {
if (!this.isFeatureFlagEnabled) {
return;
}
this.logService.info("Active account observable completed, clearing SSH keys"); this.logService.info("Active account observable completed, clearing SSH keys");
ipc.platform.sshAgent ipc.platform.sshAgent
.clearKeys() .clearKeys()
@ -204,11 +219,23 @@ export class SshAgentService implements OnDestroy {
]) ])
.pipe( .pipe(
concatMap(async ([, enabled]) => { concatMap(async ([, enabled]) => {
if (!this.isFeatureFlagEnabled) {
return;
}
if (!enabled) { if (!enabled) {
await ipc.platform.sshAgent.clearKeys(); await ipc.platform.sshAgent.clearKeys();
return; return;
} }
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
const authStatus = await firstValueFrom(
this.authService.authStatusFor$(activeAccount.id),
);
if (authStatus !== AuthenticationStatus.Unlocked) {
return;
}
const ciphers = await this.cipherService.getAllDecrypted(); const ciphers = await this.cipherService.getAllDecrypted();
if (ciphers == null) { if (ciphers == null) {
await ipc.platform.sshAgent.lock(); await ipc.platform.sshAgent.lock();