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/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 #pragma comment(lib, "crypt32.lib") | 9 #pragma comment(lib, "crypt32.lib") |
10 #include <rpc.h> | 10 #include <rpc.h> |
11 #pragma comment(lib, "rpcrt4.lib") | 11 #pragma comment(lib, "rpcrt4.lib") |
12 | 12 |
13 #include <list> | 13 #include <list> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/base64.h" | 17 #include "base/base64.h" |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "base/crypto/capi_util.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/string_piece.h" | 21 #include "base/string_piece.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
23 | 24 |
24 namespace net { | 25 namespace net { |
25 | 26 |
26 bool EncodeAndAppendType(LPCSTR type, const void* to_encode, | 27 bool EncodeAndAppendType(LPCSTR type, const void* to_encode, |
27 std::vector<BYTE>* output) { | 28 std::vector<BYTE>* output) { |
28 BOOL ok; | 29 BOOL ok; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // Per MSDN documentation for CryptAcquireContext, if applications will be | 244 // Per MSDN documentation for CryptAcquireContext, if applications will be |
244 // creating their own keys, they should ensure unique naming schemes to | 245 // creating their own keys, they should ensure unique naming schemes to |
245 // prevent overlap with any other applications or consumers of CSPs, and | 246 // prevent overlap with any other applications or consumers of CSPs, and |
246 // *should not* store new keys within the default, NULL key container. | 247 // *should not* store new keys within the default, NULL key container. |
247 new_key_id = GetNewKeyContainerId(); | 248 new_key_id = GetNewKeyContainerId(); |
248 if (new_key_id.empty()) | 249 if (new_key_id.empty()) |
249 return result; | 250 return result; |
250 | 251 |
251 // Only create new key containers, so that existing key containers are not | 252 // Only create new key containers, so that existing key containers are not |
252 // overwritten. | 253 // overwritten. |
253 ok = CryptAcquireContext(&prov, new_key_id.c_str(), NULL, PROV_RSA_FULL, | 254 ok = base::CryptAcquireContextLocked(&prov, new_key_id.c_str(), NULL, |
254 CRYPT_SILENT | CRYPT_NEWKEYSET); | 255 PROV_RSA_FULL, |
| 256 CRYPT_SILENT | CRYPT_NEWKEYSET); |
255 | 257 |
256 if (ok || GetLastError() != NTE_BAD_KEYSET) | 258 if (ok || GetLastError() != NTE_BAD_KEYSET) |
257 break; | 259 break; |
258 } | 260 } |
259 if (!ok) { | 261 if (!ok) { |
260 LOG(ERROR) << "Couldn't acquire a CryptoAPI provider context: " | 262 LOG(ERROR) << "Couldn't acquire a CryptoAPI provider context: " |
261 << GetLastError(); | 263 << GetLastError(); |
262 is_success = false; | 264 is_success = false; |
263 goto failure; | 265 goto failure; |
264 } | 266 } |
(...skipping 29 matching lines...) Expand all Loading... |
294 // key can be obtained again by resolving the key location. If | 296 // key can be obtained again by resolving the key location. If |
295 // |stores_key_| is false, the underlying key will be destroyed below. | 297 // |stores_key_| is false, the underlying key will be destroyed below. |
296 CryptDestroyKey(key); | 298 CryptDestroyKey(key); |
297 } | 299 } |
298 | 300 |
299 if (prov) { | 301 if (prov) { |
300 CryptReleaseContext(prov, 0); | 302 CryptReleaseContext(prov, 0); |
301 prov = NULL; | 303 prov = NULL; |
302 if (!stores_key_) { | 304 if (!stores_key_) { |
303 // Fully destroys any of the keys that were created and releases prov. | 305 // Fully destroys any of the keys that were created and releases prov. |
304 CryptAcquireContext(&prov, new_key_id.c_str(), NULL, PROV_RSA_FULL, | 306 base::CryptAcquireContextLocked(&prov, new_key_id.c_str(), NULL, |
305 CRYPT_SILENT | CRYPT_DELETEKEYSET); | 307 PROV_RSA_FULL, |
| 308 CRYPT_SILENT | CRYPT_DELETEKEYSET); |
306 } | 309 } |
307 } | 310 } |
308 | 311 |
309 return result; | 312 return result; |
310 } | 313 } |
311 | 314 |
312 } // namespace net | 315 } // namespace net |
OLD | NEW |