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
|
|
|
#ifndef ATOM_BROWSER_NET_ATOM_CERT_VERIFIER_H_
|
|
|
|
#define ATOM_BROWSER_NET_ATOM_CERT_VERIFIER_H_
|
2015-11-05 14:06:36 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2015-11-12 19:55:23 +00:00
|
|
|
#include "base/memory/ref_counted.h"
|
2015-11-05 14:06:36 +00:00
|
|
|
#include "net/cert/cert_verifier.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2015-11-12 19:55:23 +00:00
|
|
|
class AtomCertVerifier : public net::CertVerifier {
|
2015-11-05 14:06:36 +00:00
|
|
|
public:
|
2015-11-17 13:36:36 +00:00
|
|
|
struct VerifyArgs {
|
|
|
|
scoped_refptr<net::X509Certificate> cert;
|
|
|
|
const std::string& hostname;
|
|
|
|
net::CompletionCallback callback;
|
|
|
|
};
|
|
|
|
|
2015-11-12 19:55:23 +00:00
|
|
|
class CertVerifyRequest
|
2015-11-16 13:28:37 +00:00
|
|
|
: public base::RefCountedThreadSafe<CertVerifyRequest> {
|
2015-11-12 19:55:23 +00:00
|
|
|
public:
|
2015-11-17 11:44:55 +00:00
|
|
|
CertVerifyRequest(AtomCertVerifier* cert_verifier,
|
2015-11-17 13:36:36 +00:00
|
|
|
int result,
|
|
|
|
const VerifyArgs& args)
|
2015-11-12 19:55:23 +00:00
|
|
|
: cert_verifier_(cert_verifier),
|
2015-11-17 13:36:36 +00:00
|
|
|
result_(result),
|
|
|
|
args_(args),
|
2015-11-17 11:00:33 +00:00
|
|
|
handled_(false) {
|
2015-11-12 19:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContinueWithResult(int result);
|
|
|
|
|
2015-11-17 13:36:36 +00:00
|
|
|
const VerifyArgs& args() const { return args_; }
|
2015-11-12 19:55:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class base::RefCountedThreadSafe<CertVerifyRequest>;
|
2015-11-17 13:36:36 +00:00
|
|
|
~CertVerifyRequest();
|
2015-11-17 11:44:55 +00:00
|
|
|
|
2015-11-12 19:55:23 +00:00
|
|
|
AtomCertVerifier* cert_verifier_;
|
2015-11-17 13:36:36 +00:00
|
|
|
int result_;
|
|
|
|
VerifyArgs args_;
|
2015-11-12 19:55:23 +00:00
|
|
|
bool handled_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CertVerifyRequest);
|
|
|
|
};
|
|
|
|
|
2015-11-16 13:28:37 +00:00
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
virtual ~Delegate() {}
|
|
|
|
|
|
|
|
// Called on UI thread.
|
|
|
|
virtual void RequestCertVerification(
|
|
|
|
const scoped_refptr<CertVerifyRequest>& request) {}
|
|
|
|
};
|
|
|
|
|
2015-11-05 14:06:36 +00:00
|
|
|
AtomCertVerifier();
|
2015-11-16 13:28:37 +00:00
|
|
|
virtual ~AtomCertVerifier();
|
|
|
|
|
|
|
|
void SetDelegate(Delegate* delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
2015-11-05 14:06:36 +00:00
|
|
|
|
2015-11-12 19:55:23 +00:00
|
|
|
protected:
|
2015-11-05 14:06:36 +00:00
|
|
|
// net::CertVerifier:
|
|
|
|
int 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) override;
|
|
|
|
bool SupportsOCSPStapling() override;
|
|
|
|
|
|
|
|
private:
|
2015-11-17 11:44:55 +00:00
|
|
|
friend class CertVerifyRequest;
|
2015-11-12 19:55:23 +00:00
|
|
|
|
2015-11-17 13:36:36 +00:00
|
|
|
void VerifyCertificateFromDelegate(const VerifyArgs& args, int result);
|
|
|
|
void OnDefaultVerificationResult(const VerifyArgs& args, int result);
|
|
|
|
|
2015-11-16 13:28:37 +00:00
|
|
|
Delegate* delegate_;
|
2015-11-12 19:55:23 +00:00
|
|
|
scoped_ptr<net::CertVerifier> default_cert_verifier_;
|
2015-11-05 14:06:36 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomCertVerifier);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
2015-11-17 11:03:09 +00:00
|
|
|
#endif // ATOM_BROWSER_NET_ATOM_CERT_VERIFIER_H_
|