app: api to import client certificate
This commit is contained in:
parent
0bf1e56156
commit
e81cec4058
6 changed files with 374 additions and 31 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "base/command_line.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
|
@ -157,6 +158,43 @@ void PassLoginInformation(scoped_refptr<LoginHandler> login_handler,
|
|||
login_handler->CancelAuth();
|
||||
}
|
||||
|
||||
net::CertificateList ImportCertsFromFile(
|
||||
const base::FilePath& path) {
|
||||
net::CertificateList certs;
|
||||
if (path.empty())
|
||||
return certs;
|
||||
|
||||
std::string cert_data;
|
||||
if (!base::ReadFileToString(path, &cert_data))
|
||||
return certs;
|
||||
|
||||
certs = net::X509Certificate::CreateCertificateListFromBytes(
|
||||
cert_data.data(), cert_data.size(),
|
||||
net::X509Certificate::FORMAT_AUTO);
|
||||
|
||||
return certs;
|
||||
}
|
||||
|
||||
int ImportCertificateIntoCertStore(
|
||||
CertificateManagerModel* model,
|
||||
const base::FilePath& path,
|
||||
const base::FilePath& ca_path,
|
||||
const base::string16& password) {
|
||||
LOG(WARNING) << "importing ....";
|
||||
|
||||
std::string file_data;
|
||||
int result = -1;
|
||||
net::CertificateList ca_certs;
|
||||
net::NSSCertDatabase::ImportCertFailureList not_imported;
|
||||
auto module = model->cert_db()->GetPublicModule();
|
||||
if (base::ReadFileToString(path, &file_data)) {
|
||||
result &= model->ImportFromPKCS12(module, file_data, password, true);
|
||||
ca_certs = ImportCertsFromFile(ca_path);
|
||||
result &= model->ImportCACerts(ca_certs, net::NSSCertDatabase::TRUST_DEFAULT, ¬_imported);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
App::App() {
|
||||
|
@ -369,6 +407,34 @@ bool App::MakeSingleInstance(
|
|||
}
|
||||
}
|
||||
|
||||
void App::ImportClientCertificate(
|
||||
const base::FilePath& path,
|
||||
const base::FilePath& ca_path,
|
||||
|
||||
const base::string16& password,
|
||||
const net::CompletionCallback& callback) {
|
||||
auto browser_context = AtomBrowserMainParts::Get()->browser_context();
|
||||
if (!certificate_manager_model_) {
|
||||
CertificateManagerModel::Create(browser_context, base::Bind(&App::OnCertificateManagerModelCreated, base::Unretained(this), path, ca_path, password, callback));
|
||||
return;
|
||||
}
|
||||
|
||||
int rv = ImportCertificateIntoCertStore(certificate_manager_model_.get(), path, ca_path, password);
|
||||
callback.Run(rv);
|
||||
}
|
||||
|
||||
void App::OnCertificateManagerModelCreated(
|
||||
const base::FilePath& path,
|
||||
const base::FilePath& ca_path,
|
||||
const base::string16& password,
|
||||
const net::CompletionCallback& callback,
|
||||
scoped_ptr<CertificateManagerModel> model) {
|
||||
certificate_manager_model_ = std::move(model);
|
||||
|
||||
int rv = ImportCertificateIntoCertStore(certificate_manager_model_.get(), path, ca_path, password);
|
||||
callback.Run(rv);
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
auto browser = base::Unretained(Browser::Get());
|
||||
|
@ -408,7 +474,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
|||
.SetMethod("allowNTLMCredentialsForAllDomains",
|
||||
&App::AllowNTLMCredentialsForAllDomains)
|
||||
.SetMethod("getLocale", &App::GetLocale)
|
||||
.SetMethod("makeSingleInstance", &App::MakeSingleInstance);
|
||||
.SetMethod("makeSingleInstance", &App::MakeSingleInstance)
|
||||
.SetMethod("importClientCertificate", &App::ImportClientCertificate);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -11,9 +11,11 @@
|
|||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "chrome/browser/certificate_manager_model.h"
|
||||
#include "chrome/browser/process_singleton.h"
|
||||
#include "content/public/browser/gpu_data_manager_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/base/completion_callback.h"
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
|
@ -41,6 +43,13 @@ class App : public AtomBrowserClient::Delegate,
|
|||
int render_process_id,
|
||||
int render_frame_id);
|
||||
|
||||
void OnCertificateManagerModelCreated(
|
||||
const base::FilePath& path,
|
||||
const base::FilePath& ca_path,
|
||||
const base::string16& password,
|
||||
const net::CompletionCallback& callback,
|
||||
scoped_ptr<CertificateManagerModel> model);
|
||||
|
||||
protected:
|
||||
App();
|
||||
virtual ~App();
|
||||
|
@ -97,12 +106,14 @@ class App : public AtomBrowserClient::Delegate,
|
|||
bool MakeSingleInstance(
|
||||
const ProcessSingleton::NotificationCallback& callback);
|
||||
std::string GetLocale();
|
||||
void ImportClientCertificate(const base::FilePath& path, const base::FilePath& ca_path, const base::string16& password, const net::CompletionCallback& callback);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
bool IsAeroGlassEnabled();
|
||||
#endif
|
||||
|
||||
scoped_ptr<ProcessSingleton> process_singleton_;
|
||||
scoped_ptr<CertificateManagerModel> certificate_manager_model_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(App);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue