| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ | 5 #ifndef NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ |
| 6 #define NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ | 6 #define NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 10 // Avoid including <openssl/evp.h> |
| 11 typedef struct evp_pkey_st EVP_PKEY; |
| 12 |
| 8 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 9 | 14 #include "net/base/net_export.h" |
| 10 // Avoid including <openssl/evp.h> here. | |
| 11 typedef struct evp_pkey_st EVP_PKEY; | |
| 12 | 15 |
| 13 class GURL; | 16 class GURL; |
| 14 | 17 |
| 15 namespace net { | 18 namespace net { |
| 16 | 19 |
| 17 // Defines an abstract store for private keys; the OpenSSL library does not | 20 class X509Certificate; |
| 18 // provide this service so it is left to individual platforms to provide it. | 21 |
| 19 // | 22 // OpenSSLPrivateKeyStore provides an interface for storing |
| 20 // The contract is that the private key will be stored in an appropriate secure | 23 // public/private key pairs to system storage on platforms where |
| 21 // system location, and be available to the SSLClientSocketOpenSSL when using a | 24 // OpenSSL is used. |
| 22 // client certificate created against the associated public key for client | 25 // This class shall only be used from the network thread. |
| 23 // authentication. | 26 class NET_EXPORT OpenSSLPrivateKeyStore { |
| 24 class OpenSSLPrivateKeyStore { | |
| 25 public: | 27 public: |
| 26 // Platforms must define this factory function as appropriate. | 28 // Called to permanently store a private/public key pair, generated |
| 27 static OpenSSLPrivateKeyStore* GetInstance(); | 29 // via <keygen> while visiting |url|, to an appropriate system |
| 30 // location. Increments |pkey|'s reference count, so the caller is still |
| 31 // responsible for calling EVP_PKEY_free on it. |
| 32 // |url| is the corresponding server URL. |
| 33 // |pkey| is the key pair handle. |
| 34 // Returns false if an error occurred whilst attempting to store the key. |
| 35 static bool StoreKeyPair(const GURL& url, EVP_PKEY* pkey); |
| 28 | 36 |
| 29 virtual ~OpenSSLPrivateKeyStore() {} | 37 // Checks that the private key for a given public key is installed. |
| 30 | 38 // |pub_key| a public key. |
| 31 // Called to store a private key generated via <keygen> while visiting |url|. | 39 // Returns true if there is a private key that was previously |
| 32 // Does not takes ownership of |pkey|, the caller reamins responsible to | 40 // recorded through StoreKeyPair(). |
| 33 // EVP_PKEY_free it. (Internally, a copy maybe made or the reference count | 41 // NOTE: Intentionally not implemented on Android because there is no |
| 34 // incremented). | 42 // platform API that can perform this operation silently. |
| 35 // Returns false if an error occurred whilst attempting to store the key. | 43 static bool HasPrivateKey(EVP_PKEY* pub_key); |
| 36 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) = 0; | |
| 37 | |
| 38 // Given a |public_key| part returns the corresponding private key, or NULL | |
| 39 // if no key found. Does NOT return ownership. | |
| 40 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* public_key) = 0; | |
| 41 | |
| 42 protected: | |
| 43 OpenSSLPrivateKeyStore() {} | |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 OpenSSLPrivateKeyStore(); // not implemented. |
| 47 ~OpenSSLPrivateKeyStore(); // not implemented. |
| 46 DISALLOW_COPY_AND_ASSIGN(OpenSSLPrivateKeyStore); | 48 DISALLOW_COPY_AND_ASSIGN(OpenSSLPrivateKeyStore); |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 } // namespace net | 51 } // namespace net |
| 50 | 52 |
| 51 #endif // NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ | 53 #endif // NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ |
| OLD | NEW |