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

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: ; 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
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 ~OpenSSLMemoryKeyStore() {
bulach 2010/12/08 20:37:00 virtual?
joth 2010/12/09 11:20:21 Done.
24 AutoLock lock(lock_);
25 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin();
26 it != keys_.end(); ++it) {
27 EVP_PKEY_free(*it);
28 }
29 }
bulach 2010/12/08 20:37:00 \n
joth 2010/12/09 11:20:21 Done.
30 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) {
31 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
32 AutoLock lock(lock_);
33 keys_.push_back(pkey);
34 return true;
35 }
bulach 2010/12/08 20:37:00 \n
joth 2010/12/09 11:20:21 Done.
36 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* pkey) {
37 AutoLock lock(lock_);
38 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin();
39 it != keys_.end(); ++it) {
40 if (EVP_PKEY_cmp(*it, pkey) == 1)
41 return *it;
42 }
43 return NULL;
44 }
45
46 private:
47 std::vector<EVP_PKEY*> keys_;
48 Lock lock_;
49
50 DISALLOW_COPY_AND_ASSIGN(OpenSSLMemoryKeyStore);
51 };
52
53 } // namespace
54
55 // static
56 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() {
57 return Singleton<OpenSSLMemoryKeyStore>::get();
58 }
59
60 } // namespace net
61
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698