1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_CERT_CERT_VERIFIER_H_
6 #define NET_CERT_CERT_VERIFIER_H_
10 #include "base/basictypes.h"
11 #include "net/base/completion_callback.h"
12 #include "net/base/net_export.h"
17 class CertVerifyResult
;
19 class X509Certificate
;
21 // CertVerifier represents a service for verifying certificates.
23 // CertVerifiers can handle multiple requests at a time. A simpler alternative
24 // for consumers that only have 1 outstanding request at a time is to create a
25 // SingleRequestCertVerifier wrapper around CertVerifier (which will
26 // automatically cancel the single request when it goes out of scope).
27 class NET_EXPORT CertVerifier
{
29 // Opaque pointer type used to cancel outstanding requests.
30 typedef void* RequestHandle
;
33 // If set, enables online revocation checking via CRLs and OCSP for the
35 VERIFY_REV_CHECKING_ENABLED
= 1 << 0,
37 // If set, and the certificate being verified may be an EV certificate,
38 // attempt to verify the certificate according to the EV processing
39 // guidelines. In order to successfully verify a certificate as EV,
40 // either an online or offline revocation check must be successfully
41 // completed. To ensure it's possible to complete a revocation check,
42 // callers should also specify either VERIFY_REV_CHECKING_ENABLED or
43 // VERIFY_REV_CHECKING_ENABLED_EV_ONLY (to enable online checks), and
44 // VERIFY_CERT_IO_ENABLED (to enable network fetches for online checks).
45 VERIFY_EV_CERT
= 1 << 1,
47 // If set, permits NSS to use the network when verifying certificates,
48 // such as to fetch missing intermediates or to check OCSP or CRLs.
49 // TODO(rsleevi): http://crbug.com/143300 - Define this flag for all
50 // verification engines with well-defined semantics, rather than being
52 VERIFY_CERT_IO_ENABLED
= 1 << 2,
54 // If set, enables online revocation checking via CRLs or OCSP, but only
55 // for certificates which may be EV, and only when VERIFY_EV_CERT is also
57 VERIFY_REV_CHECKING_ENABLED_EV_ONLY
= 1 << 3,
60 // When the verifier is destroyed, all certificate verification requests are
61 // canceled, and their completion callbacks will not be called.
62 virtual ~CertVerifier() {}
64 // Verifies the given certificate against the given hostname as an SSL server.
65 // Returns OK if successful or an error code upon failure.
67 // The |*verify_result| structure, including the |verify_result->cert_status|
68 // bitmask, is always filled out regardless of the return value. If the
69 // certificate has multiple errors, the corresponding status flags are set in
70 // |verify_result->cert_status|, and the error code for the most serious
73 // |flags| is bitwise OR'd of VerifyFlags.
74 // If VERIFY_REV_CHECKING_ENABLED is set in |flags|, certificate revocation
75 // checking is performed.
77 // If VERIFY_EV_CERT is set in |flags| too, EV certificate verification is
78 // performed. If |flags| is VERIFY_EV_CERT (that is,
79 // VERIFY_REV_CHECKING_ENABLED is not set), EV certificate verification will
82 // |crl_set| points to an optional CRLSet structure which can be used to
83 // avoid revocation checks over the network.
85 // |callback| must not be null. ERR_IO_PENDING is returned if the operation
86 // could not be completed synchronously, in which case the result code will
87 // be passed to the callback when available.
89 // |*out_req| will be filled with a handle to the async request.
90 // This handle is not valid after the request has completed.
92 // TODO(rsleevi): Move CRLSet* out of the CertVerifier signature.
93 virtual int Verify(X509Certificate
* cert
,
94 const std::string
& hostname
,
97 CertVerifyResult
* verify_result
,
98 const CompletionCallback
& callback
,
99 RequestHandle
* out_req
,
100 const BoundNetLog
& net_log
) = 0;
102 // Cancels the specified request. |req| is the handle returned by Verify().
103 // After a request is canceled, its completion callback will not be called.
104 virtual void CancelRequest(RequestHandle req
) = 0;
106 // Creates a CertVerifier implementation that verifies certificates using
107 // the preferred underlying cryptographic libraries.
108 static CertVerifier
* CreateDefault();
113 #endif // NET_CERT_CERT_VERIFIER_H_