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