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 
      8 #include <vector>
      9 
     10 // Avoid including <openssl/evp.h>
     11 typedef struct evp_pkey_st EVP_PKEY;
     12 
     13 #include "base/basictypes.h"
     14 #include "net/base/net_export.h"
     15 
     16 class GURL;
     17 
     18 namespace net {
     19 
     20 class X509Certificate;
     21 
     22 // OpenSSLPrivateKeyStore provides an interface for storing
     23 // public/private key pairs to system storage on platforms where
     24 // OpenSSL is used.
     25 // This class shall only be used from the network thread.
     26 class NET_EXPORT OpenSSLPrivateKeyStore {
     27  public:
     28   // Called to permanently store a private/public key pair, generated
     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);
     36 
     37   // Checks that the private key for a given public key is installed.
     38   // |pub_key| a public key.
     39   // Returns true if there is a private key that was previously
     40   // recorded through StoreKeyPair().
     41   // NOTE: Intentionally not implemented on Android because there is no
     42   // platform API that can perform this operation silently.
     43   static bool HasPrivateKey(EVP_PKEY* pub_key);
     44 
     45  private:
     46   OpenSSLPrivateKeyStore();  // not implemented.
     47   ~OpenSSLPrivateKeyStore();  // not implemented.
     48   DISALLOW_COPY_AND_ASSIGN(OpenSSLPrivateKeyStore);
     49 };
     50 
     51 } // namespace net
     52 
     53 #endif  // NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_
     54