Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(981)

Side by Side Diff: net/base/openssl_memory_private_key_store.cc

Issue 5594009: Adds first cut implementation of a private key store abstraction for openssl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wtc comment from http://codereview.chromium.org/5592003/ Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/keygen_handler_openssl.cc ('k') | net/base/openssl_private_key_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « net/base/keygen_handler_openssl.cc ('k') | net/base/openssl_private_key_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698