OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Defines an in-memory private key store, primarily used for testing. | 5 // Defines an in-memory private key store, primarily used for testing. |
6 | 6 |
7 #include "net/base/openssl_private_key_store.h" | 7 #include "net/base/openssl_private_key_store.h" |
8 | 8 |
9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 class MemoryKeyPairStore { | 22 class MemoryKeyPairStore { |
23 public: | 23 public: |
24 MemoryKeyPairStore() {} | 24 MemoryKeyPairStore() {} |
25 | 25 |
26 static MemoryKeyPairStore* GetInstance() { | 26 static MemoryKeyPairStore* GetInstance() { |
27 return Singleton<MemoryKeyPairStore>::get(); | 27 return Singleton<MemoryKeyPairStore>::get(); |
28 } | 28 } |
29 | 29 |
30 ~MemoryKeyPairStore() { | 30 ~MemoryKeyPairStore() { |
31 base::AutoLock lock(lock_); | 31 base::AutoLock lock(lock_); |
32 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); | 32 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); it != keys_.end(); |
33 it != keys_.end(); ++it) { | 33 ++it) { |
34 EVP_PKEY_free(*it); | 34 EVP_PKEY_free(*it); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 bool StoreKeyPair(EVP_PKEY* pkey) { | 38 bool StoreKeyPair(EVP_PKEY* pkey) { |
39 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); | 39 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
40 base::AutoLock lock(lock_); | 40 base::AutoLock lock(lock_); |
41 keys_.push_back(pkey); | 41 keys_.push_back(pkey); |
42 return true; | 42 return true; |
43 } | 43 } |
44 | 44 |
45 bool HasPrivateKey(EVP_PKEY* pkey) { | 45 bool HasPrivateKey(EVP_PKEY* pkey) { |
46 base::AutoLock lock(lock_); | 46 base::AutoLock lock(lock_); |
47 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); | 47 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); it != keys_.end(); |
48 it != keys_.end(); ++it) { | 48 ++it) { |
49 if (EVP_PKEY_cmp(*it, pkey) == 1) | 49 if (EVP_PKEY_cmp(*it, pkey) == 1) |
50 return true; | 50 return true; |
51 } | 51 } |
52 return false; | 52 return false; |
53 } | 53 } |
54 | 54 |
55 private: | 55 private: |
56 std::vector<EVP_PKEY*> keys_; | 56 std::vector<EVP_PKEY*> keys_; |
57 base::Lock lock_; | 57 base::Lock lock_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(MemoryKeyPairStore); | 59 DISALLOW_COPY_AND_ASSIGN(MemoryKeyPairStore); |
60 }; | 60 }; |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 bool OpenSSLPrivateKeyStore::StoreKeyPair(const GURL& url, | 64 bool OpenSSLPrivateKeyStore::StoreKeyPair(const GURL& url, EVP_PKEY* pkey) { |
65 EVP_PKEY* pkey) { | |
66 return MemoryKeyPairStore::GetInstance()->StoreKeyPair(pkey); | 65 return MemoryKeyPairStore::GetInstance()->StoreKeyPair(pkey); |
67 } | 66 } |
68 | 67 |
69 bool OpenSSLPrivateKeyStore::HasPrivateKey(EVP_PKEY* pub_key) { | 68 bool OpenSSLPrivateKeyStore::HasPrivateKey(EVP_PKEY* pub_key) { |
70 return MemoryKeyPairStore::GetInstance()->HasPrivateKey(pub_key); | 69 return MemoryKeyPairStore::GetInstance()->HasPrivateKey(pub_key); |
71 } | 70 } |
72 | 71 |
73 } // namespace net | 72 } // namespace net |
74 | |
OLD | NEW |