-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.initial check-in for separate vault key ui changes
- Loading branch information
Showing
23 changed files
with
921 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { safeStorage } from 'electron'; | ||
|
||
import LocalStorage from '../local-storage'; | ||
import { initLocalStorage } from '../window-utils'; | ||
import { ipcMainHandle } from './electron'; | ||
|
||
export interface secretStorageBridgeAPI { | ||
setSecret: typeof setSecret; | ||
getSecret: typeof getSecret; | ||
deleteSecret: typeof deleteSecret; | ||
encryptString: (raw: string) => Promise<string>; | ||
decryptString: (cipherText: string) => Promise<string>; | ||
} | ||
|
||
export function registerSecretStorageHandlers() { | ||
ipcMainHandle('secretStorage.setSecret', (_, key, secret) => setSecret(key, secret)); | ||
ipcMainHandle('secretStorage.getSecret', (_, key) => getSecret(key)); | ||
ipcMainHandle('secretStorage.deleteSecret', (_, key) => deleteSecret(key)); | ||
ipcMainHandle('secretStorage.encryptString', (_, raw) => encryptString(raw)); | ||
ipcMainHandle('secretStorage.decryptString', (_, raw) => decryptString(raw)); | ||
} | ||
|
||
let localStorage: LocalStorage | null = null; | ||
|
||
const getLocalStorage = () => { | ||
if (!localStorage) { | ||
localStorage = initLocalStorage(); | ||
} | ||
return localStorage; | ||
}; | ||
|
||
const setSecret = async (key: string, secret: string) => { | ||
try { | ||
const secretStorage = getLocalStorage(); | ||
const encrypted = encryptString(secret); | ||
secretStorage.setItem(key, encrypted); | ||
} catch (error) { | ||
console.error(`Can not save secret ${error.toString()}`); | ||
return Promise.reject(error); | ||
} | ||
}; | ||
|
||
const getSecret = async (key: string) => { | ||
try { | ||
const secretStorage = getLocalStorage(); | ||
const encrypted = secretStorage.getItem(key, ''); | ||
return encrypted === '' ? null : decryptString(encrypted); | ||
} catch (error) { | ||
console.error(`Can not get secret ${error.toString()}`); | ||
return Promise.reject(null); | ||
} | ||
}; | ||
|
||
const deleteSecret = async (key: string) => { | ||
try { | ||
const secretStorage = getLocalStorage(); | ||
secretStorage.deleteItem(key); | ||
} catch (error) { | ||
console.error(`Can not delele secret ${error.toString()}`); | ||
return Promise.reject(error); | ||
} | ||
}; | ||
|
||
const encryptString = (raw: string) => { | ||
if (safeStorage.isEncryptionAvailable()) { | ||
return safeStorage.encryptString(raw).toString('hex'); | ||
} | ||
return raw; | ||
}; | ||
|
||
const decryptString = (cipherText: string) => { | ||
const buffer = Buffer.from(cipherText, 'hex'); | ||
if (safeStorage.isEncryptionAvailable()) { | ||
return safeStorage.decryptString(buffer); | ||
} | ||
return cipherText; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.