-
Notifications
You must be signed in to change notification settings - Fork 16.2k
feat: add electron.safeStorage
encryption API
#30020
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
Conversation
electron.safeStorage
cookie encryption APIelectron.safeStorage
encryption API
electron.safeStorage
encryption APIelectron.safeStorage
encryption API
8c868f9
to
7a86391
Compare
|
||
std::string SafeStorage::DecryptString(v8::Isolate* isolate, | ||
v8::Local<v8::Value> buffer) { | ||
if (!node::Buffer::HasInstance(buffer)) { |
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.
We should accept any Uint8Array
here, and not require Buffer
(which is a subclass of Uint8Array
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 10000 reason will be displayed to describe this comment to others. Learn more.
I think Buffer
is the better move here, as you note Buffer
is a loose wrapper around Uint8Array
, in fact you can do zero-cost conversions into a Buffer
class or just pass a Uint8Array
to anything that supports a node::Buffer
.
Node documents things as taking Buffer's even if they also support Uint8Array
's.
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.
node::Buffer::HasInstance
will return false
for a Uint8Array
though?
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.
@MarshallOfSound @nornagon Sorry to gravedig this one, just wondering if there was any resolution to this conversation/ and if there were any strong feelings against keeping Buffer
as the input? 🙇
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.
I think for consistency we should use buffer, we don't have any other apis that take uint8array but we do work with buffers a bunch.
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.
I still think we should accept Uint8Array
even if we document this as accepting Buffer
. https://en.wikipedia.org/wiki/Robustness_principle
I won't block the PR on it though.
e72bd7c
to
fdd4b9e
Compare
4fe1c3a
to
cb6eb32
Compare
e34ac71
to
67fd1fd
Compare
|
||
// ensures an error is thrown in Mac or Linux on | ||
// decryption failure, rather than failing silently | ||
std::vector<std::string> kEncryptionVersionPrefix{"v10", "v11"}; |
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.
This could be defined outside of this method, preferably as two unique char*
so that we aren't statically allocating strings or vectors
gin_helper::ErrorThrower(isolate).ThrowError( | ||
"Error while decrypting the ciphertext provided to " | ||
"safeStorage.decryptString. " | ||
"Ciphertext may not be encrypted."); |
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.
"Ciphertext may not be encrypted."); | |
"Ciphertext does not appear to be encrypted."); |
557c4dc
to
59f2c7a
Compare
#ifndef SHELL_BROWSER_API_ELECTRON_API_SAFE_STORAGE_H_ | ||
#define SHELL_BROWSER_API_ELECTRON_API_SAFE_STORAGE_H_ | ||
|
||
#include <string> |
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.
#include <string> |
/* isEncryptionAvailable returns false in Linux when running CI due to a mocked dbus. This stops | ||
* Chrome from reaching the system's keyring or libsecret. When running the tests with config.store | ||
* set to basic-text, a nullptr is returned from chromium, defaulting the available encryption to false. | ||
* | ||
* Because all encryption methods are gated by isEncryptionAvailable, the methods will never return the correct values | ||
* when run on CI and linux. |
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.
This is a shame, it would be a nice followup to have the keyring stuff mocked out in dbus in a way that would allow the tests to run. But I think it's OK to ship without this.
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.
created a follow-up issue so this doesn't get lost :)
spec-main/api-safe-storage-spec.ts
Outdated
|
||
ifdescribe(process.platform !== 'linux')('safeStorage module', () => { | ||
after(async () => { | ||
if (process.platform === 'linux') return; |
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.
handled by ifdescribe
above.
if (process.platform === 'linux') return; |
spec-main/api-safe-storage-spec.ts
Outdated
encryptAppProcess.stderr.on('data', data => { stdout += data; }); | ||
|
||
// this setTimeout is left here for QOL in case we need to debug this test in the future | ||
setTimeout(() => { console.log(stdout); }, 3000); |
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.
Hm, this setTimeout
is a bit weird... it might make the stdout look like it was coming from a different test. Maybe instead something like:
try {
// ... rest of the test ...
} catch (e) {
console.log(stdout)
throw e
}
?
c1cd352
to
eaf33c4
Compare
Linux asan failure is fixed in main. |
Release Notes Persisted
|
I was unable to backport this PR to "14-x-y" cleanly; |
* feat: add SafeStorage api; first commit * chore: rename files to fit semantically * chore: add linkedBindings * chore: fix function signatures * chore: refactor eisCookieEncryptionEnabled() fuse * chore: create test file * chore: add tests and documentation * chore: add copyright and lint * chore: add additional tests * chore: fix constructor * chore: commit for pair programming * wip: commit for keeley pairing * chore: docs change and code cleanup * chore: add linux import * chore: add description to documentation * chore: fixing tests * chore: modify behaviour to not allow unencrypted strings as decyption input * fix add patch for enabling default v11 encryption on Linux * chore: remove file after each test * chore: fix patch * chore: remove chromium patch * chore: add linux specific tests * chore: fix path * chore: add checker for linuux file deletion * chore: add dcheck back * chore: remove reference to headless mode * chore: remove tests for linux * chore: edit commit message * chore: refactor safeStorage to not be a class * chore: remove static variable from header * chore: spec file remove settimeout Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
I have automatically backported this PR to "15-x-y", please check out #30430 |
* feat: add SafeStorage api; first commit * chore: rename files to fit semantically * chore: add linkedBindings * chore: fix function signatures * chore: refactor eisCookieEncryptionEnabled() fuse * chore: create test file * chore: add tests and documentation * chore: add copyright and lint * chore: add additional tests * chore: fix constructor * chore: commit for pair programming * wip: commit for keeley pairing * chore: docs change and code cleanup * chore: add linux import * chore: add description to documentation * chore: fixing tests * chore: modify behaviour to not allow unencrypted strings as decyption input * fix add patch for enabling default v11 encryption on Linux * chore: remove file after each test * chore: fix patch * chore: remove chromium patch * chore: add linux specific tests * chore: fix path * chore: add checker for linuux file deletion * chore: add dcheck back * chore: remove reference to headless mode * chore: remove tests for linux * chore: edit commit message * chore: refactor safeStorage to not be a class * chore: remove static variable from header * chore: spec file remove settimeout Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
* feat: add SafeStorage api; first commit * chore: rename files to fit semantically * chore: add linkedBindings * chore: fix function signatures * chore: refactor eisCookieEncryptionEnabled() fuse * chore: create test file * chore: add tests and documentation * chore: add copyright and lint * chore: add additional tests * chore: fix constructor * chore: commit for pair programming * wip: commit for keeley pairing * chore: docs change and code cleanup * chore: add linux import * chore: add description to documentation * chore: fixing tests * chore: modify behaviour to not allow unencrypted strings as decyption input * fix add patch for enabling default v11 encryption on Linux * chore: remove file after each test * chore: fix patch * chore: remove chromium patch * chore: add linux specific tests * chore: fix path * chore: add checker for linuux file deletion * chore: add dcheck back * chore: remove reference to headless mode * chore: remove tests for linux * chore: edit commit message * chore: refactor safeStorage to not be a class * chore: remove static variable from header * chore: spec file remove settimeout Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: George Xu <33054982+georgexu99@users.noreply.github.com> Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
* feat: add SafeStorage api; first commit * chore: rename files to fit semantically * chore: add linkedBindings * chore: fix function signatures * chore: refactor eisCookieEncryptionEnabled() fuse * chore: create test file * chore: add tests and documentation * chore: add copyright and lint * chore: add additional tests * chore: fix constructor * chore: commit for pair programming * wip: commit for keeley pairing * chore: docs change and code cleanup * chore: add linux import * chore: add description to documentation * chore: fixing tests * chore: modify behaviour to not allow unencrypted strings as decyption input * fix add patch for enabling default v11 encryption on Linux * chore: remove file after each test * chore: fix patch * chore: remove chromium patch * chore: add linux specific tests * chore: fix path * chore: add checker for linuux file deletion * chore: add dcheck back * chore: remove reference to headless mode * chore: remove tests for linux * chore: edit commit message * chore: refactor safeStorage to not be a class * chore: remove static variable from header * chore: spec file remove settimeout Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
Will i.e. Do alternate security measures need anticipating just at startup or at anytime? |
Description of Change
add a cookie encryption api to allow users to encrypt, decrypt strings and check whether encryption is available.
we recently added experimental cookie encryption support #27524. This API exposes three methods from Chromium, but only when os_crypto is available.
Checklist
npm test
passesRelease Notes
Notes: add
safeStorage
string encryption API