Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/base/openssl_private_key_store.h" | 5 #include "net/base/openssl_private_key_store.h" |
| 6 | 6 |
| 7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "crypto/openssl_util.h" | 11 #include "crypto/openssl_util.h" |
| 12 #include "net/android/network_library.h" | 12 #include "net/android/network_library.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class OpenSSLKeyStoreAndroid : public OpenSSLPrivateKeyStore { | 18 class OpenSSLKeyStoreAndroid : public OpenSSLPrivateKeyStore { |
| 19 public: | 19 public: |
| 20 typedef LeakySingletonTraits<OpenSSLKeyStoreAndroid> | |
| 21 OpenSSLKeyStoreAndroidLeakyTraits; | |
|
Ryan Sleevi
2012/09/06 18:23:35
Sorry, this was my bug in my nit. This doesn't nee
Johnny(Jianning) Ding
2012/09/07 04:33:07
Done.
| |
| 20 ~OpenSSLKeyStoreAndroid() {} | 22 ~OpenSSLKeyStoreAndroid() {} |
| 21 | 23 |
| 22 // TODO(joth): Use the |url| to help identify this key to the user. | 24 // TODO(joth): Use the |url| to help identify this key to the user. |
| 23 // Currently Android has no UI to list these stored private keys (and no | 25 // Currently Android has no UI to list these stored private keys (and no |
| 24 // API to associate a name with them), so this is a non-issue. | 26 // API to associate a name with them), so this is a non-issue. |
| 25 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) { | 27 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) { |
| 26 uint8* public_key = NULL; | 28 uint8* public_key = NULL; |
| 27 int public_len = i2d_PublicKey(pkey, &public_key); | 29 int public_len = i2d_PublicKey(pkey, &public_key); |
| 28 uint8* private_key = NULL; | 30 uint8* private_key = NULL; |
| 29 int private_len = i2d_PrivateKey(pkey, &private_key); | 31 int private_len = i2d_PrivateKey(pkey, &private_key); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 40 return ret; | 42 return ret; |
| 41 } | 43 } |
| 42 | 44 |
| 43 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* pkey) { | 45 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* pkey) { |
| 44 // TODO(joth): Implement when client authentication is required. | 46 // TODO(joth): Implement when client authentication is required. |
| 45 NOTIMPLEMENTED(); | 47 NOTIMPLEMENTED(); |
| 46 return NULL; | 48 return NULL; |
| 47 } | 49 } |
| 48 | 50 |
| 49 static OpenSSLKeyStoreAndroid* GetInstance() { | 51 static OpenSSLKeyStoreAndroid* GetInstance() { |
| 50 return Singleton<OpenSSLKeyStoreAndroid>::get(); | 52 // Leak the OpenSSL key store as it is used from a non-joinable worker |
| 53 // thread that may still be running at shutdown. | |
| 54 return Singleton< | |
| 55 OpenSSLKeyStoreAndroid, | |
| 56 OpenSSLKeyStoreAndroidLeakyTraits>::get(); | |
| 51 } | 57 } |
| 52 | 58 |
| 53 private: | 59 private: |
| 60 friend struct DefaultSingletonTraits<OpenSSLKeyStoreAndroid>; | |
| 54 OpenSSLKeyStoreAndroid() {} | 61 OpenSSLKeyStoreAndroid() {} |
| 55 friend struct DefaultSingletonTraits<OpenSSLKeyStoreAndroid>; | |
| 56 | 62 |
| 57 DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyStoreAndroid); | 63 DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyStoreAndroid); |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 } // namespace | 66 } // namespace |
| 61 | 67 |
| 62 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { | 68 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { |
| 63 return OpenSSLKeyStoreAndroid::GetInstance(); | 69 return OpenSSLKeyStoreAndroid::GetInstance(); |
| 64 } | 70 } |
| 65 | 71 |
| 66 } // namespace net | 72 } // namespace net |
| OLD | NEW |