Skip to content

macOS: Add certificate trust API - #9099

Merged
kevinsawicki merged 36 commits into
masterfrom
certificate-trust
Apr 4, 2017
Merged

kevinsawicki merged 36 commits into
masterfrom
certificate-trust

Conversation

@joshaber

@joshaber joshaber commented Apr 3, 2017

Copy link
Copy Markdown
Contributor

Continuing from #9068

Add the dialog.showCertificateTrustDialog API to show the OS-provided UI to let the user decide to accept and trust a self-signed or untrusted certificate:

cert_trust_panel_5b4faf16-9b52-4d4f-8aa0-63b89361dd60

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.

Comment thread atom/browser/ui/certificate_trust.h Outdated

void ShowCertificateTrust(atom::NativeWindow* parent_window,
const scoped_refptr<net::X509Certificate>& cert,
std::string message,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be const std::string& to match the other params?

dict.Set("issuerCert", issuer_cert);

std::vector<std::string> intermediates_encoded;
for (size_t i = 0; i < intermediates.size(); i++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this could be for (auto& native_cert : intermediates)

Comment thread atom/browser/api/atom_api_app.h Outdated
#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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔥

for (size_t i = 0; i < intermediates.size(); i++) {
auto native_cert = intermediates[i];
std::string encoded;
net::X509Certificate::GetPEMEncoded(native_cert, &encoded);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method does return a bool, wonder if we should only push encoded to the vector when it returns true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm into it 👍

@joshaber joshaber changed the title [WIP] macOS: Add certificate trust API macOS: Add certificate trust API Apr 3, 2017
cert_db->NotifyObserversCertDBChanged(cert_.get());
}

callback_.Run(returnCode);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the callback expects a bool, what do you think about comparing the value passed to the return code constants for clarity like:

 callback_.Run(returnCode == NSFileHandlingPanelOKButton ? true : false);

Or maybe add an else block that calls it with false and call it with true in the if block?

nil;
auto msg = base::SysUTF8ToNSString(message);

SFCertificateTrustPanel *panel = [[SFCertificateTrustPanel alloc] init];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Super minor: SFCertificateTrustPanel* panel

Comment thread atom/browser/api/atom_api_dialog.cc Outdated
}

#if defined(OS_MACOSX)
void ShowCertificateTrust(atom::NativeWindow* parent_window,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can delete this method and just use the following below:

dict.SetMethod("showCertificateTrustDialog",
               &certificate_trust::ShowCertificateTrust);

Comment thread docs/api/dialog.md Outdated
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_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread filenames.gypi
'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',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔥 the space between NSWindow and *

certChain:(CFArrayRef)certChain
secPolicy:(SecPolicyRef)secPolicy;

- (void)panelDidEnd:(NSWindow *)sheet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔥 the space between NSWindow and *

@kevinsawicki kevinsawicki self-assigned this Apr 3, 2017
@joshaber

joshaber commented Apr 4, 2017

Copy link
Copy Markdown
Contributor Author

🏓

return dict.GetHandle();
}

bool CertFromData(const std::string& data,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be moved to an anonymous namespace.

@joshaber

joshaber commented Apr 4, 2017

Copy link
Copy Markdown
Contributor Author

🍍

Comment thread lib/browser/api/dialog.js Outdated
}

let {certificate, message} = options
if (certificate == null || typeof options !== 'object') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be typeof certificate !== 'object' instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ha, good catch 👍

@joshaber

joshaber commented Apr 4, 2017

Copy link
Copy Markdown
Contributor Author

⛏

@kevinsawicki
kevinsawicki merged commit 3e9014c into master Apr 4, 2017
@kevinsawicki

Copy link
Copy Markdown
Contributor

Thanks @joshaber, great work on this 👍

@kevinsawicki
kevinsawicki deleted the certificate-trust branch April 4, 2017 18:17
@shiftkey shiftkey mentioned this pull request Apr 21, 2017
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants