OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_CERT_TEST_ROOT_CERTS_H_ | 5 #ifndef NET_CERT_TEST_ROOT_CERTS_H_ |
6 #define NET_CERT_TEST_ROOT_CERTS_H_ | 6 #define NET_CERT_TEST_ROOT_CERTS_H_ |
7 | 7 |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
13 | 13 |
14 #if defined(USE_NSS_CERTS) | 14 #if defined(USE_NSS_CERTS) |
15 #include <cert.h> | 15 #include <cert.h> |
16 #include <vector> | 16 #include <vector> |
17 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
18 #include <vector> | |
19 #elif defined(OS_WIN) | 17 #elif defined(OS_WIN) |
20 #include <windows.h> | 18 #include <windows.h> |
21 #include "crypto/wincrypt_shim.h" | 19 #include "crypto/wincrypt_shim.h" |
22 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
23 #include <CoreFoundation/CFArray.h> | 21 #include <CoreFoundation/CFArray.h> |
24 #include <Security/SecTrust.h> | 22 #include <Security/SecTrust.h> |
25 #include "base/mac/scoped_cftyperef.h" | 23 #include "base/mac/scoped_cftyperef.h" |
26 #endif | 24 #endif |
27 | 25 |
28 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
29 typedef struct x509_st X509; | |
30 #endif | |
31 | |
32 namespace base { | 26 namespace base { |
33 class FilePath; | 27 class FilePath; |
34 } | 28 } |
35 | 29 |
36 namespace net { | 30 namespace net { |
37 | 31 |
38 class X509Certificate; | 32 class X509Certificate; |
39 | 33 |
40 // TestRootCerts is a helper class for unit tests that is used to | 34 // TestRootCerts is a helper class for unit tests that is used to |
41 // artificially mark a certificate as trusted, independent of the local | 35 // artificially mark a certificate as trusted, independent of the local |
(...skipping 30 matching lines...) Expand all Loading... |
72 | 66 |
73 // Modifies the root certificates of |trust_ref| to include the | 67 // Modifies the root certificates of |trust_ref| to include the |
74 // certificates stored in |temporary_roots_|. If IsEmpty() is true, this | 68 // certificates stored in |temporary_roots_|. If IsEmpty() is true, this |
75 // does not modify |trust_ref|. | 69 // does not modify |trust_ref|. |
76 OSStatus FixupSecTrustRef(SecTrustRef trust_ref) const; | 70 OSStatus FixupSecTrustRef(SecTrustRef trust_ref) const; |
77 | 71 |
78 // Configures whether or not the default/system root store should also | 72 // Configures whether or not the default/system root store should also |
79 // be trusted. By default, this is true, indicating that the TestRootCerts | 73 // be trusted. By default, this is true, indicating that the TestRootCerts |
80 // are used in addition to OS trust store. | 74 // are used in addition to OS trust store. |
81 void SetAllowSystemTrust(bool allow_system_trust); | 75 void SetAllowSystemTrust(bool allow_system_trust); |
82 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
83 const std::vector<scoped_refptr<X509Certificate> >& | |
84 temporary_roots() const { return temporary_roots_; } | |
85 bool Contains(X509* cert) const; | |
86 #elif defined(OS_WIN) | 76 #elif defined(OS_WIN) |
87 HCERTSTORE temporary_roots() const { return temporary_roots_; } | 77 HCERTSTORE temporary_roots() const { return temporary_roots_; } |
88 | 78 |
89 // Returns an HCERTCHAINENGINE suitable to be used for certificate | 79 // Returns an HCERTCHAINENGINE suitable to be used for certificate |
90 // validation routines, or NULL to indicate that the default system chain | 80 // validation routines, or NULL to indicate that the default system chain |
91 // engine is appropriate. The caller is responsible for freeing the | 81 // engine is appropriate. The caller is responsible for freeing the |
92 // returned HCERTCHAINENGINE. | 82 // returned HCERTCHAINENGINE. |
93 HCERTCHAINENGINE GetChainEngine() const; | 83 HCERTCHAINENGINE GetChainEngine() const; |
94 #endif | 84 #endif |
95 | 85 |
(...skipping 27 matching lines...) Expand all Loading... |
123 // The original trust settings, before |certificate_| was manipulated to | 113 // The original trust settings, before |certificate_| was manipulated to |
124 // be a temporarily trusted root. | 114 // be a temporarily trusted root. |
125 CERTCertTrust trust_; | 115 CERTCertTrust trust_; |
126 | 116 |
127 DISALLOW_COPY_AND_ASSIGN(TrustEntry); | 117 DISALLOW_COPY_AND_ASSIGN(TrustEntry); |
128 }; | 118 }; |
129 | 119 |
130 // It is necessary to maintain a cache of the original certificate trust | 120 // It is necessary to maintain a cache of the original certificate trust |
131 // settings, in order to restore them when Clear() is called. | 121 // settings, in order to restore them when Clear() is called. |
132 std::vector<std::unique_ptr<TrustEntry>> trust_cache_; | 122 std::vector<std::unique_ptr<TrustEntry>> trust_cache_; |
133 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
134 std::vector<scoped_refptr<X509Certificate>> temporary_roots_; | |
135 #elif defined(OS_WIN) | 123 #elif defined(OS_WIN) |
136 HCERTSTORE temporary_roots_; | 124 HCERTSTORE temporary_roots_; |
137 #elif defined(OS_MACOSX) | 125 #elif defined(OS_MACOSX) |
138 base::ScopedCFTypeRef<CFMutableArrayRef> temporary_roots_; | 126 base::ScopedCFTypeRef<CFMutableArrayRef> temporary_roots_; |
139 bool allow_system_trust_; | 127 bool allow_system_trust_; |
140 #endif | 128 #endif |
141 | 129 |
142 #if defined(OS_WIN) || defined(OS_ANDROID) | 130 #if defined(OS_WIN) || defined(OS_ANDROID) |
143 // True if there are no temporarily trusted root certificates. | 131 // True if there are no temporarily trusted root certificates. |
144 bool empty_; | 132 bool empty_; |
(...skipping 21 matching lines...) Expand all Loading... |
166 | 154 |
167 private: | 155 private: |
168 scoped_refptr<X509Certificate> cert_; | 156 scoped_refptr<X509Certificate> cert_; |
169 | 157 |
170 DISALLOW_COPY_AND_ASSIGN(ScopedTestRoot); | 158 DISALLOW_COPY_AND_ASSIGN(ScopedTestRoot); |
171 }; | 159 }; |
172 | 160 |
173 } // namespace net | 161 } // namespace net |
174 | 162 |
175 #endif // NET_CERT_TEST_ROOT_CERTS_H_ | 163 #endif // NET_CERT_TEST_ROOT_CERTS_H_ |
OLD | NEW |