summaryrefslogtreecommitdiffstats
path: root/net/ssl/client_key_store.cc
blob: 87dafec16b0197cc4bc65753bd2f77b46d56882c (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
52
53
54
// Copyright 2015 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/client_key_store.h"

#include <algorithm>
#include <utility>

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

namespace net {

namespace {
static base::LazyInstance<ClientKeyStore>::Leaky g_client_key_store =
    LAZY_INSTANCE_INITIALIZER;
}  // namespace

ClientKeyStore::ClientKeyStore() {}

ClientKeyStore::~ClientKeyStore() {}

// static
ClientKeyStore* ClientKeyStore::GetInstance() {
  return g_client_key_store.Pointer();
}

void ClientKeyStore::AddProvider(CertKeyProvider* provider) {
  base::AutoLock auto_lock(lock_);
  providers_.push_back(provider);
}

void ClientKeyStore::RemoveProvider(const CertKeyProvider* provider) {
  base::AutoLock auto_lock(lock_);

  const auto& it = std::find(providers_.begin(), providers_.end(), provider);
  if (it != providers_.end())
    providers_.erase(it);
}

scoped_refptr<SSLPrivateKey> ClientKeyStore::FetchClientCertPrivateKey(
    const X509Certificate& certificate) {
  base::AutoLock auto_lock(lock_);

  for (const auto& provider : providers_) {
    scoped_refptr<SSLPrivateKey> key;
    if (provider->GetCertificateKey(certificate, &key))
      return key;
  }
  return nullptr;
}

}  // namespace net