Skip to content

Commit

Permalink
[PB-1977] fix: SIGTRAP when calling safe storage methods (#481)
Browse files Browse the repository at this point in the history
fix: add 1s delay before trying to encrypt the credentials
  • Loading branch information
JoanVicens authored Apr 4, 2024
1 parent d83a458 commit c2fd687
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/apps/main/auth/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,22 @@ export function onUserUnauthorized() {
ipcMain.on('user-is-unauthorized', onUserUnauthorized);

ipcMain.on('user-logged-in', async (_, data: AccessResponse) => {
setCredentials(data.user, data.user.mnemonic, data.token, data.newToken);
if (!canHisConfigBeRestored(data.user.uuid)) {
await setupRootFolder();
try {
await setCredentials(
data.user,
data.user.mnemonic,
data.token,
data.newToken
);
if (!canHisConfigBeRestored(data.user.uuid)) {
await setupRootFolder();
}

setIsLoggedIn(true);
eventBus.emit('USER_LOGGED_IN');
} catch (err) {
Logger.error(err);
}

setIsLoggedIn(true);
eventBus.emit('USER_LOGGED_IN');
});

ipcMain.on('user-logged-out', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/apps/main/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Logger from 'electron-log';
import packageConfig from '../../../../package.json';
import ConfigStore, { defaults, fieldsToSave } from '../config';
import { User } from '../types';
import { Delay } from '../../shared/Delay';

const TOKEN_ENCODING = 'latin1';

Expand Down Expand Up @@ -39,7 +40,7 @@ function ecnryptToken(token: string): string {
return buffer.toString(TOKEN_ENCODING);
}

export function setCredentials(
export async function setCredentials(
userData: User,
mnemonic: string,
bearerToken: string,
Expand All @@ -48,6 +49,11 @@ export function setCredentials(
ConfigStore.set('mnemonic', mnemonic);
ConfigStore.set('userData', userData);

await Delay.ms(1_000);
// In the version of electron we are using calling
// isEncryptionAvailable or decryptString "too son" will crash the app
// we will be able to remove once we can update the electron version

const isSafeStorageAvailable = safeStorage.isEncryptionAvailable();

const token = isSafeStorageAvailable
Expand Down
7 changes: 7 additions & 0 deletions src/apps/shared/Delay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Delay {
static ms(milliseconds: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12673,6 +12673,11 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"

undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

undici@^5.5.1:
version "5.22.1"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.22.1.tgz#877d512effef2ac8be65e695f3586922e1a57d7b"
Expand Down

0 comments on commit c2fd687

Please sign in to comment.