OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #ifndef NET_SSL_CLIENT_KEY_STORE_H_ | |
6 #define NET_SSL_CLIENT_KEY_STORE_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/synchronization/lock.h" | |
16 #include "net/base/net_export.h" | |
17 | |
18 template <typename T> | |
19 struct DefaultSingletonTraits; | |
20 | |
21 namespace net { | |
22 | |
23 class SSLPrivateKey; | |
24 class X509Certificate; | |
25 | |
26 // A certificate and key store that allows several external certificate | |
27 // providers to push certificates and keys into this store. All currently | |
28 // provided certificates will be exposed through |FetchClientCertPrivateKey|. | |
29 // Methods of this singleton can be called on any thread. | |
30 class NET_EXPORT ClientKeyStore { | |
31 public: | |
32 struct ProviderHandle { | |
33 ProviderHandle() : id(-1) {} | |
34 ProviderHandle(int provider_id) : id(provider_id) {} | |
35 int id; | |
36 }; | |
Ryan Sleevi
2015/08/08 00:14:22
Why is this necessary? Why do you return it as Pro
pneubeck (no reviews)
2015/08/13 08:20:19
refactored.
| |
37 | |
38 using KeyGetter = base::Callback<scoped_ptr<SSLPrivateKey>(void)>; | |
Ryan Sleevi
2015/08/08 00:14:22
This seems unnecessarily opaque. It does not seem
pneubeck (no reviews)
2015/08/13 08:20:19
refactored.
| |
39 | |
40 struct CertAndKey { | |
Ryan Sleevi
2015/08/08 00:14:22
Why is this a struct instead of just a std::pair o
pneubeck (no reviews)
2015/08/13 08:20:19
refactored.
| |
41 CertAndKey(); | |
42 ~CertAndKey(); | |
43 | |
44 scoped_refptr<X509Certificate> certificate; | |
45 | |
46 // Can be called on every thread. Each call returns an SSLPrivateKey that | |
47 // can be used on the calling thread. The SSLPrivateKey must represent the | |
48 // private key certified by |certificate|. | |
49 KeyGetter key_getter; | |
50 }; | |
51 using CertsAndKeys = std::vector<CertAndKey>; | |
Ryan Sleevi
2015/08/08 00:14:22
This seems unnecessarily opaque. It does not seem
pneubeck (no reviews)
2015/08/13 08:20:19
refactored.
| |
52 | |
53 static ClientKeyStore* GetInstance(); | |
54 | |
55 // Creates a new provider and returns a handle to that provider. | |
56 ProviderHandle CreateNewProvider(); | |
57 | |
58 // Removes the given provider. All provided certificates of that provider will | |
59 // be dropped. | |
60 void RemoveProvider(ProviderHandle provider); | |
61 | |
62 // Sets the certificates provided by |provider| to |certs|. Any previously set | |
63 // certificates will be ignored. | |
64 // |certs| will be empty after this call. | |
65 void SetCertificates(ProviderHandle provider, CertsAndKeys* certs); | |
66 | |
67 // Given a certificate's |public_key|, return the corresponding private | |
68 // key if any of the registered providers has a matching key. | |
69 // Returns its matching private key on success, NULL otherwise. | |
70 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | |
71 const X509Certificate* certificate); | |
72 | |
73 private: | |
74 ClientKeyStore(); | |
75 ~ClientKeyStore(); | |
76 | |
77 friend struct DefaultSingletonTraits<ClientKeyStore>; | |
78 int next_free_provider_id_ = 0; | |
79 std::map<int, CertsAndKeys> certs_per_provider_; | |
80 base::Lock lock_; | |
Ryan Sleevi
2015/08/08 00:14:22
Presumably this lock protects all these members; h
pneubeck (no reviews)
2015/08/13 08:20:19
Done.
| |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(ClientKeyStore); | |
83 }; | |
84 | |
85 } // namespace net | |
86 | |
87 #endif // NET_SSL_CLIENT_KEY_STORE_H_ | |
OLD | NEW |