10000 feat: add `electron.safeStorage` encryption API by georgexu99 · Pull Request #30020 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add electron.safeStorage encryption API #30020

New issue 10000

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

Merged
merged 31 commits into from
Aug 5, 2021

Conversation

georgexu99
Copy link
Contributor
@georgexu99 georgexu99 commented Jul 5, 2021

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

Release Notes

Notes: add safeStorage string encryption API

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jul 5, 2021
@MarshallOfSound MarshallOfSound changed the title [WIP] feat: add electron.safeStorage cookie encryption API [WIP] feat: add electron.safeStorage encryption API Jul 5, 2021
@MarshallOfSound MarshallOfSound added semver/minor backwards-compatible functionality target/14-x-y labels Jul 5, 2021
@georgexu99 georgexu99 changed the title [WIP] feat: add electron.safeStorage encryption API feat: add electron.safeStorage encryption API Jul 8, 2021
@georgexu99 georgexu99 force-pushed the cookie-encryption-api branch from 8c868f9 to 7a86391 Compare July 8, 2021 18:04
@georgexu99 georgexu99 marked this pull request as ready for review July 8, 2021 21:23

std::string SafeStorage::DecryptString(v8::Isolate* isolate,
v8::Local<v8::Value> buffer) {
if (!node::Buffer::HasInstance(buffer)) {
Copy link
Contributor

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).

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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? 🙇

Copy link
Member

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.

Copy link
Contributor
@nornagon nornagon Jul 13, 2021

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.

@georgexu99 georgexu99 force-pushed the cookie-encryption-api branch from e72bd7c to fdd4b9e Compare July 12, 2021 22:10
@georgexu99 georgexu99 requested a review from a team as a code owner July 20, 2021 20:09
@georgexu99 georgexu99 force-pushed the cookie-encryption-api branch 2 times, most recently from 4fe1c3a to cb6eb32 Compare July 21, 2021 17:44
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Jul 22, 2021
@georgexu99 georgexu99 force-pushed the cookie-encryption-api branch from e34ac71 to 67fd1fd Compare July 23, 2021 23:38
@georgexu99 < 8000 a class="author Link--primary text-bold" data-test-selector="pr-timeline-events-actor-profile-link" data-hovercard-type="user" data-hovercard-url="/users/georgexu99/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="/georgexu99">georgexu99 requested a review from MarshallOfSound July 27, 2021 22:04

// ensures an error is thrown in Mac or Linux on
// decryption failure, rather than failing silently
std::vector<std::string> kEncryptionVersionPrefix{"v10", "v11"};
Copy link
Member

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.");
Copy link
57A7
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Ciphertext may not be encrypted.");
"Ciphertext does not appear to be encrypted.");

@georgexu99 georgexu99 force-pushed the cookie-encryption-api branch 3 times, most recently from 557c4dc to 59f2c7a Compare July 29, 2021 21:36
@georgexu99 georgexu99 requested review from a team as code owners July 29, 2021 21:36
#ifndef SHELL_BROWSER_API_ELECTRON_API_SAFE_STORAGE_H_
#define SHELL_BROWSER_API_ELECTRON_API_SAFE_STORAGE_H_

#include <string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <string>

Comment on lines +9 to +14
/* 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)


ifdescribe(process.platform !== 'linux')('safeStorage module', () => {
after(async () => {
if (process.platform === 'linux') return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled by ifdescribe above.

Suggested change
if (process.platform === 'linux') return;

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);
Copy link
Contributor

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
}

?

@nornagon
Copy link
Contributor
nornagon commented Aug 5, 2021

Linux asan failure is fixed in main.

@VerteDinde VerteDinde merged commit bc508c6 into electron:main Aug 5, 2021
@release-clerk
Copy link
release-clerk bot commented Aug 5, 2021

Release Notes Persisted

add safeStorage string encryption API

@trop
Copy link
Contributor
trop bot commented Aug 5, 2021

I was unable to backport this PR to "14-x-y" cleanly;
you will need to perform this backport manually.

trop bot pushed a commit that referenced this pull request Aug 5, 2021
* 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>
@trop
Copy link
Contributor
trop bot commented Aug 5, 2021

I have automatically backported this PR to "15-x-y", please check out #30430

VerteDinde added a commit that referenced this pull request Aug 12, 2021
* 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>
VerteDinde added a commit that referenced this pull request Aug 23, 2021
* 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>
BlackHole1 pushed a commit to BlackHole1/electron that referenced this pull request Aug 30, 2021
* 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>
Ovenoboyo added a commit to Moosync/Moosync-electron that referenced this pull request Oct 11, 2021
@shadow-light
Copy link

Will isEncryptionAvailable ever change value while Electron is running?

i.e. Do alternate security measures need anticipating just at startup or at anytime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review/requested 🗳 semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0