Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / cert / cert_verifier.h
blob6e5eac98e4fa0152cffdf1cc208682c9d17c28a0
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_
8 #include <string>
10 #include "base/macros.h"
11 #include "net/base/completion_callback.h"
12 #include "net/base/net_export.h"
14 namespace net {
16 class BoundNetLog;
17 class CertVerifyResult;
18 class CRLSet;
19 class X509Certificate;
21 // CertVerifier represents a service for verifying certificates.
23 // CertVerifiers can handle multiple requests at a time.
24 class NET_EXPORT CertVerifier {
25 public:
26 class Request {
27 public:
28 Request() {}
30 // Destruction of the Request cancels it.
31 virtual ~Request() {}
33 private:
34 DISALLOW_COPY_AND_ASSIGN(Request);
37 enum VerifyFlags {
38 // If set, enables online revocation checking via CRLs and OCSP for the
39 // certificate chain.
40 VERIFY_REV_CHECKING_ENABLED = 1 << 0,
42 // If set, and the certificate being verified may be an EV certificate,
43 // attempt to verify the certificate according to the EV processing
44 // guidelines. In order to successfully verify a certificate as EV,
45 // either an online or offline revocation check must be successfully
46 // completed. To ensure it's possible to complete a revocation check,
47 // callers should also specify either VERIFY_REV_CHECKING_ENABLED or
48 // VERIFY_REV_CHECKING_ENABLED_EV_ONLY (to enable online checks), and
49 // VERIFY_CERT_IO_ENABLED (to enable network fetches for online checks).
50 VERIFY_EV_CERT = 1 << 1,
52 // If set, permits NSS to use the network when verifying certificates,
53 // such as to fetch missing intermediates or to check OCSP or CRLs.
54 // TODO(rsleevi): http://crbug.com/143300 - Define this flag for all
55 // verification engines with well-defined semantics, rather than being
56 // NSS only.
57 VERIFY_CERT_IO_ENABLED = 1 << 2,
59 // If set, enables online revocation checking via CRLs or OCSP when the
60 // chain is not covered by a fresh CRLSet, but only for certificates which
61 // may be EV, and only when VERIFY_EV_CERT is also set.
62 VERIFY_REV_CHECKING_ENABLED_EV_ONLY = 1 << 3,
64 // If set, this is equivalent to VERIFY_REV_CHECKING_ENABLED, in that it
65 // enables online revocation checking via CRLs or OCSP, but only
66 // for certificates issued by non-public trust anchors. Failure to check
67 // revocation is treated as a hard failure.
68 // Note: If VERIFY_CERT_IO_ENABLE is not also supplied, certificates
69 // that chain to local trust anchors will likely fail - for example, due to
70 // lacking fresh cached revocation issue (Windows) or because OCSP stapling
71 // can only provide information for the leaf, and not for any
72 // intermediates.
73 VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS = 1 << 4,
76 // When the verifier is destroyed, all certificate verification requests are
77 // canceled, and their completion callbacks will not be called.
78 virtual ~CertVerifier() {}
80 // Verifies the given certificate against the given hostname as an SSL server.
81 // Returns OK if successful or an error code upon failure.
83 // The |*verify_result| structure, including the |verify_result->cert_status|
84 // bitmask, is always filled out regardless of the return value. If the
85 // certificate has multiple errors, the corresponding status flags are set in
86 // |verify_result->cert_status|, and the error code for the most serious
87 // error is returned.
89 // |ocsp_response|, if non-empty, is a stapled OCSP response to use.
91 // |flags| is bitwise OR'd of VerifyFlags.
92 // If VERIFY_REV_CHECKING_ENABLED is set in |flags|, certificate revocation
93 // checking is performed.
95 // If VERIFY_EV_CERT is set in |flags| too, EV certificate verification is
96 // performed. If |flags| is VERIFY_EV_CERT (that is,
97 // VERIFY_REV_CHECKING_ENABLED is not set), EV certificate verification will
98 // not be performed.
100 // |crl_set| points to an optional CRLSet structure which can be used to
101 // avoid revocation checks over the network.
103 // |callback| must not be null. ERR_IO_PENDING is returned if the operation
104 // could not be completed synchronously, in which case the result code will
105 // be passed to the callback when available.
107 // On asynchronous completion (when Verify returns ERR_IO_PENDING) |out_req|
108 // will be reset with a pointer to the request. Freeing this pointer before
109 // the request has completed will cancel it.
111 // If Verify() completes synchronously then |out_req| *may* be reset to
112 // nullptr. However it is not guaranteed that all implementations will reset
113 // it in this case.
115 // TODO(rsleevi): Move CRLSet* out of the CertVerifier signature.
116 virtual int Verify(X509Certificate* cert,
117 const std::string& hostname,
118 const std::string& ocsp_response,
119 int flags,
120 CRLSet* crl_set,
121 CertVerifyResult* verify_result,
122 const CompletionCallback& callback,
123 scoped_ptr<Request>* out_req,
124 const BoundNetLog& net_log) = 0;
126 // Returns true if this CertVerifier supports stapled OCSP responses.
127 virtual bool SupportsOCSPStapling();
129 // Creates a CertVerifier implementation that verifies certificates using
130 // the preferred underlying cryptographic libraries.
131 static CertVerifier* CreateDefault();
134 } // namespace net
136 #endif // NET_CERT_CERT_VERIFIER_H_