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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 | 9 |
10 // Avoid including <openssl/evp.h> here. | 10 // Avoid including <openssl/evp.h> here. |
11 typedef struct evp_pkey_st EVP_PKEY; | 11 typedef struct evp_pkey_st EVP_PKEY; |
12 | 12 |
13 class GURL; | 13 class GURL; |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 class X509Certificate; | |
18 | |
17 // Defines an abstract store for private keys; the OpenSSL library does not | 19 // 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. | 20 // provide this service so it is left to individual platforms to provide it. |
19 // | 21 // |
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 { | 22 class OpenSSLPrivateKeyStore { |
25 public: | 23 public: |
26 // Platforms must define this factory function as appropriate. | 24 // Platforms must define this factory function as appropriate. |
27 static OpenSSLPrivateKeyStore* GetInstance(); | 25 static OpenSSLPrivateKeyStore* GetInstance(); |
28 | 26 |
29 virtual ~OpenSSLPrivateKeyStore() {} | 27 virtual ~OpenSSLPrivateKeyStore() {} |
30 | 28 |
31 // Called to store a private key generated via <keygen> while visiting |url|. | 29 // Called to store a private/public key pair, generated via <keygen> while |
32 // Does not takes ownership of |pkey|, the caller reamins responsible to | 30 // visiting |url|, to an appropriate secure system location. |
33 // EVP_PKEY_free it. (Internally, a copy maybe made or the reference count | 31 // Increments |pkey|'s reference count, so the caller is still responsible |
34 // incremented). | 32 // for calling EVP_PKEY_free on it. |
33 // |url| is the corresponding server URL. | |
34 // |pkey| is the key pair handle. | |
35 // Returns false if an error occurred whilst attempting to store the key. | 35 // Returns false if an error occurred whilst attempting to store the key. |
36 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) = 0; | 36 virtual bool StoreKeyPair(const GURL& url, EVP_PKEY* pkey) = 0; |
37 | 37 |
38 // Given a |public_key| part returns the corresponding private key, or NULL | 38 // Record the association between a certificate and its private key. |
39 // if no key found. Does NOT return ownership. | 39 // This method should be called _before_ FetchPrivateKey to ensure that |
40 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* public_key) = 0; | 40 // the private key is returned when it is called later. |
41 // |cert| is a handle to a certificate object. | |
42 // |private_key| is an OpenSSL EVP_PKEY that corresponds to the | |
43 // certificate's private key. | |
44 // Returns false if an error occured. | |
45 // This function does not take ownership of the private_key, but may | |
46 // increment its internal reference count. | |
Ryan Sleevi
2013/02/12 00:25:17
comment nit: That is the very definition of taking
digit1
2013/02/12 15:05:25
I'll rephrase that. I was just paraphrasing the or
| |
47 virtual bool RecordClientCertPrivateKey(const X509Certificate& cert, | |
48 EVP_PKEY* private_key) = 0; | |
Ryan Sleevi
2013/02/12 20:12:58
Nowhere in Chromium do we pass a "const X509Certif
digit1
2013/02/13 18:24:34
I think a simple grep would show otherwise. Howeve
| |
49 | |
50 // Given a certificate's |public_key|, return the corresponding private | |
51 // key that has been recorded previously by RecordClientCertPrivateKey(). | |
52 // |public_key| must contain the certificate's public key. | |
53 // Returns a handle to the private key's EVP_PKEY object. Caller must | |
54 // call EVP_PKEY_free() to free it. | |
Ryan Sleevi
2013/02/12 00:25:17
Can you not return a scoped_ptr<EVP_PKEY, EVP_PKEY
digit1
2013/02/13 18:24:34
Done.
| |
55 virtual EVP_PKEY* FetchClientCertPrivateKey( | |
56 const X509Certificate& cert) = 0; | |
41 | 57 |
42 protected: | 58 protected: |
43 OpenSSLPrivateKeyStore() {} | 59 OpenSSLPrivateKeyStore() {} |
44 | 60 |
45 private: | 61 private: |
46 DISALLOW_COPY_AND_ASSIGN(OpenSSLPrivateKeyStore); | 62 DISALLOW_COPY_AND_ASSIGN(OpenSSLPrivateKeyStore); |
47 }; | 63 }; |
48 | 64 |
49 } // namespace net | 65 } // namespace net |
50 | 66 |
51 #endif // NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ | 67 #endif // NET_BASE_OPENSSL_PRIVATE_KEY_STORE_H_ |
OLD | NEW |