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-12 19:55:23 +00:00
|
|
|
void AtomCertVerifier::CertVerifyRequest::ContinueWithResult(int result) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
|
|
|
|
if (handled_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
handled_ = true;
|
|
|
|
|
|
|
|
if (result != net::ERR_IO_PENDING) {
|
|
|
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
2015-11-17 11:44:55 +00:00
|
|
|
base::Bind(callback_, result));
|
2015-11-12 19:55:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserThread::PostTask(
|
|
|
|
BrowserThread::IO, FROM_HERE,
|
2015-11-17 11:00:33 +00:00
|
|
|
base::Bind(&CertVerifyRequest::DelegateToDefaultVerifier, this));
|
2015-11-12 19:55:23 +00:00
|
|
|
}
|
2015-11-05 14:06:36 +00:00
|
|
|
|
2015-11-17 11:44:55 +00:00
|
|
|
void AtomCertVerifier::CertVerifyRequest::DelegateToDefaultVerifier() {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
|
int result = cert_verifier_->default_cert_verifier_->Verify(
|
|
|
|
cert_.get(), hostname_, ocsp_response_, flags_, crl_set_.get(),
|
|
|
|
verify_result_, callback_, out_req_, net_log_);
|
|
|
|
if (result != net::ERR_IO_PENDING)
|
|
|
|
callback_.Run(result);
|
|
|
|
}
|
|
|
|
|
2015-11-16 13:28:37 +00:00
|
|
|
AtomCertVerifier::AtomCertVerifier()
|
|
|
|
: delegate_(nullptr) {
|
2015-11-05 14:06:36 +00:00
|
|
|
default_cert_verifier_.reset(net::CertVerifier::CreateDefault());
|
|
|
|
}
|
|
|
|
|
|
|
|
AtomCertVerifier::~AtomCertVerifier() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int AtomCertVerifier::Verify(
|
|
|
|
net::X509Certificate* cert,
|
|
|
|
const std::string& hostname,
|
|
|
|
const std::string& ocsp_response,
|
|
|
|
int flags,
|
|
|
|
net::CRLSet* crl_set,
|
|
|
|
net::CertVerifyResult* verify_result,
|
|
|
|
const net::CompletionCallback& callback,
|
|
|
|
scoped_ptr<Request>* out_req,
|
|
|
|
const net::BoundNetLog& net_log) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
|
|
2015-11-16 13:28:37 +00:00
|
|
|
if (callback.is_null() || !verify_result || hostname.empty() || !delegate_)
|
2015-11-05 14:06:36 +00:00
|
|
|
return net::ERR_INVALID_ARGUMENT;
|
|
|
|
|
2015-11-17 11:44:55 +00:00
|
|
|
CertVerifyRequest* request = new CertVerifyRequest(
|
|
|
|
this, cert, hostname, ocsp_response, flags, crl_set, verify_result,
|
|
|
|
callback, out_req, net_log);
|
|
|
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&Delegate::RequestCertVerification,
|
|
|
|
base::Unretained(delegate_),
|
|
|
|
make_scoped_refptr(request)));
|
2015-11-12 19:55:23 +00:00
|
|
|
return net::ERR_IO_PENDING;
|
2015-11-05 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomCertVerifier::SupportsOCSPStapling() {
|
2015-11-12 19:55:23 +00:00
|
|
|
return true;
|
2015-11-05 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|