2015-11-05 14:06:36 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-17 11:03:09 +00:00
|
|
|
#include "atom/browser/net/atom_cert_verifier.h"
|
2015-11-05 14:06:36 +00:00
|
|
|
|
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include "atom/common/native_mate_converters/net_converter.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "net/base/net_errors.h"
|
2015-11-17 11:44:55 +00:00
|
|
|
#include "net/cert/crl_set.h"
|
|
|
|
#include "net/cert/x509_certificate.h"
|
2015-11-05 14:06:36 +00:00
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2015-11-18 03:17:08 +00:00
|
|
|
namespace {
|
2015-11-12 19:55:23 +00:00
|
|
|
|
2015-11-18 03:17:08 +00:00
|
|
|
void OnResult(
|
|
|
|
net::CertVerifyResult* verify_result,
|
|
|
|
const net::CompletionCallback& callback,
|
|
|
|
bool result) {
|
2015-11-12 19:55:23 +00:00
|
|
|
BrowserThread::PostTask(
|
|
|
|
BrowserThread::IO, FROM_HERE,
|
2015-11-18 03:17:08 +00:00
|
|
|
base::Bind(callback, result ? net::OK : net::ERR_FAILED));
|
2015-11-17 11:44:55 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 03:17:08 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-11-16 13:28:37 +00:00
|
|
|
AtomCertVerifier::AtomCertVerifier()
|
2015-11-18 03:17:08 +00:00
|
|
|
: default_cert_verifier_(net::CertVerifier::CreateDefault()) {
|
2015-11-05 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomCertVerifier::~AtomCertVerifier() {
|
|
|
|
}
|
|
|
|
|
2015-11-18 03:17:08 +00:00
|
|
|
void AtomCertVerifier::SetVerifyProc(const VerifyProc& proc) {
|
|
|
|
verify_proc_ = proc;
|
|
|
|
}
|
|
|
|
|
2015-11-05 14:06:36 +00:00
|
|
|
int AtomCertVerifier::Verify(
|
2016-09-06 08:24:37 +00:00
|
|
|
const RequestParams& params,
|
2015-11-05 14:06:36 +00:00
|
|
|
net::CRLSet* crl_set,
|
|
|
|
net::CertVerifyResult* verify_result,
|
|
|
|
const net::CompletionCallback& callback,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<Request>* out_req,
|
2015-11-05 14:06:36 +00:00
|
|
|
const net::BoundNetLog& net_log) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
|
|
2016-07-13 03:07:57 +00:00
|
|
|
if (verify_proc_.is_null())
|
2015-11-18 03:17:08 +00:00
|
|
|
return default_cert_verifier_->Verify(
|
2016-09-06 08:24:37 +00:00
|
|
|
params, crl_set, verify_result, callback, out_req, net_log);
|
2015-11-18 03:17:08 +00:00
|
|
|
|
|
|
|
BrowserThread::PostTask(
|
|
|
|
BrowserThread::UI, FROM_HERE,
|
2016-09-06 08:24:37 +00:00
|
|
|
base::Bind(verify_proc_, params.hostname(), params.certificate(),
|
2015-11-18 03:17:08 +00:00
|
|
|
base::Bind(OnResult, verify_result, callback)));
|
|
|
|
return net::ERR_IO_PENDING;
|
2015-11-17 13:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomCertVerifier::SupportsOCSPStapling() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-05 14:06:36 +00:00
|
|
|
} // namespace atom
|