2017-03-30 21:25:44 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_certificate_trust.h"
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#import <CoreServices/CoreServices.h>
|
|
|
|
#import <SecurityInterface/SFCertificateTrustPanel.h>
|
|
|
|
|
|
|
|
#include "atom/browser/native_window.h"
|
|
|
|
#include "base/files/file_util.h"
|
|
|
|
#include "base/mac/foundation_util.h"
|
|
|
|
#include "base/mac/mac_util.h"
|
|
|
|
#include "base/mac/scoped_cftyperef.h"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
|
|
#include "net/cert/x509_certificate.h"
|
2017-04-01 01:51:29 +00:00
|
|
|
#include "net/cert/cert_database.h"
|
2017-03-30 21:25:44 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
void ShowCertificateTrustUI(atom::NativeWindow* parent_window,
|
2017-03-31 17:53:42 +00:00
|
|
|
const scoped_refptr<net::X509Certificate>& cert,
|
2017-03-30 21:25:44 +00:00
|
|
|
std::string message,
|
|
|
|
const ShowTrustCallback& callback) {
|
|
|
|
auto sec_policy = SecPolicyCreateBasicX509();
|
|
|
|
SecTrustRef trust = nullptr;
|
2017-03-31 17:53:42 +00:00
|
|
|
SecTrustCreateWithCertificates(cert->CreateOSCertChainForCert(), sec_policy, &trust);
|
2017-03-30 21:25:44 +00:00
|
|
|
// CFRelease(sec_policy);
|
|
|
|
|
2017-04-01 01:51:29 +00:00
|
|
|
// NSWindow* window = parent_window ?
|
|
|
|
// parent_window->GetNativeWindow() :
|
|
|
|
// NULL;
|
2017-03-30 21:25:44 +00:00
|
|
|
|
|
|
|
auto msg = base::SysUTF8ToNSString(message);
|
|
|
|
|
|
|
|
SFCertificateTrustPanel *panel = [[SFCertificateTrustPanel alloc] init];
|
2017-04-01 01:51:29 +00:00
|
|
|
[panel runModalForTrust:trust message:msg];
|
|
|
|
// [panel beginSheetForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:NULL trust:trust message:msg];
|
|
|
|
|
|
|
|
auto cert_db = net::CertDatabase::GetInstance();
|
|
|
|
// This forces Chromium to reload the certificate since it might be trusted
|
|
|
|
// now.
|
|
|
|
cert_db->NotifyObserversCertDBChanged(cert.get());
|
2017-03-30 21:25:44 +00:00
|
|
|
|
|
|
|
callback.Run(true);
|
|
|
|
// CFRelease(trust);
|
|
|
|
// [panel release];
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|