summaryrefslogtreecommitdiffstats
path: root/net/ssl/ssl_client_auth_cache.cc
blob: ba60c1bc5feb1d62b08ad4fee82f02bdf229aa49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/ssl/ssl_client_auth_cache.h"

#include "base/logging.h"
#include "net/cert/x509_certificate.h"
#include "net/ssl/ssl_private_key.h"

namespace net {

SSLClientAuthCache::SSLClientAuthCache() {
  CertDatabase::GetInstance()->AddObserver(this);
}

SSLClientAuthCache::~SSLClientAuthCache() {
  CertDatabase::GetInstance()->RemoveObserver(this);
}

bool SSLClientAuthCache::Lookup(const HostPortPair& server,
                                scoped_refptr<X509Certificate>* certificate,
                                scoped_refptr<SSLPrivateKey>* private_key) {
  DCHECK(certificate);

  AuthCacheMap::iterator iter = cache_.find(server);
  if (iter == cache_.end())
    return false;

  *certificate = iter->second.first;
  *private_key = iter->second.second;
  return true;
}

void SSLClientAuthCache::Add(const HostPortPair& server,
                             X509Certificate* certificate,
                             SSLPrivateKey* private_key) {
  cache_[server] = std::make_pair(certificate, private_key);

  // TODO(wtc): enforce a maximum number of entries.
}

void SSLClientAuthCache::Remove(const HostPortPair& server) {
  cache_.erase(server);
}

void SSLClientAuthCache::OnCertAdded(const X509Certificate* cert) {
  cache_.clear();
}

}  // namespace net