| Index: net/base/cert_verifier.h
|
| ===================================================================
|
| --- net/base/cert_verifier.h (revision 128056)
|
| +++ net/base/cert_verifier.h (working copy)
|
| @@ -6,50 +6,36 @@
|
| #define NET_BASE_CERT_VERIFIER_H_
|
| #pragma once
|
|
|
| -#include <map>
|
| #include <string>
|
|
|
| #include "base/basictypes.h"
|
| -#include "base/gtest_prod_util.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| -#include "base/threading/non_thread_safe.h"
|
| -#include "net/base/cert_database.h"
|
| -#include "net/base/cert_verify_result.h"
|
| #include "net/base/completion_callback.h"
|
| -#include "net/base/expiring_cache.h"
|
| #include "net/base/net_export.h"
|
| -#include "net/base/x509_cert_types.h"
|
|
|
| namespace net {
|
|
|
| class BoundNetLog;
|
| -class CertVerifierJob;
|
| -class CertVerifierWorker;
|
| +class CertVerifyResult;
|
| class CRLSet;
|
| class X509Certificate;
|
|
|
| // CertVerifier represents a service for verifying certificates.
|
| //
|
| -// CertVerifier can handle multiple requests at a time, so when canceling a
|
| -// request the RequestHandle that was returned by Verify() needs to be
|
| -// given. A simpler alternative for consumers that only have 1 outstanding
|
| -// request at a time is to create a SingleRequestCertVerifier wrapper around
|
| -// CertVerifier (which will automatically cancel the single request when it
|
| -// goes out of scope).
|
| -class NET_EXPORT CertVerifier : NON_EXPORTED_BASE(public base::NonThreadSafe),
|
| - public CertDatabase::Observer {
|
| +// CertVerifiers can handle multiple requests at a time. A simpler alternative
|
| +// for consumers that only have 1 outstanding request at a time is to create a
|
| +// SingleRequestCertVerifier wrapper around CertVerifier (which will
|
| +// automatically cancel the single request when it goes out of scope).
|
| +class NET_EXPORT CertVerifier {
|
| public:
|
| - // Opaque type used to cancel a request.
|
| + // Opaque pointer type used to cancel outstanding requests.
|
| typedef void* RequestHandle;
|
|
|
| - CertVerifier();
|
| -
|
| - // When the verifier is destroyed, all certificate verifications requests are
|
| + // When the verifier is destroyed, all certificate verification requests are
|
| // canceled, and their completion callbacks will not be called.
|
| - virtual ~CertVerifier();
|
| + virtual ~CertVerifier() {}
|
|
|
| - // Verifies the given certificate against the given hostname. Returns OK if
|
| - // successful or an error code upon failure.
|
| + // Verifies the given certificate against the given hostname as an SSL server.
|
| + // Returns OK if successful or an error code upon failure.
|
| //
|
| // The |*verify_result| structure, including the |verify_result->cert_status|
|
| // bitmask, is always filled out regardless of the return value. If the
|
| @@ -76,141 +62,26 @@
|
| // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to
|
| // the async request. This handle is not valid after the request has
|
| // completed.
|
| - int Verify(X509Certificate* cert,
|
| - const std::string& hostname,
|
| - int flags,
|
| - CRLSet* crl_set,
|
| - CertVerifyResult* verify_result,
|
| - const CompletionCallback& callback,
|
| - RequestHandle* out_req,
|
| - const BoundNetLog& net_log);
|
| + //
|
| + // TODO(rsleevi): Move CRLSet* out of the CertVerifier signature.
|
| + virtual int Verify(X509Certificate* cert,
|
| + const std::string& hostname,
|
| + int flags,
|
| + CRLSet* crl_set,
|
| + CertVerifyResult* verify_result,
|
| + const CompletionCallback& callback,
|
| + RequestHandle* out_req,
|
| + const BoundNetLog& net_log) = 0;
|
|
|
| // Cancels the specified request. |req| is the handle returned by Verify().
|
| // After a request is canceled, its completion callback will not be called.
|
| - void CancelRequest(RequestHandle req);
|
| + virtual void CancelRequest(RequestHandle req) = 0;
|
|
|
| - private:
|
| - friend class CertVerifierWorker; // Calls HandleResult.
|
| - friend class CertVerifierRequest;
|
| - friend class CertVerifierJob;
|
| - FRIEND_TEST_ALL_PREFIXES(CertVerifierTest, CacheHit);
|
| - FRIEND_TEST_ALL_PREFIXES(CertVerifierTest, DifferentCACerts);
|
| - FRIEND_TEST_ALL_PREFIXES(CertVerifierTest, InflightJoin);
|
| - FRIEND_TEST_ALL_PREFIXES(CertVerifierTest, CancelRequest);
|
| - FRIEND_TEST_ALL_PREFIXES(CertVerifierTest, RequestParamsComparators);
|
| -
|
| - // Input parameters of a certificate verification request.
|
| - struct RequestParams {
|
| - RequestParams(const SHA1Fingerprint& cert_fingerprint_arg,
|
| - const SHA1Fingerprint& ca_fingerprint_arg,
|
| - const std::string& hostname_arg,
|
| - int flags_arg)
|
| - : cert_fingerprint(cert_fingerprint_arg),
|
| - ca_fingerprint(ca_fingerprint_arg),
|
| - hostname(hostname_arg),
|
| - flags(flags_arg) {}
|
| -
|
| - bool operator<(const RequestParams& other) const {
|
| - // |flags| is compared before |cert_fingerprint|, |ca_fingerprint|, and
|
| - // |hostname| under assumption that integer comparisons are faster than
|
| - // memory and string comparisons.
|
| - if (flags != other.flags)
|
| - return flags < other.flags;
|
| - int rv = memcmp(cert_fingerprint.data, other.cert_fingerprint.data,
|
| - sizeof(cert_fingerprint.data));
|
| - if (rv != 0)
|
| - return rv < 0;
|
| - rv = memcmp(ca_fingerprint.data, other.ca_fingerprint.data,
|
| - sizeof(ca_fingerprint.data));
|
| - if (rv != 0)
|
| - return rv < 0;
|
| - return hostname < other.hostname;
|
| - }
|
| -
|
| - SHA1Fingerprint cert_fingerprint;
|
| - SHA1Fingerprint ca_fingerprint;
|
| - std::string hostname;
|
| - int flags;
|
| - };
|
| -
|
| - // CachedResult contains the result of a certificate verification.
|
| - struct CachedResult {
|
| - CachedResult();
|
| - ~CachedResult();
|
| -
|
| - int error; // The return value of CertVerifier::Verify.
|
| - CertVerifyResult result; // The output of CertVerifier::Verify.
|
| - };
|
| -
|
| - void HandleResult(X509Certificate* cert,
|
| - const std::string& hostname,
|
| - int flags,
|
| - int error,
|
| - const CertVerifyResult& verify_result);
|
| -
|
| - // CertDatabase::Observer methods:
|
| - virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE;
|
| -
|
| - // For unit testing.
|
| - void ClearCache() { cache_.Clear(); }
|
| - size_t GetCacheSize() const { return cache_.size(); }
|
| - uint64 cache_hits() const { return cache_hits_; }
|
| - uint64 requests() const { return requests_; }
|
| - uint64 inflight_joins() const { return inflight_joins_; }
|
| -
|
| - // cache_ maps from a request to a cached result.
|
| - typedef ExpiringCache<RequestParams, CachedResult> CertVerifierCache;
|
| - CertVerifierCache cache_;
|
| -
|
| - // inflight_ maps from a request to an active verification which is taking
|
| - // place.
|
| - std::map<RequestParams, CertVerifierJob*> inflight_;
|
| -
|
| - uint64 requests_;
|
| - uint64 cache_hits_;
|
| - uint64 inflight_joins_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(CertVerifier);
|
| + // Creates a CertVerifier implementation that verifies certificates using
|
| + // the preferred underlying cryptographic libraries.
|
| + static CertVerifier* CreateDefault();
|
| };
|
|
|
| -// This class represents the task of verifying a certificate. It wraps
|
| -// CertVerifier to verify only a single certificate at a time and cancels this
|
| -// request when going out of scope.
|
| -class SingleRequestCertVerifier {
|
| - public:
|
| - // |cert_verifier| must remain valid for the lifetime of |this|.
|
| - explicit SingleRequestCertVerifier(CertVerifier* cert_verifier);
|
| -
|
| - // If a completion callback is pending when the verifier is destroyed, the
|
| - // certificate verification is canceled, and the completion callback will
|
| - // not be called.
|
| - ~SingleRequestCertVerifier();
|
| -
|
| - // Verifies the given certificate, filling out the |verify_result| object
|
| - // upon success. See CertVerifier::Verify() for details.
|
| - int Verify(X509Certificate* cert,
|
| - const std::string& hostname,
|
| - int flags,
|
| - CRLSet* crl_set,
|
| - CertVerifyResult* verify_result,
|
| - const CompletionCallback& callback,
|
| - const BoundNetLog& net_log);
|
| -
|
| - private:
|
| - // Callback for when the request to |cert_verifier_| completes, so we
|
| - // dispatch to the user's callback.
|
| - void OnVerifyCompletion(int result);
|
| -
|
| - // The actual certificate verifier that will handle the request.
|
| - CertVerifier* const cert_verifier_;
|
| -
|
| - // The current request (if any).
|
| - CertVerifier::RequestHandle cur_request_;
|
| - CompletionCallback cur_request_callback_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(SingleRequestCertVerifier);
|
| -};
|
| -
|
| } // namespace net
|
|
|
| #endif // NET_BASE_CERT_VERIFIER_H_
|
|
|