-
Notifications
You must be signed in to change notification settings - Fork 91
[PM-12436] replace node keytar #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JaredScar
wants to merge
5
commits into
main
Choose a base branch
from
ac/pm-12436-replace-node-keytar-sonnet-attempt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3abd3f0
Refactor secure storage implementation to use native bindings and migβ¦
JaredScar 9aab82d
Integrate native module 'dc-native' for secure storage, updating Typeβ¦
JaredScar 8543265
Refactor TypeScript definitions for password management functions by β¦
JaredScar 3bf4916
Refactor secure storage implementation to utilize the 'dc-native' modβ¦
JaredScar 216f57a
Merge branch 'main' into ac/pm-12436-replace-node-keytar-sonnet-attempt
JaredScar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| v20 | ||
| v22 |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ export default [ | |
| "eslint.config.mjs", | ||
| "scripts/**/*.js", | ||
| "**/node_modules/**", | ||
| "native/**", | ||
| ], | ||
| }, | ||
|
|
||
|
|
||
This file contains hidden or 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
60 changes: 35 additions & 25 deletions
60
jslib/electron/src/services/electronRendererSecureStorage.service.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,43 +1,53 @@ | ||
| import { ipcRenderer } from "electron"; | ||
|
|
||
| import { StorageService } from "@/jslib/common/src/abstractions/storage.service"; | ||
| import { StorageOptions } from "@/jslib/common/src/models/domain/storageOptions"; | ||
|
|
||
| import { passwords } from "dc-native"; | ||
|
|
||
| const APPLICATION_NAME = "Bitwarden Directory Connector"; | ||
|
|
||
| export class ElectronRendererSecureStorageService implements StorageService { | ||
| async get<T>(key: string, options?: StorageOptions): Promise<T> { | ||
| const val = ipcRenderer.sendSync("keytar", { | ||
| action: "getPassword", | ||
| key: key, | ||
| keySuffix: options?.keySuffix ?? "", | ||
| }); | ||
| return Promise.resolve(val != null ? (JSON.parse(val) as T) : null); | ||
| return passwords | ||
| .getPassword(this.buildServiceName(options), key) | ||
| .then((val: string) => JSON.parse(val) as T) | ||
| .catch((e: Error): T => { | ||
| if (e.message === passwords.PASSWORD_NOT_FOUND) { | ||
| return null; | ||
| } | ||
| throw e; | ||
| }); | ||
| } | ||
|
|
||
| async has(key: string, options?: StorageOptions): Promise<boolean> { | ||
| const val = ipcRenderer.sendSync("keytar", { | ||
| action: "hasPassword", | ||
| key: key, | ||
| keySuffix: options?.keySuffix ?? "", | ||
| }); | ||
| return Promise.resolve(!!val); | ||
| return (await this.get(key, options)) != null; | ||
| } | ||
|
|
||
| async save(key: string, obj: any, options?: StorageOptions): Promise<any> { | ||
| ipcRenderer.sendSync("keytar", { | ||
| action: "setPassword", | ||
| key: key, | ||
| keySuffix: options?.keySuffix ?? "", | ||
| value: JSON.stringify(obj), | ||
| }); | ||
| return Promise.resolve(); | ||
| if (!obj) { | ||
| return this.remove(key, options); | ||
| } | ||
| return passwords.setPassword( | ||
| this.buildServiceName(options), | ||
| key, | ||
| JSON.stringify(obj), | ||
| ); | ||
| } | ||
|
|
||
| async remove(key: string, options?: StorageOptions): Promise<any> { | ||
| ipcRenderer.sendSync("keytar", { | ||
| action: "deletePassword", | ||
| key: key, | ||
| keySuffix: options?.keySuffix ?? "", | ||
| return passwords.deletePassword(this.buildServiceName(options), key).catch((e: Error) => { | ||
| if (e.message === passwords.PASSWORD_NOT_FOUND) { | ||
| return; | ||
| } | ||
| throw e; | ||
| }); | ||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| private buildServiceName(options?: StorageOptions): string { | ||
| const suffix = options?.keySuffix; | ||
| if (suffix) { | ||
| return `${APPLICATION_NAME}_${suffix}`; | ||
| } | ||
| return APPLICATION_NAME; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π¨ SUGGESTED: This service name is now hardcoded in three separate locations:
ElectronRendererSecureStorageServicestateMigration.service.tsline 190 (const serviceName = "Bitwarden Directory Connector")bwdc.tsline 63 (const applicationName = "Bitwarden Directory Connector")If any of these drift out of sync, credentials written by one path would be invisible to another. Consider extracting this to a shared constant (e.g., in a constants file) to make the coupling explicit and prevent future inconsistencies.