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 3 // found in the LICENSE file. 4 5 #ifndef NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ 6 #define NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ 7 #pragma once 8 9 #include "base/basictypes.h" 10 11 typedef struct evp_pkey_st EVP_PKEY; 12 13 class GURL; 14 15 namespace net { 16 17 // Defines an abstract store for private keys; the OpenSSL library does not 18 // provide this service so it is left to individual platforms to provide it. 19 // 20 // The contract is that the private key will be stored in an appropriate secure 21 // system location, and be available to the SSLClientSocketOpenSSL when using a 22 // client certificate created against the associated public key for client 23 // authentication. 24 class OpenSSLPrivateKeyStore { 25 public: 26 // Platforms must define this factory function as appropriate. 27 static OpenSSLPrivateKeyStore* GetInstance(); 28 ~OpenSSLPrivateKeyStore()29 virtual ~OpenSSLPrivateKeyStore() {} 30 31 // Called to store a private key generated via <keygen> while visiting |url|. 32 // Does not takes ownership of |pkey|, the caller reamins responsible to 33 // EVP_PKEY_free it. (Internally, a copy maybe made or the reference count 34 // incremented). 35 // Returns false if an error occurred whilst attempting to store the 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: OpenSSLPrivateKeyStore()43 OpenSSLPrivateKeyStore() {} 44 45 private: 46 DISALLOW_COPY_AND_ASSIGN(OpenSSLPrivateKeyStore); 47 }; 48 49 } // namespace net 50 51 #endif // NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ 52