diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-17 09:57:18 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-17 09:57:18 +0000 |
commit | 313834720d46a68071afe305975f8b70e9bc5782 (patch) | |
tree | 1d7b0dea339a8bcf3499cf29f27217cc985f35a1 /net/base/openssl_util.h | |
parent | 0d18ee21d5ddbfecf3951ac8fc0f5a30465e0ffe (diff) | |
download | chromium_src-313834720d46a68071afe305975f8b70e9bc5782.zip chromium_src-313834720d46a68071afe305975f8b70e9bc5782.tar.gz chromium_src-313834720d46a68071afe305975f8b70e9bc5782.tar.bz2 |
Refactor EnsureOpenSSLInit and openssl_util into base
This allows the base/crypto methods to call EnsureOpenSSLInit.
Also factors out the SSL_CTX and X509_STORE to be more closely associated with their consumers (ssl socket and X509Certificate resp.) rather than process wide globals.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/4963002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66413 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/openssl_util.h')
-rw-r--r-- | net/base/openssl_util.h | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/net/base/openssl_util.h b/net/base/openssl_util.h deleted file mode 100644 index d4603c6..0000000 --- a/net/base/openssl_util.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <openssl/ssl.h> - -#include "base/lock.h" -#include "base/scoped_vector.h" -#include "base/singleton.h" - -namespace net { - -// A helper class that takes care of destroying OpenSSL objects when it goes out -// of scope. -template <typename T, void (*destructor)(T*)> -class ScopedSSL { - public: - explicit ScopedSSL(T* ptr_) : ptr_(ptr_) { } - ~ScopedSSL() { if (ptr_) (*destructor)(ptr_); } - - T* get() const { return ptr_; } - - private: - T* ptr_; -}; - -// Singleton for initializing / cleaning up OpenSSL and holding a X509 store. -// Access it via GetOpenSSLInitSingleton(). -class OpenSSLInitSingleton { - public: - SSL_CTX* ssl_ctx() const { return ssl_ctx_.get(); } - X509_STORE* x509_store() const { return store_.get(); } - - private: - friend struct DefaultSingletonTraits<OpenSSLInitSingleton>; - OpenSSLInitSingleton(); - ~OpenSSLInitSingleton(); - - static void LockingCallback(int mode, int n, const char* file, int line); - void OnLockingCallback(int mode, int n, const char* file, int line); - - ScopedSSL<SSL_CTX, SSL_CTX_free> ssl_ctx_; - ScopedSSL<X509_STORE, X509_STORE_free> store_; - // These locks are used and managed by OpenSSL via LockingCallback(). - ScopedVector<Lock> locks_; - - DISALLOW_COPY_AND_ASSIGN(OpenSSLInitSingleton); -}; - -OpenSSLInitSingleton* GetOpenSSLInitSingleton(); - -// Initialize OpenSSL if it isn't already initialized. This must be called -// before any other OpenSSL functions (except GetOpenSSLInitSingleton above). -// This function is thread-safe, and OpenSSL will only ever be initialized once. -// OpenSSL will be properly shut down on program exit. -void EnsureOpenSSLInit(); - -} // namespace net - |