Skip to content
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

[Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Linux when called before creation of the first BrowserWindow #32206

Closed
3 tasks done
ganthern opened this issue Dec 16, 2021 · 7 comments · Fixed by #33913
Labels
15-x-y 16-x-y 17-x-y 18-x-y bug 🪲 platform/linux status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@ganthern
Copy link
Contributor

ganthern commented Dec 16, 2021

Preflight Checklist

Electron Version

15 and 16

What operating system are you using?

Ubuntu

Operating System Version

Ubuntu 20.04

What arch are you using?

x64

Last Known Working Electron version

n/a

Expected Behavior

calling electron.safeStorage.isEncryptionAvailable() returns a boolean

Actual Behavior

calling electron.safeStorage.isEncryptionAvailable() segfaults immediately

Testcase Gist URL

https://github.com/ganthern/safe-storage-segfault

Additional Information

It also happens in a fresh openSUSE Leap 15.1.1 VM.

The API should be available as soon as possible (preferrably before app ready) since it's useful for apps that run on startup without immediately opening BrowserWindows.

For the record, it works as expected on MacOs and returns false on windows, which makes the current documentation of isEncryptionAvailable inaccurate.

@ganthern ganthern changed the title [Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Ubuntu 20.04 [Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Linux Dec 16, 2021
@ganthern ganthern changed the title [Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Linux [Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Linux when called before creation of the first browserWindow Dec 21, 2021
@ganthern ganthern changed the title [Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Linux when called before creation of the first browserWindow [Bug]: electron.safeStorage.isEncryptionAvailable() segfaults on Linux when called before creation of the first BrowserWindow Dec 21, 2021
@theDevelopper
Copy link

I also have this issue in electron 16. Any call to a safeStorage function such as isEncryptionAvailable or decryptString on Ubuntu that happens "to soon" after start will just crash electron. If I delay the first call somewhat then it works just fine.
I hope someone is looking at this issue soon.

@Nantris
Copy link
Contributor

Nantris commented Apr 20, 2022

@ganthern I believe this issue can probably be closed now if the solution is in #33640 - unless you've tried this and it yields the same error.

I think we should just document that it requires the app to be ready on windows.

@RaisinTen
Copy link
Member

@slapbox IMO this issue shouldn't be closed with a doc fix alone because this involves a crash. A doc fix would have been fine if isEncryptionAvailable() returned false or if the other safeStorage APIs threw JS exceptions like

App threw an error during load
Error: Error while decrypting the ciphertext provided to safeStorage.decryptString. Encryption is not available.

for a certain while but on Linux it just segfaults.

@ganthern
Copy link
Contributor Author

ganthern commented Apr 21, 2022

@ganthern I believe this issue can probably be closed now if the solution is in #33640 - unless you've tried this and it yields the same error.

There is no error, the app just dies.

@RaisinTen
Copy link
Member

Today, I tried to attach the debugging symbols to the release builds of Electron v18.0.3 and managed to get a human readable stack trace:

Thread 1 "electron" received signal SIGTRAP, Trace/breakpoint trap.
0x000055555b8b4faf in (anonymous namespace)::CreateKeyStorage () at ../../components/os_crypt/os_crypt_linux.cc:74
74	../../components/os_crypt/os_crypt_linux.cc: No such file or directory.
(gdb) bt
#0  0x000055555b8b4faf in (anonymous namespace)::CreateKeyStorage () at ../../components/os_crypt/os_crypt_linux.cc:74
#1  0x000055555b8b53e9 in (anonymous namespace)::GetPasswordV11 () at ../../components/os_crypt/os_crypt_linux.cc:117
#2  0x000055555b8b4b79 in OSCrypt::IsEncryptionAvailable () at ../../components/os_crypt/os_crypt_linux.cc:245
#3  0x00005555575c6f11 in base::RepeatingCallback<bool ()>::Run() const & (this=0x7fffffffbbc0) at ../../base/callback.h:241
#4  gin_helper::Invoker<gin_helper::IndicesHolder<>>::DispatchToCallback<bool>(base::RepeatingCallback<bool ()>) (callback=..., this=<optimized out>)
    at ../../electron/shell/common/gin_helper/function_template.h:222
#5  gin_helper::Dispatcher<bool ()>::DispatchToCallback(v8::FunctionCallbackInfo<v8::Value> const&) (info=...)
    at ../../electron/shell/common/gin_helper/function_template.h:264
#6  0x00005555587307e1 in v8::internal::FunctionCallbackArguments::Call (this=0x7fffffffbc58, handler=...)
    at ../../v8/src/api/api-arguments-inl.h:152
#7  v8::internal::(anonymous namespace)::HandleApiCallHelper<false> (isolate=0x28d00060c000, fun_data=..., receiver=..., function=..., 
    new_target=..., args=...) at ../../v8/src/builtins/builtins-api.cc:112
#8  v8::internal::Builtin_Impl_HandleApiCall (args=..., isolate=0x28d00060c000) at ../../v8/src/builtins/builtins-api.cc:142
#9  v8::internal::Builtin_HandleApiCall (args_length=5, args_object=<optimized out>, isolate=0x28d00060c000)
    at ../../v8/src/builtins/builtins-api.cc:130
#10 0x00005555572cb5f8 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit ()
#11 0x000055555724ae22 in Builtins_InterpreterEntryTrampoline ()

So this is probably coming from the release build assertion CHECK in https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0

// Create the KeyStorage. Will be null if no service is found. A Config must be
// set before every call to this function.
std::unique_ptr<KeyStorageLinux> CreateKeyStorage() {
  CHECK(g_cache.Get().config);
  std::unique_ptr<KeyStorageLinux> key_storage =
      KeyStorageLinux::CreateService(*g_cache.Get().config);
  g_cache.Get().config.reset();
  return key_storage;
}

Apparently the config wasn't set as expected. Will try to debug further tomorrow.

RaisinTen added a commit to RaisinTen/electron that referenced this issue Apr 25, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this change patches [`IsEncryptionAvailable()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=245;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
to return false if the config hasn't been set already.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue Apr 25, 2022
…d of crashing

On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this change patches [`IsEncryptionAvailable()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=245;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
to return false if the config hasn't been set already.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@RaisinTen
Copy link
Member

Sent a potential fix for this in #33913! Haven't tested it locally yet because I don't have the resources to compile electron on linux yet, so I can try to download the artifacts and test those out instead. Unfortunately, just as @codebytere mentioned in #33640 (comment), electron is mirroring chromium's behavior and that prevents us from running safeStorage methods before the app is ready on linux. The fix makes safeStorage.isEncryptionAvailable() return false instead of crashing before the 'ready' event is emitted by the app.

RaisinTen added a commit to RaisinTen/electron that referenced this issue Apr 25, 2022
…d of crashing

On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this change patches [`IsEncryptionAvailable()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=245;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
to return false if the config hasn't been set already.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue Apr 26, 2022
…d of crashing

On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue Apr 26, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue Apr 26, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@ckerr ckerr added status/confirmed A maintainer reproduced the bug or agreed with the feature 16-x-y 17-x-y 18-x-y 15-x-y platform/linux labels Apr 26, 2022
@ckerr
Copy link
Member

ckerr commented Apr 26, 2022

Yep, the config is set in ElectronBrowserMainParts::PostCreateMainMessageLoop at

OSCrypt::SetConfig(std::move(config));

RaisinTen added a commit to RaisinTen/electron that referenced this issue May 5, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
jkleinsc pushed a commit that referenced this issue May 9, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
trop bot pushed a commit that referenced this issue May 9, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
trop bot pushed a commit that referenced this issue May 9, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
codebytere pushed a commit that referenced this issue May 11, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>

Co-authored-by: Darshan Sen <raisinten@gmail.com>
jkleinsc pushed a commit that referenced this issue May 11, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>

Co-authored-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue May 17, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue May 17, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit to RaisinTen/electron that referenced this issue May 17, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
jkleinsc pushed a commit that referenced this issue May 18, 2022
* fix: fix a crash in `safeStorage` on Linux (#33913)

On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>

* fix: replace BUILDFLAG(IS_LINUX) with defined(OS_LINUX)

Signed-off-by: Darshan Sen <raisinten@gmail.com>

* Linux: Send OSCrypt raw encryption key to the Network Service

This backports 0e09738.

Signed-off-by: Darshan Sen <raisinten@gmail.com>

* fix: add ifdef guard around NetworkService::SetEncryptionKey()

network::mojom::NetworkService::SetEncryptionKey() is only available on
Windows and macOS.

Signed-off-by: Darshan Sen <raisinten@gmail.com>
khalwa pushed a commit to solarwindscloud/electron that referenced this issue Feb 22, 2023
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
15-x-y 16-x-y 17-x-y 18-x-y bug 🪲 platform/linux status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants