macOS: Add certificate trust API #9099
Conversation
|
|
||
| void ShowCertificateTrust(atom::NativeWindow* parent_window, | ||
| const scoped_refptr<net::X509Certificate>& cert, | ||
| std::string message, |
kevinsawicki
Apr 3, 2017
Contributor
Could this be const std::string& to match the other params?
Could this be const std::string& to match the other params?
| @@ -68,11 +69,72 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8( | |||
| val->GetIntermediateCertificates().front(), | |||
| issuer_intermediates); | |||
| dict.Set("issuerCert", issuer_cert); | |||
|
|
|||
| std::vector<std::string> intermediates_encoded; | |||
| for (size_t i = 0; i < intermediates.size(); i++) { | |||
kevinsawicki
Apr 3, 2017
Contributor
I think this could be for (auto& native_cert : intermediates)
I think this could be for (auto& native_cert : intermediates)
| @@ -19,6 +19,7 @@ | |||
| #include "content/public/browser/gpu_data_manager_observer.h" | |||
| #include "native_mate/handle.h" | |||
| #include "net/base/completion_callback.h" | |||
| #include "net/cert/x509_certificate.h" | |||
kevinsawicki
Apr 3, 2017
Contributor
🔥
| for (size_t i = 0; i < intermediates.size(); i++) { | ||
| auto native_cert = intermediates[i]; | ||
| std::string encoded; | ||
| net::X509Certificate::GetPEMEncoded(native_cert, &encoded); |
kevinsawicki
Apr 3, 2017
Contributor
This method does return a bool, wonder if we should only push encoded to the vector when it returns true?
This method does return a bool, wonder if we should only push encoded to the vector when it returns true?
joshaber
Apr 3, 2017
Author
Contributor
I'm a little torn on that. On the one hand, I like being careful. On the other hand, we don't have any way of signaling that "yooooo we couldn't encode this one." And if we encode some nonsense, that has the funny upside of failing when we FromV8 the certificate. On the other hand, it's hard to know exactly what shape of nonsense we'll get if this fails.
What do you think?
I'm a little torn on that. On the one hand, I like being careful. On the other hand, we don't have any way of signaling that "yooooo we couldn't encode this one." And if we encode some nonsense, that has the funny upside of failing when we FromV8 the certificate. On the other hand, it's hard to know exactly what shape of nonsense we'll get if this fails.
What do you think?
kevinsawicki
Apr 3, 2017
Contributor
What do you think?
Hmm, yeah, looks like we don't use the return value on the root certificate so makes sense not to use it here either, can revisit separately.
What do you think?
Hmm, yeah, looks like we don't use the return value on the root certificate so makes sense not to use it here either, can revisit separately.
kevinsawicki
Apr 3, 2017
Contributor
Would it make sense for intermediates to be an array of objects though that is the full cert information instead of just the encoded part?
I think it could just reuse what dict.Set("issuerCert", issuer_cert); does.
Would it make sense for intermediates to be an array of objects though that is the full cert information instead of just the encoded part?
I think it could just reuse what dict.Set("issuerCert", issuer_cert); does.
joshaber
Apr 3, 2017
Author
Contributor
Yeah I'm into it 👍
Yeah I'm into it
| nil; | ||
| auto msg = base::SysUTF8ToNSString(message); | ||
|
|
||
| SFCertificateTrustPanel *panel = [[SFCertificateTrustPanel alloc] init]; |
kevinsawicki
Apr 3, 2017
Contributor
Super minor: SFCertificateTrustPanel* panel
Super minor: SFCertificateTrustPanel* panel
| @@ -119,13 +121,27 @@ void ShowSaveDialog(const file_dialog::DialogSettings& settings, | |||
| } | |||
| } | |||
|
|
|||
| #if defined(OS_MACOSX) | |||
| void ShowCertificateTrust(atom::NativeWindow* parent_window, | |||
kevinsawicki
Apr 3, 2017
Contributor
I think you can delete this method and just use the following below:
dict.SetMethod("showCertificateTrustDialog",
&certificate_trust::ShowCertificateTrust);
I think you can delete this method and just use the following below:
dict.SetMethod("showCertificateTrustDialog",
&certificate_trust::ShowCertificateTrust);| @@ -175,6 +175,17 @@ it is usually used to report errors in early stage of startup. If called | |||
| before the app `ready`event on Linux, the message will be emitted to stderr, | |||
| and no GUI dialog will appear. | |||
|
|
|||
| ### `dialog.showCertificateTrustDialog(browserWindow, certificate, message, callback)` _macOS_ | |||
kevinsawicki
Apr 3, 2017
Contributor
If/when this gets support on other platforms there might be some additional options needed so it might be better to start this off as:
dialog.showCertificateTrustDialog(browserWindow, options, callback)
You can leave the C++ signature as-is, and just pluck the options in JS like showMessageBox does.
If/when this gets support on other platforms there might be some additional options needed so it might be better to start this off as:
dialog.showCertificateTrustDialog(browserWindow, options, callback)You can leave the C++ signature as-is, and just pluck the options in JS like showMessageBox does.
| @@ -279,6 +279,8 @@ | |||
| 'atom/browser/ui/accelerator_util_views.cc', | |||
| 'atom/browser/ui/atom_menu_model.cc', | |||
| 'atom/browser/ui/atom_menu_model.h', | |||
| 'atom/browser/ui/certificate_trust_mac.mm', | |||
| 'atom/browser/ui/certificate_trust.h', | |||
kevinsawicki
Apr 3, 2017
Contributor
Super minor: I think the order here should be swapped, looks like . sorts before _ in other places in this list like file_dialog.h.
Super minor: I think the order here should be swapped, looks like . sorts before _ in other places in this list like file_dialog.h.
| return self; | ||
| } | ||
|
|
||
| - (void)panelDidEnd:(NSWindow *)sheet |
kevinsawicki
Apr 3, 2017
Contributor
🔥 the space between NSWindow and *
NSWindow and *
| certChain:(CFArrayRef)certChain | ||
| secPolicy:(SecPolicyRef)secPolicy; | ||
|
|
||
| - (void)panelDidEnd:(NSWindow *)sheet |
kevinsawicki
Apr 3, 2017
Contributor
🔥 the space between NSWindow and *
NSWindow and *
|
|
| @@ -73,6 +73,54 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8( | |||
| return dict.GetHandle(); | |||
| } | |||
|
|
|||
| bool CertFromData(const std::string& data, | |||
deepak1556
Apr 4, 2017
Member
Can be moved to an anonymous namespace.
Can be moved to an anonymous namespace.
It's meaningless on macOS, at least.
|
|
| } | ||
|
|
||
| let {certificate, message} = options | ||
| if (certificate == null || typeof options !== 'object') { |
kevinsawicki
Apr 4, 2017
Contributor
Should this be typeof certificate !== 'object' instead?
Should this be typeof certificate !== 'object' instead?
joshaber
Apr 4, 2017
Author
Contributor
Ha, good catch 👍
Ha, good catch
|
|
3e9014c
into
master
|
Thanks @joshaber, great work on this |
Continuing from #9068
Add the
dialog.showCertificateTrustDialogAPI to show the OS-provided UI to let the user decide to accept and trust a self-signed or untrusted certificate:This is only the macOS-side of things. I think we can get @shiftkey to do the Windows side.
I'm opening this early because I have no idea what I'm doing and I'd welcome any feedback or advice anyone would like to provide.