certificate trust API for Windows #9242
Conversation
|
Looks like a great start here, let me know if you have any questions or when it is ready to review, |
|
@kevinsawicki I think the only issue I have at this stage is with the debugging experience:
Is there anything I need to be aware of when generating |
| The `browserWindow` argument allows the dialog to attach itself to a parent | ||
| window, making it modal. | ||
| On macOS the `browserWindow` argument allows the dialog to attach itself to a parent | ||
| window, making it modal. On Windows a modal dialog is not supported. |
joshaber
Apr 24, 2017
Contributor
Or it looks like it's always a modal dialog on Windows?
Or it looks like it's always a modal dialog on Windows?
shiftkey
Apr 26, 2017
Author
Contributor
This is probably getting way into obscure Win32 territory, but there's no way to pass a window handle to CertAddCertificateContextToStore to associate the popup message with a parent window - so modality isn't enforced here (that is, you can interact with the window without acknowledging the popup).
I need to tidy this these docs, but I also had a idea to show a dialog before this step with the message argument that the caller provides.
This is probably getting way into obscure Win32 territory, but there's no way to pass a window handle to CertAddCertificateContextToStore to associate the popup message with a parent window - so modality isn't enforced here (that is, you can interact with the window without acknowledging the popup).
I need to tidy this these docs, but I also had a idea to show a dialog before this step with the message argument that the caller provides.
joshaber
Apr 26, 2017
Contributor
Ahhhh I see 👍
Ahhhh I see
|
I found myself off spending way too much time thinking about certificate chains and trust which we didn't really need to do here (only handle self-signed certs). I'm going to throw some more testing at it in a live app to ensure I haven't missed anything but I think this is ready for a first round of reviewing. |
| // store for the current user. | ||
| // | ||
| // This requires prompting the user to confirm they trust the certificate. | ||
| BOOL AddToTrustedRootStore(const PCCERT_CONTEXT certContext, |
kevinsawicki
Apr 28, 2017
Contributor
Underscore case names (cert_context) are preferred, looks like there are several camel cases in this file currently.
Underscore case names (cert_context) are preferred, looks like there are several camel cases in this file currently.
| NULL, | ||
| NULL, | ||
| &chainContext)) { | ||
| switch (chainContext->TrustStatus.dwErrorStatus) { |
kevinsawicki
Apr 28, 2017
•
Contributor
Maybe an if block would make this a little more direct and concise, unless you are planning to add more cases to this block in this PR:
if (chainContext->TrustStatus.dwErrorStatus == CERT_TRUST_IS_SELF_SIGNED) {
AddToTrustedRootStore(pCertContext, cert);
}
Maybe an if block would make this a little more direct and concise, unless you are planning to add more cases to this block in this PR:
if (chainContext->TrustStatus.dwErrorStatus == CERT_TRUST_IS_SELF_SIGNED) {
AddToTrustedRootStore(pCertContext, cert);
}| On macOS, this displays a modal dialog that shows a message and certificate | ||
| information, and gives the user the option of trusting/importing the | ||
| certificate. If you provide a `browserWindow` argument the dialog will be | ||
| attached to the parent window, makign it modal. |
kevinsawicki
Apr 28, 2017
•
Contributor
makign -> making
makign -> making
| window, making it modal. | ||
| On Windows the options are more limited, due to the Win32 APIs used: | ||
|
|
||
| - the `message` argument is not used, as the OS provides it's own confirmation |
kevinsawicki
Apr 28, 2017
Contributor
it's -> its
it's -> its
kevinsawicki
Apr 28, 2017
Contributor
the -> The
the -> The
|
|
||
| - the `message` argument is not used, as the OS provides it's own confirmation | ||
| dialog. | ||
| - it is not possible to make this confirmation dialog modal. |
kevinsawicki
Apr 28, 2017
Contributor
Maybe expand a bit to mention browserWindow is ignored:
The `browserWindow` argument is ignored since it is not possible to make this confirmation dialog modal.
Maybe expand a bit to mention browserWindow is ignored:
The `browserWindow` argument is ignored since it is not possible to make this confirmation dialog modal.
|
Left a few very minor style comments, code looks great otherwise |
| @@ -0,0 +1,101 @@ | |||
| // Copyright (c) 2013 GitHub, Inc. | |||
anaisbetts
Apr 28, 2017
Contributor
Are we sure that there isn't a Chromium version of this code? https://cs.chromium.org/chromium/src/net/ssl/client_cert_store_win.cc?q=CertAddCertificateContextToStore+package:%5Echromium$&dr=C looks promising
Are we sure that there isn't a Chromium version of this code? https://cs.chromium.org/chromium/src/net/ssl/client_cert_store_win.cc?q=CertAddCertificateContextToStore+package:%5Echromium$&dr=C looks promising
kevinsawicki
Apr 28, 2017
Contributor
Hmm, I'm not seeing a public API in https://cs.chromium.org/chromium/src/net/ssl/client_cert_store.h?dr=C or https://cs.chromium.org/chromium/src/net/ssl/client_cert_store_win.h?dr=C to add a certificate to the store.
Hmm, I'm not seeing a public API in https://cs.chromium.org/chromium/src/net/ssl/client_cert_store.h?dr=C or https://cs.chromium.org/chromium/src/net/ssl/client_cert_store_win.h?dr=C to add a certificate to the store.
anaisbetts
May 4, 2017
Contributor
Oh I just mean code that would be good for copy-pasting - any time you can copy-paste security code instead of writing it yourself it's a Good Thing
Oh I just mean code that would be good for copy-pasting - any time you can copy-paste security code instead of writing it yourself it's a Good Thing
| @@ -0,0 +1,101 @@ | |||
| // Copyright (c) 2013 GitHub, Inc. | |||
kevinsawicki
Apr 28, 2017
Contributor
2013 -> 2017
2013 -> 2017
So I tried testing this using https://badssl.com via |
|
@kevinsawicki yep, we can handle those two in the same way - looks like we get |
|
Yep, I'm happy with the testing of this for those two scenarios above. Let me know if there's anything else left to do to get this merged |
|
@kevinsawicki friendly bump |
|
Thanks @shiftkey |
|
Correct me if I'm wrong, but it looks like this only supports importing certificates to the operating systems' trust chain? If this is the case, self signed certs will still throw up a nastygram in Firefox, which relies exclusively on its own certdb. |
Yes, because this is what an Electron app relies on for it's certificate validation. |
|
Got it, thanks. I have an Electron app that spins up local Express servers and generates self-signed certs on the fly. Handling trust chain support for the OS wasn't too taxing, but Firefox support was pretty gnarly... I was hoping for a cleaner approach :-) I may still use this for working with OS trust chains though. Great work on all of this. |
This is the second half of #9099 - adding the certificate trust API for Windows.
The Setup
I've configured a local IIS instance with a self-signed certificate to trigger this failure over HTTPS. Edge and IE don't like it, and spit this error out at the user:
I can write up the way to setup this environment locally if others want to test this flow out themselves. The sample app I've been using can be found here: shiftkey/electron-test-network-windows
User Experience
The magic in
certificate_trust_win.ccis some code I've tested in isolation to resolve the above error. It installs the received certificate to the Trusted Root Certificate for the current user (not the local computer) and because we're only doing it for the current user it doesn't require elevation.However, interacting with the trusted root certificate store will trigger this dialog when you invoke
CertAddCertificateContextToStore:It's certainly not as pretty (or as functional) as the macOS equivalent, but that might be okay for now. As a result I'm also not using the
messageargument thatShowCertificateTrustreceives. I'm open to putting more context into this flow based on feedback and security concerns - this is just a first pass.Testing
I'm currently at the point where the test app has the right IPC setup to trigger the certificate error, but I'm missing something with the "swap in a debug version" process and the
dialog.showCertificateTrustDialogmethod isn't visible on Windows (there's nothing in the original PR to suggest this is being hidden deliberately).Here's my flow for testing this PR (I've probably missed something):
#if definedherepython script\bootstrap.py --msvsto get a VS solution filenpm run buildto get a debug build of my branchout\D\*tonode_modules\electron\dist\I can then run the test harness, attach to the
electron.exeprocesses and VS loads the PDB symbols for electron.exe and node.exe.UPDATE: there's something up with how
electron.asaris being packaged for debug builds - I've repackaged that archive with theshowCertificateTrustDialogmethod and I can launch the dialog in the app.TODO
ShowCertificateTrustgracefully, ensuring we cleanup any resources