#include "atom/browser/browser.h"
#include "atom/browser/login_handler.h"
#include "atom/common/native_mate_converters/callback.h"
-#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
+#include "atom/common/native_mate_converters/net_converter.h"
+#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
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(
+int ImportIntoCertStore(
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);
+ const base::DictionaryValue& options) {
+ std::string file_data, cert_path;
+ base::string16 password;
+ net::CertificateList imported_certs;
+ int rv;
+ options.GetString("clientCertificate", &cert_path);
+ options.GetString("password", &password);
+
+ if (!cert_path.empty()) {
+ if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
+ auto module = model->cert_db()->GetPublicModule();
+ rv = model->ImportFromPKCS12(module,
+ file_data,
+ password,
+ true,
+ &imported_certs);
+ if (imported_certs.size() > 1) {
+ auto it = imported_certs.begin();
+ ++it; // skip first which would be the client certificate.
+ for (; it != imported_certs.end(); ++it)
+ rv &= model->SetCertTrust(it->get(),
+ net::CA_CERT,
+ net::NSSCertDatabase::TRUSTED_SSL);
+ }
+ }
}
- return result;
+ return rv;
}
} // namespace
}
void App::ImportClientCertificate(
- const base::FilePath& path,
- const base::FilePath& ca_path,
-
- const base::string16& password,
+ const base::DictionaryValue& options,
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));
+ scoped_ptr<base::DictionaryValue> copy = options.CreateDeepCopy();
+ CertificateManagerModel::Create(browser_context,
+ base::Bind(&App::OnCertificateManagerModelCreated,
+ base::Unretained(this),
+ base::Passed(©),
+ callback));
return;
}
- int rv = ImportCertificateIntoCertStore(certificate_manager_model_.get(), path, ca_path, password);
+ int rv = ImportIntoCertStore(certificate_manager_model_.get(), options);
callback.Run(rv);
}
void App::OnCertificateManagerModelCreated(
- const base::FilePath& path,
- const base::FilePath& ca_path,
- const base::string16& password,
+ scoped_ptr<base::DictionaryValue> options,
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);
+ int rv = ImportIntoCertStore(certificate_manager_model_.get(),
+ *(options.get()));
callback.Run(rv);
}
.SetMethod("allowNTLMCredentialsForAllDomains",
&App::AllowNTLMCredentialsForAllDomains)
.SetMethod("getLocale", &App::GetLocale)
- .SetMethod("makeSingleInstance", &App::MakeSingleInstance)
- .SetMethod("importClientCertificate", &App::ImportClientCertificate);
+#if defined(OS_LINUX)
+ .SetMethod("importClientCertificate", &App::ImportClientCertificate)
+#endif
+ .SetMethod("makeSingleInstance", &App::MakeSingleInstance);
}
// static
#include <utility>
#include "base/bind.h"
-#include "base/i18n/time_formatting.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
-#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "net/base/net_errors.h"
#include "net/cert/nss_cert_database.h"
#include "net/cert/x509_certificate.h"
-#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
// GetNSSCertDatabaseForResourceContext
// |
// CertificateManagerModel::DidGetCertDBOnIOThread
-// |
-// crypto::IsTPMTokenEnabledForNSS
// v--------------------------------------/
// CertificateManagerModel::DidGetCertDBOnUIThread
// |
int CertificateManagerModel::ImportFromPKCS12(net::CryptoModule* module,
const std::string& data,
const base::string16& password,
- bool is_extractable) {
+ bool is_extractable,
+ net::CertificateList* imported_certs) {
return cert_db_->ImportFromPKCS12(module, data, password,
- is_extractable, NULL);
+ is_extractable, imported_certs);
}
int CertificateManagerModel::ImportUserCert(const std::string& data) {
net::NSSCertDatabase::TrustBits trust_bits,
net::NSSCertDatabase::ImportCertFailureList* not_imported) {
return cert_db_->ImportServerCert(certificates, trust_bits,
- not_imported);
+ not_imported);
}
bool CertificateManagerModel::SetCertTrust(