secure storage via ipc to main
This commit is contained in:
parent
95e6d0b92d
commit
78b1f5df99
|
@ -5,6 +5,7 @@ import { NgModule } from '@angular/core';
|
||||||
import { DesktopMessagingService } from '../../services/desktopMessaging.service';
|
import { DesktopMessagingService } from '../../services/desktopMessaging.service';
|
||||||
import { DesktopPlatformUtilsService } from '../../services/desktopPlatformUtils.service';
|
import { DesktopPlatformUtilsService } from '../../services/desktopPlatformUtils.service';
|
||||||
import { DesktopStorageService } from '../../services/desktopStorage.service';
|
import { DesktopStorageService } from '../../services/desktopStorage.service';
|
||||||
|
import { DesktopSecureStorageService } from '../../services/desktopSecureStorage.service';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ApiService,
|
ApiService,
|
||||||
|
@ -53,9 +54,9 @@ const utilsService = new UtilsService();
|
||||||
const platformUtilsService = new DesktopPlatformUtilsService();
|
const platformUtilsService = new DesktopPlatformUtilsService();
|
||||||
const messagingService = new DesktopMessagingService();
|
const messagingService = new DesktopMessagingService();
|
||||||
const storageService: StorageServiceAbstraction = new DesktopStorageService();
|
const storageService: StorageServiceAbstraction = new DesktopStorageService();
|
||||||
const secureStorageService: StorageServiceAbstraction = storageService; //remote.getGlobal('secureStorageService');
|
const secureStorageService: StorageServiceAbstraction = new DesktopSecureStorageService();
|
||||||
const constantsService = new ConstantsService({}, 0);
|
const constantsService = new ConstantsService({}, 0);
|
||||||
const cryptoService = new CryptoService(storageService, storageService);
|
const cryptoService = new CryptoService(storageService, storageService); // TODO: use secure storage
|
||||||
const tokenService = new TokenService(storageService);
|
const tokenService = new TokenService(storageService);
|
||||||
const appIdService = new AppIdService(storageService);
|
const appIdService = new AppIdService(storageService);
|
||||||
const apiService = new ApiService(tokenService, platformUtilsService,
|
const apiService = new ApiService(tokenService, platformUtilsService,
|
||||||
|
|
28
src/main.ts
28
src/main.ts
|
@ -1,10 +1,30 @@
|
||||||
import { app, BrowserWindow, screen } from 'electron';
|
import { app, BrowserWindow, screen, ipcMain } from 'electron';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
/*
|
||||||
|
import { getPassword, setPassword, deletePassword } from 'keytar';
|
||||||
|
|
||||||
//import { DesktopSecureStorageService } from './services/desktopSecureStorage.service';
|
const keytarService = 'bitwarden';
|
||||||
//const secureStorageService = new DesktopSecureStorageService();
|
ipcMain.on('keytar', async (event: any, message: any) => {
|
||||||
//(global as any).secureStorageService = secureStorageService;
|
try {
|
||||||
|
let val: string = null;
|
||||||
|
if (message.action && message.key) {
|
||||||
|
if (message.action === 'getPassword') {
|
||||||
|
val = await getPassword(keytarService, message.key);
|
||||||
|
} else if (message.action === 'setPassword' && message.value) {
|
||||||
|
await setPassword(keytarService, message.key, message.value);
|
||||||
|
} else if (message.action === 'deletePassword') {
|
||||||
|
await deletePassword(keytarService, message.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.returnValue = val;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
event.returnValue = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
let win: BrowserWindow;
|
let win: BrowserWindow;
|
||||||
const args = process.argv.slice(1);
|
const args = process.argv.slice(1);
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
import { getPassword, setPassword, deletePassword } from 'keytar';
|
import { ipcRenderer } from 'electron';
|
||||||
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||||
import { StorageService } from 'jslib/abstractions';
|
|
||||||
|
|
||||||
export class DesktopSecureStorageService implements StorageService {
|
export class DesktopSecureStorageService implements StorageService {
|
||||||
async get<T>(key: string): Promise<T> {
|
async get<T>(key: string): Promise<T> {
|
||||||
const val: string = await getPassword('bitwarden', key);
|
const val = ipcRenderer.sendSync('keytar', {
|
||||||
return val ? JSON.parse(val) as T : null
|
action: 'getPassword',
|
||||||
|
key: key,
|
||||||
|
});
|
||||||
|
return Promise.resolve(val ? JSON.parse(val) as T : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(key: string, obj: any): Promise<any> {
|
async save(key: string, obj: any): Promise<any> {
|
||||||
await setPassword('bitwarden', key, JSON.stringify(obj));
|
ipcRenderer.sendSync('keytar', {
|
||||||
|
action: 'setPassword',
|
||||||
|
key: key,
|
||||||
|
value: JSON.stringify(obj),
|
||||||
|
});
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(key: string): Promise<any> {
|
async remove(key: string): Promise<any> {
|
||||||
await deletePassword('bitwarden', key);
|
ipcRenderer.sendSync('keytar', {
|
||||||
|
action: 'deletePassword',
|
||||||
|
key: key,
|
||||||
|
});
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue