Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #include <openssl/evp.h> | |
| 6 | |
| 7 #include "net/base/openssl_private_key_store.h" | |
|
wtc
2011/08/09 18:47:22
This header probably should be listed first.
michaelbai
2011/08/11 16:10:18
Done.
| |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/singleton.h" | |
| 11 #include "crypto/openssl_util.h" | |
| 12 #include "net/android/network_library.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class OpenSSLKeyStoreAndroid : public OpenSSLPrivateKeyStore { | |
| 19 public: | |
| 20 ~OpenSSLKeyStoreAndroid() {} | |
| 21 | |
| 22 // 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 | |
| 24 // API to associate a name with them), so this is a non-issue. | |
| 25 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) { | |
| 26 uint8* public_key = NULL; | |
| 27 int public_len = i2d_PublicKey(pkey, &public_key); | |
| 28 uint8* private_key = NULL; | |
| 29 int private_len = i2d_PrivateKey(pkey, &private_key); | |
| 30 | |
| 31 bool ret = false; | |
| 32 if (public_len && private_len) { | |
| 33 ret = net::android::StoreKeyPair(public_key, public_len, | |
| 34 private_key, private_len); | |
|
wtc
2011/08/09 18:47:22
Fix argument indentation.
michaelbai
2011/08/11 16:10:18
Done.
| |
| 35 } | |
| 36 LOG_IF(ERROR, !ret) << "StorePrivateKey failed. pub len = " << public_len | |
| 37 << " priv len = " << private_len; | |
| 38 OPENSSL_free(public_key); | |
| 39 OPENSSL_free(private_key); | |
| 40 return ret; | |
| 41 } | |
| 42 | |
| 43 virtual EVP_PKEY* FetchPrivateKey(EVP_PKEY* pkey) { | |
| 44 // TODO(joth): Implement when client authentication is required. | |
| 45 NOTIMPLEMENTED(); | |
| 46 return NULL; | |
| 47 } | |
| 48 | |
| 49 static OpenSSLKeyStoreAndroid* GetInstance(); | |
| 50 | |
| 51 private: | |
| 52 OpenSSLKeyStoreAndroid() {} | |
| 53 friend struct DefaultSingletonTraits<OpenSSLKeyStoreAndroid>; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyStoreAndroid); | |
| 56 }; | |
| 57 | |
| 58 } // namespace | |
| 59 | |
| 60 // static | |
| 61 OpenSSLKeyStoreAndroid* OpenSSLKeyStoreAndroid::GetInstance() { | |
| 62 return Singleton<OpenSSLKeyStoreAndroid>::get(); | |
| 63 } | |
| 64 | |
| 65 /* | |
| 66 // static | |
| 67 // TODO(MERGE): Conflict with openssl_memory_private_key_store.cc | |
| 68 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { | |
| 69 return OpenSSLKeyStoreAndroid::GetInstance(); | |
| 70 } | |
| 71 */ | |
|
wtc
2011/08/09 18:47:22
Please use
#if 0
...
#endif
to comment out a bloc
michaelbai
2011/08/11 16:10:18
Fixed, This introduced in the merge and fixed in g
| |
| 72 } // namespace net | |
| OLD | NEW |