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 // We report the size of the old struct since we don't need the new members. |
| 179 static const DWORD kSizeofCertChainEngineConfig = |
| 180 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER( |
| 181 CERT_CHAIN_ENGINE_CONFIG, CycleDetectionModulus); |
| 182 |
175 // Each HCERTCHAINENGINE caches both the configured system stores and | 183 // Each HCERTCHAINENGINE caches both the configured system stores and |
176 // information about each chain that has been built. In order to ensure | 184 // information about each chain that has been built. In order to ensure |
177 // that changes to |temporary_roots_| are properly propagated and that the | 185 // that changes to |temporary_roots_| are properly propagated and that the |
178 // various caches are flushed, when at least one certificate is added, | 186 // various caches are flushed, when at least one certificate is added, |
179 // return a new chain engine for every call. Each chain engine creation | 187 // 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 | 188 // should re-open the root store, ensuring the most recent changes are |
181 // visible. | 189 // visible. |
182 CERT_CHAIN_ENGINE_CONFIG engine_config = { | 190 CERT_CHAIN_ENGINE_CONFIG engine_config = { |
183 sizeof(engine_config) | 191 kSizeofCertChainEngineConfig |
184 }; | 192 }; |
185 engine_config.dwFlags = | 193 engine_config.dwFlags = |
186 CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE | | 194 CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE | |
187 CERT_CHAIN_ENABLE_SHARE_STORE; | 195 CERT_CHAIN_ENABLE_SHARE_STORE; |
188 HCERTCHAINENGINE chain_engine = NULL; | 196 HCERTCHAINENGINE chain_engine = NULL; |
189 BOOL ok = CertCreateCertificateChainEngine(&engine_config, &chain_engine); | 197 BOOL ok = CertCreateCertificateChainEngine(&engine_config, &chain_engine); |
190 DCHECK(ok); | 198 DCHECK(ok); |
191 return chain_engine; | 199 return chain_engine; |
192 } | 200 } |
193 | 201 |
194 TestRootCerts::~TestRootCerts() { | 202 TestRootCerts::~TestRootCerts() { |
195 CertCloseStore(temporary_roots_, 0); | 203 CertCloseStore(temporary_roots_, 0); |
196 } | 204 } |
197 | 205 |
198 void TestRootCerts::Init() { | 206 void TestRootCerts::Init() { |
199 empty_ = true; | 207 empty_ = true; |
200 temporary_roots_ = CertOpenStore( | 208 temporary_roots_ = CertOpenStore( |
201 CERT_STORE_PROV_MEMORY, 0, NULL, | 209 CERT_STORE_PROV_MEMORY, 0, NULL, |
202 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); | 210 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); |
203 DCHECK(temporary_roots_); | 211 DCHECK(temporary_roots_); |
204 } | 212 } |
205 | 213 |
206 } // namespace net | 214 } // namespace net |
OLD | NEW |