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

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

Issue 12220104: Wire up SSL client authentication for OpenSSL/Android through the net/ stack (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address recent nits Created 7 years, 10 months 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
OLDNEW
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 <openssl/evp.h> 7 #include <openssl/evp.h>
8 8
9 #include "net/base/openssl_private_key_store.h" 9 #include "net/base/openssl_private_key_store.h"
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "net/base/x509_certificate.h" 14 #include "net/base/x509_certificate.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 namespace { 18 namespace {
19 19
20 // This is the linux_redux specific implementation of
Ryan Sleevi 2013/02/15 23:53:26 nit: "linux_redux" is meaningless here. Try to exp
digit1 2013/02/25 14:26:22 Done.
21 // OpenSSLPrivateKeyStore.
20 class OpenSSLMemoryKeyStore : public OpenSSLPrivateKeyStore { 22 class OpenSSLMemoryKeyStore : public OpenSSLPrivateKeyStore {
ppi 2013/02/15 19:54:46 Suggestion: We might want to rename this to OpenSS
digit1 2013/02/25 14:26:22 I've renamed this to OpenSSLPrivateKeyStoreMemory,
21 public: 23 public:
22 OpenSSLMemoryKeyStore() {} 24 OpenSSLMemoryKeyStore() {}
23 25
24 static OpenSSLMemoryKeyStore* GetInstance() { 26 static OpenSSLMemoryKeyStore* GetInstance() {
25 return Singleton<OpenSSLMemoryKeyStore>::get(); 27 return Singleton<OpenSSLMemoryKeyStore>::get();
26 } 28 }
27 29
28 virtual ~OpenSSLMemoryKeyStore() { 30 virtual bool StoreKeyPair(const GURL& url, EVP_PKEY* pkey) OVERRIDE {
29 base::AutoLock lock(lock_); 31 // Since there is no real key store, just record the keys in
30 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); 32 // memory.
31 it != keys_.end(); ++it) { 33 AddKeyPair(pkey, pkey);
32 EVP_PKEY_free(*it);
33 }
34 }
35
36 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) {
37 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
38 base::AutoLock lock(lock_);
39 keys_.push_back(pkey);
40 return true; 34 return true;
41 } 35 }
42 36
43 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* pkey) {
44 base::AutoLock lock(lock_);
45 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin();
46 it != keys_.end(); ++it) {
47 if (EVP_PKEY_cmp(*it, pkey) == 1)
48 return *it;
49 }
50 return NULL;
51 }
52
53 private: 37 private:
54 std::vector<EVP_PKEY*> keys_;
55 base::Lock lock_;
56
57 DISALLOW_COPY_AND_ASSIGN(OpenSSLMemoryKeyStore); 38 DISALLOW_COPY_AND_ASSIGN(OpenSSLMemoryKeyStore);
58 }; 39 };
59 40
60 } // namespace 41 } // namespace
61 42
62 // static 43 // static
63 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { 44 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() {
64 return OpenSSLMemoryKeyStore::GetInstance(); 45 return OpenSSLMemoryKeyStore::GetInstance();
65 } 46 }
66 47
67 } // namespace net 48 } // namespace net
68 49
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698