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 #include "net/ssl/ssl_client_auth_cache.h" | 5 #include "net/ssl/ssl_client_auth_cache.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/cert/x509_certificate.h" | 8 #include "net/cert/x509_certificate.h" |
| 9 #include "net/ssl/ssl_private_key.h" |
9 | 10 |
10 namespace net { | 11 namespace net { |
11 | 12 |
12 SSLClientAuthCache::SSLClientAuthCache() { | 13 SSLClientAuthCache::SSLClientAuthCache() { |
13 CertDatabase::GetInstance()->AddObserver(this); | 14 CertDatabase::GetInstance()->AddObserver(this); |
14 } | 15 } |
15 | 16 |
16 SSLClientAuthCache::~SSLClientAuthCache() { | 17 SSLClientAuthCache::~SSLClientAuthCache() { |
17 CertDatabase::GetInstance()->RemoveObserver(this); | 18 CertDatabase::GetInstance()->RemoveObserver(this); |
18 } | 19 } |
19 | 20 |
20 bool SSLClientAuthCache::Lookup( | 21 bool SSLClientAuthCache::Lookup(const HostPortPair& server, |
21 const HostPortPair& server, | 22 scoped_refptr<X509Certificate>* certificate, |
22 scoped_refptr<X509Certificate>* certificate) { | 23 scoped_refptr<SSLPrivateKey>* private_key) { |
23 DCHECK(certificate); | 24 DCHECK(certificate); |
24 | 25 |
25 AuthCacheMap::iterator iter = cache_.find(server); | 26 AuthCacheMap::iterator iter = cache_.find(server); |
26 if (iter == cache_.end()) | 27 if (iter == cache_.end()) |
27 return false; | 28 return false; |
28 | 29 |
29 *certificate = iter->second; | 30 *certificate = iter->second.first; |
| 31 *private_key = iter->second.second; |
30 return true; | 32 return true; |
31 } | 33 } |
32 | 34 |
33 void SSLClientAuthCache::Add(const HostPortPair& server, | 35 void SSLClientAuthCache::Add(const HostPortPair& server, |
34 X509Certificate* value) { | 36 X509Certificate* certificate, |
35 cache_[server] = value; | 37 SSLPrivateKey* private_key) { |
| 38 cache_[server] = std::make_pair(certificate, private_key); |
36 | 39 |
37 // TODO(wtc): enforce a maximum number of entries. | 40 // TODO(wtc): enforce a maximum number of entries. |
38 } | 41 } |
39 | 42 |
40 void SSLClientAuthCache::Remove(const HostPortPair& server) { | 43 void SSLClientAuthCache::Remove(const HostPortPair& server) { |
41 cache_.erase(server); | 44 cache_.erase(server); |
42 } | 45 } |
43 | 46 |
44 void SSLClientAuthCache::OnCertAdded(const X509Certificate* cert) { | 47 void SSLClientAuthCache::OnCertAdded(const X509Certificate* cert) { |
45 cache_.clear(); | 48 cache_.clear(); |
46 } | 49 } |
47 | 50 |
48 } // namespace net | 51 } // namespace net |
OLD | NEW |