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