OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Defines an in-memory private key store, primarily used for testing. |
| 6 |
| 7 #include <openssl/evp.h> |
| 8 |
| 9 #include "net/base/openssl_private_key_store.h" |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/openssl_util.h" |
| 13 #include "base/singleton.h" |
| 14 #include "net/base/x509_certificate.h" |
| 15 |
| 16 namespace net { |
| 17 |
| 18 namespace { |
| 19 |
| 20 class OpenSSLMemoryKeyStore : public OpenSSLPrivateKeyStore { |
| 21 public: |
| 22 OpenSSLMemoryKeyStore() {} |
| 23 |
| 24 virtual ~OpenSSLMemoryKeyStore() { |
| 25 AutoLock lock(lock_); |
| 26 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); |
| 27 it != keys_.end(); ++it) { |
| 28 EVP_PKEY_free(*it); |
| 29 } |
| 30 } |
| 31 |
| 32 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) { |
| 33 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
| 34 AutoLock lock(lock_); |
| 35 keys_.push_back(pkey); |
| 36 return true; |
| 37 } |
| 38 |
| 39 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* pkey) { |
| 40 AutoLock lock(lock_); |
| 41 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); |
| 42 it != keys_.end(); ++it) { |
| 43 if (EVP_PKEY_cmp(*it, pkey) == 1) |
| 44 return *it; |
| 45 } |
| 46 return NULL; |
| 47 } |
| 48 |
| 49 private: |
| 50 std::vector<EVP_PKEY*> keys_; |
| 51 Lock lock_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(OpenSSLMemoryKeyStore); |
| 54 }; |
| 55 |
| 56 } // namespace |
| 57 |
| 58 // static |
| 59 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { |
| 60 return Singleton<OpenSSLMemoryKeyStore>::get(); |
| 61 } |
| 62 |
| 63 } // namespace net |
| 64 |
OLD | NEW |