Chromium Code Reviews| 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/lazy_instance.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/synchronization/lock.h" | |
| 16 #include "net/base/net_export.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 class SSLPrivateKey; | |
| 21 class X509Certificate; | |
| 22 | |
| 23 // TODO(rsleevi, davidben): Remove this once https://crbug.com/394131 is fixed. | |
| 24 // A certificate and key store that allows several external certificate | |
| 25 // providers to push certificates and keys into this store. All currently | |
| 26 // provided certificates will be exposed through |FetchClientCertPrivateKey|. | |
| 27 // Methods of this singleton can be called from any thread. | |
| 28 class NET_EXPORT ClientKeyStore { | |
| 29 public: | |
| 30 class CertKeyProvider { | |
| 31 public: | |
| 32 // This can be called from any thread. | |
| 33 virtual ~CertKeyProvider() {} | |
| 34 | |
| 35 // Obtains a handle to the certificate private key for |cert| and stores it | |
| 36 // in |private_key|. | |
| 37 // If the CertKeyProvider does not know about the |cert|, returns false. If | |
| 38 // it knows about the certificate, but is unable to return the private key, | |
| 39 // returns true and sets |*private_key| to nullptr. | |
| 40 // This can be called from any thread. | |
| 41 virtual bool GetCertificateKey(const X509Certificate& cert, | |
| 42 scoped_ptr<SSLPrivateKey>* private_key) = 0; | |
| 43 }; | |
| 44 | |
| 45 static ClientKeyStore* GetInstance(); | |
| 46 | |
| 47 // The |provider| will be accessed and destroyed on any thread but no | |
|
mattm
2015/08/21 23:18:17
Comment about what thread |provider| will be destr
pneubeck (no reviews)
2015/08/24 10:08:06
Done.
| |
| 48 // concurrent method invocations will happen. | |
| 49 // |provider| must be valid until it is removed using |RemoveProvider| or the | |
| 50 // store is destroyed. | |
| 51 void AddProvider(CertKeyProvider* provider); | |
| 52 | |
| 53 void RemoveProvider(const CertKeyProvider* provider); | |
| 54 | |
| 55 // Given a |certificate|'s public key, return the corresponding private | |
| 56 // key if any of the registered providers has a matching key. | |
| 57 // Returns its matching private key on success, nullptr otherwise. | |
| 58 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | |
| 59 const X509Certificate& certificate); | |
| 60 | |
| 61 private: | |
| 62 friend struct base::DefaultLazyInstanceTraits<ClientKeyStore>; | |
| 63 | |
| 64 ClientKeyStore(); | |
| 65 ~ClientKeyStore(); | |
| 66 | |
| 67 base::Lock lock_; | |
| 68 std::vector<CertKeyProvider*> providers_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(ClientKeyStore); | |
| 71 }; | |
| 72 | |
| 73 } // namespace net | |
| 74 | |
| 75 #endif // NET_SSL_CLIENT_KEY_STORE_H_ | |
| OLD | NEW |