From a0be734ccbde189f7972c3d229e4a90d8be8a913 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 23 Oct 2017 13:24:17 +0530 Subject: [PATCH] Fix client certificate private key handling api --- atom/browser/api/atom_api_app.cc | 37 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index e78927ee452d..ada6de3479f7 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -45,6 +45,7 @@ #include "content/public/common/content_switches.h" #include "media/audio/audio_manager.h" #include "native_mate/object_template_builder.h" +#include "net/ssl/client_cert_identity.h" #include "net/ssl/ssl_cert_request_info.h" #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/image/image.h" @@ -420,9 +421,16 @@ bool NotificationCallbackWrapper( return !Browser::Get()->is_shutting_down(); } +void GotPrivateKey(std::shared_ptr delegate, + scoped_refptr cert, + scoped_refptr private_key) { + delegate->ContinueWithCertificate(cert, private_key); +} + void OnClientCertificateSelected( v8::Isolate* isolate, std::shared_ptr delegate, + std::shared_ptr identities, mate::Arguments* args) { if (args->Length() == 2) { delegate->ContinueWithCertificate(nullptr, nullptr); @@ -450,8 +458,14 @@ void OnClientCertificateSelected( data.c_str(), data.length(), net::X509Certificate::FORMAT_AUTO); if (!certs.empty()) { scoped_refptr cert(certs[0].get()); - // FIXME: Pass private key as a second argument. - delegate->ContinueWithCertificate(cert, nullptr); + for (size_t i = 0; i < identities->size(); ++i) { + if (cert->Equals((*identities)[i]->certificate())) { + net::ClientCertIdentity::SelfOwningAcquirePrivateKey( + std::move((*identities)[i]), + base::Bind(&GotPrivateKey, delegate, std::move(cert))); + break; + } + } } } @@ -713,20 +727,23 @@ void App::SelectClientCertificate( for (const std::unique_ptr& identity : identities) client_certs.push_back(identity->certificate()); + auto shared_identities = + std::make_shared(std::move(identities)); + bool prevent_default = Emit("select-client-certificate", WebContents::CreateFrom(isolate(), web_contents), - cert_request_info->host_and_port.ToString(), - std::move(client_certs), - base::Bind(&OnClientCertificateSelected, - isolate(), - shared_delegate)); + cert_request_info->host_and_port.ToString(), std::move(client_certs), + base::Bind(&OnClientCertificateSelected, isolate(), shared_delegate, + shared_identities)); // Default to first certificate from the platform store. if (!prevent_default) { - scoped_refptr cert = identities[0]->certificate(); - // FIXME: Pass private key as a second argument. - shared_delegate->ContinueWithCertificate(cert, nullptr); + scoped_refptr cert = + (*shared_identities)[0]->certificate(); + net::ClientCertIdentity::SelfOwningAcquirePrivateKey( + std::move((*shared_identities)[0]), + base::Bind(&GotPrivateKey, shared_delegate, std::move(cert))); } }