OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/base/test_root_certs.h" | 5 #include "net/base/test_root_certs.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/win/win_util.h" | |
14 #include "base/win/windows_version.h" | |
13 #include "net/base/x509_certificate.h" | 15 #include "net/base/x509_certificate.h" |
14 | 16 |
15 namespace net { | 17 namespace net { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 // Provides a CertDllOpenStoreProv callback provider function, to be called | 21 // Provides a CertDllOpenStoreProv callback provider function, to be called |
20 // by CertOpenStore when the CERT_STORE_PROV_SYSTEM_W store is opened. See | 22 // by CertOpenStore when the CERT_STORE_PROV_SYSTEM_W store is opened. See |
21 // http://msdn.microsoft.com/en-us/library/aa376043(VS.85).aspx. | 23 // http://msdn.microsoft.com/en-us/library/aa376043(VS.85).aspx. |
22 BOOL WINAPI InterceptedOpenStoreW(LPCSTR store_provider, | 24 BOOL WINAPI InterceptedOpenStoreW(LPCSTR store_provider, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 } | 167 } |
166 | 168 |
167 bool TestRootCerts::IsEmpty() const { | 169 bool TestRootCerts::IsEmpty() const { |
168 return empty_; | 170 return empty_; |
169 } | 171 } |
170 | 172 |
171 HCERTCHAINENGINE TestRootCerts::GetChainEngine() const { | 173 HCERTCHAINENGINE TestRootCerts::GetChainEngine() const { |
172 if (IsEmpty()) | 174 if (IsEmpty()) |
173 return NULL; // Default chain engine will suffice. | 175 return NULL; // Default chain engine will suffice. |
174 | 176 |
177 // Windows versions before 7 don't accept the struct size for later versions. | |
178 // So, we report the size of the old struct for earlier Vista and earlier. | |
179 const DWORD kSizeofCertChainEngineConfig = | |
brettw
2011/09/25 06:13:26
Don't give this "k" naming since it's not a consta
jschuh
2011/09/25 20:39:34
I originally had it the other way and switched it
| |
180 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | |
181 sizeof(CERT_CHAIN_ENGINE_CONFIG) : | |
182 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER( | |
183 CERT_CHAIN_ENGINE_CONFIG, CycleDetectionModulus); | |
184 | |
175 // Each HCERTCHAINENGINE caches both the configured system stores and | 185 // Each HCERTCHAINENGINE caches both the configured system stores and |
176 // information about each chain that has been built. In order to ensure | 186 // information about each chain that has been built. In order to ensure |
177 // that changes to |temporary_roots_| are properly propagated and that the | 187 // that changes to |temporary_roots_| are properly propagated and that the |
178 // various caches are flushed, when at least one certificate is added, | 188 // various caches are flushed, when at least one certificate is added, |
179 // return a new chain engine for every call. Each chain engine creation | 189 // return a new chain engine for every call. Each chain engine creation |
180 // should re-open the root store, ensuring the most recent changes are | 190 // should re-open the root store, ensuring the most recent changes are |
181 // visible. | 191 // visible. |
182 CERT_CHAIN_ENGINE_CONFIG engine_config = { | 192 CERT_CHAIN_ENGINE_CONFIG engine_config = { |
183 sizeof(engine_config) | 193 kSizeofCertChainEngineConfig |
184 }; | 194 }; |
185 engine_config.dwFlags = | 195 engine_config.dwFlags = |
186 CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE | | 196 CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE | |
187 CERT_CHAIN_ENABLE_SHARE_STORE; | 197 CERT_CHAIN_ENABLE_SHARE_STORE; |
188 HCERTCHAINENGINE chain_engine = NULL; | 198 HCERTCHAINENGINE chain_engine = NULL; |
189 BOOL ok = CertCreateCertificateChainEngine(&engine_config, &chain_engine); | 199 BOOL ok = CertCreateCertificateChainEngine(&engine_config, &chain_engine); |
190 DCHECK(ok); | 200 DCHECK(ok); |
191 return chain_engine; | 201 return chain_engine; |
192 } | 202 } |
193 | 203 |
194 TestRootCerts::~TestRootCerts() { | 204 TestRootCerts::~TestRootCerts() { |
195 CertCloseStore(temporary_roots_, 0); | 205 CertCloseStore(temporary_roots_, 0); |
196 } | 206 } |
197 | 207 |
198 void TestRootCerts::Init() { | 208 void TestRootCerts::Init() { |
199 empty_ = true; | 209 empty_ = true; |
200 temporary_roots_ = CertOpenStore( | 210 temporary_roots_ = CertOpenStore( |
201 CERT_STORE_PROV_MEMORY, 0, NULL, | 211 CERT_STORE_PROV_MEMORY, 0, NULL, |
202 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); | 212 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); |
203 DCHECK(temporary_roots_); | 213 DCHECK(temporary_roots_); |
204 } | 214 } |
205 | 215 |
206 } // namespace net | 216 } // namespace net |
OLD | NEW |