Merge pull request #3344 from deepak1556/certificate_verifier_api_patch
session: api to allow handling certificate verification
This commit is contained in:
commit
24f573eceb
12 changed files with 436 additions and 17 deletions
|
@ -62,21 +62,6 @@ struct Converter<Browser::UserTask> {
|
|||
};
|
||||
#endif
|
||||
|
||||
template<>
|
||||
struct Converter<scoped_refptr<net::X509Certificate>> {
|
||||
static v8::Local<v8::Value> ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const scoped_refptr<net::X509Certificate>& val) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
std::string encoded_data;
|
||||
net::X509Certificate::GetPEMEncoded(
|
||||
val->os_cert_handle(), &encoded_data);
|
||||
dict.Set("data", encoded_data);
|
||||
dict.Set("issuerName", val->issuer().GetDisplayName());
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/prefs/pref_service.h"
|
||||
|
@ -237,11 +238,21 @@ void SetProxyInIO(net::URLRequestContextGetter* getter,
|
|||
RunCallbackInUI(callback);
|
||||
}
|
||||
|
||||
void PassVerificationResult(
|
||||
scoped_refptr<AtomCertVerifier::CertVerifyRequest> request,
|
||||
bool success) {
|
||||
int result = net::OK;
|
||||
if (!success)
|
||||
result = net::ERR_FAILED;
|
||||
request->ContinueWithResult(result);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Session::Session(AtomBrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
AttachAsUserData(browser_context);
|
||||
browser_context->cert_verifier()->SetDelegate(this);
|
||||
|
||||
// Observe DownloadManger to get download notifications.
|
||||
content::BrowserContext::GetDownloadManager(browser_context)->
|
||||
|
@ -254,6 +265,18 @@ Session::~Session() {
|
|||
Destroy();
|
||||
}
|
||||
|
||||
void Session::RequestCertVerification(
|
||||
const scoped_refptr<AtomCertVerifier::CertVerifyRequest>& request) {
|
||||
bool prevent_default = Emit(
|
||||
"verify-certificate",
|
||||
request->hostname(),
|
||||
request->certificate(),
|
||||
base::Bind(&PassVerificationResult, request));
|
||||
|
||||
if (!prevent_default)
|
||||
request->ContinueWithResult(net::ERR_IO_PENDING);
|
||||
}
|
||||
|
||||
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||
content::DownloadItem* item) {
|
||||
auto web_contents = item->GetWebContents();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/atom_cert_verifier.h"
|
||||
#include "content/public/browser/download_manager.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/base/completion_callback.h"
|
||||
|
@ -34,6 +35,7 @@ class AtomBrowserContext;
|
|||
namespace api {
|
||||
|
||||
class Session: public mate::TrackableObject<Session>,
|
||||
public AtomCertVerifier::Delegate,
|
||||
public content::DownloadManager::Observer {
|
||||
public:
|
||||
using ResolveProxyCallback = base::Callback<void(std::string)>;
|
||||
|
@ -52,6 +54,10 @@ class Session: public mate::TrackableObject<Session>,
|
|||
explicit Session(AtomBrowserContext* browser_context);
|
||||
~Session();
|
||||
|
||||
// AtomCertVerifier::Delegate:
|
||||
void RequestCertVerification(
|
||||
const scoped_refptr<AtomCertVerifier::CertVerifyRequest>&) override;
|
||||
|
||||
// content::DownloadManager::Observer:
|
||||
void OnDownloadCreated(content::DownloadManager* manager,
|
||||
content::DownloadItem* item) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue