Ticket #7610: boost-psk-patch.diff
File boost-psk-patch.diff, 11.6 KB (added by , 10 years ago) |
---|
-
asio/ssl/context.hpp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/context.hpp asio/ssl/context.hpp
old new 28 28 # include <boost/asio/ssl/detail/openssl_init.hpp> 29 29 # include <boost/asio/ssl/detail/password_callback.hpp> 30 30 # include <boost/asio/ssl/detail/verify_callback.hpp> 31 # include <boost/asio/ssl/detail/psk_callback.hpp> 31 32 # include <boost/asio/ssl/verify_mode.hpp> 32 33 #endif // defined(BOOST_ASIO_ENABLE_OLD_SSL) 33 34 … … public: 167 168 BOOST_ASIO_DECL boost::system::error_code set_verify_mode( 168 169 verify_mode v, boost::system::error_code& ec); 169 170 171 BOOST_ASIO_DECL void set_psk_identity(const char* psk); 172 173 template <typename PSKCallback> 174 void set_psk_server_callback(PSKCallback callback); 175 176 template <typename PSKCallback> 177 boost::system::error_code set_psk_server_callback(PSKCallback callback, 178 boost::system::error_code& ec); 179 170 180 /// Set the callback used to verify peer certificates. 171 181 /** 172 182 * This function is used to specify a callback function that will be called … … public: 494 504 boost::system::error_code& ec); 495 505 496 506 private: 507 // Helper function used to set a peer identity and PSK callback. 508 BOOST_ASIO_DECL boost::system::error_code do_set_psk_server_callback( 509 detail::psk_callback_base* callback, boost::system::error_code& ec); 510 511 // Callback used when the SSL implementation wants to verify a PSK. 512 BOOST_ASIO_DECL static unsigned int psk_server_callback_function(SSL *ssl, 513 const char* identity, unsigned char* psk, unsigned int max_psk_len); 514 497 515 // Helper function used to set a peer certificate verification callback. 498 516 BOOST_ASIO_DECL boost::system::error_code do_set_verify_callback( 499 517 detail::verify_callback_base* callback, boost::system::error_code& ec); -
asio/ssl/detail/engine.hpp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/detail/engine.hpp asio/ssl/detail/engine.hpp
old new public: 77 77 BOOST_ASIO_DECL boost::system::error_code set_verify_callback( 78 78 verify_callback_base* callback, boost::system::error_code& ec); 79 79 80 // Set a peer PSK verification callback 81 BOOST_ASIO_DECL boost::system::error_code set_psk_server_callback( 82 psk_callback_base* callback, boost::system::error_code& ec); 83 80 84 // Perform an SSL handshake using either SSL_connect (client-side) or 81 85 // SSL_accept (server-side). 82 86 BOOST_ASIO_DECL want handshake( … … private: 116 120 BOOST_ASIO_DECL static int verify_callback_function( 117 121 int preverified, X509_STORE_CTX* ctx); 118 122 123 BOOST_ASIO_DECL static unsigned int psk_server_callback_function( 124 SSL *ssl, const char* identity, unsigned char* psk, unsigned int max_psk_len); 125 119 126 // The SSL_accept function may not be thread safe. This mutex is used to 120 127 // protect all calls to the SSL_accept function. 121 128 BOOST_ASIO_DECL static boost::asio::detail::static_mutex& accept_mutex(); -
asio/ssl/detail/impl/engine.ipp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/detail/impl/engine.ipp asio/ssl/detail/impl/engine.ipp
old new boost::system::error_code engine::set_ve 98 88 return ec; 99 89 } 100 90 91 boost::system::error_code engine::set_psk_server_callback( 92 psk_callback_base* callback, boost::system::error_code& ec) 93 { 94 if (SSL_get_app_data(ssl_)) 95 delete static_cast<psk_callback_base*>(SSL_get_app_data(ssl_)); 96 97 SSL_set_app_data(ssl_, callback); 98 99 ::SSL_set_psk_server_callback(ssl_, &engine::psk_server_callback_function); 100 101 ec = boost::system::error_code(); 102 return ec; 103 } 104 101 105 int engine::verify_callback_function(int preverified, X509_STORE_CTX* ctx) 102 106 { 103 107 if (ctx) … … int engine::verify_callback_function(int 119 123 } 120 124 121 125 return 0; 126 } 127 128 unsigned int engine::psk_server_callback_function(SSL *ssl, 129 const char* identity, unsigned char* psk, unsigned int max_psk_len) 130 { 131 if (SSL_get_app_data(ssl)) 132 { 133 psk_callback_base* callback = 134 static_cast<psk_callback_base*>( 135 SSL_get_app_data(ssl)); 136 137 psk_context psk_ctx(ssl, identity, psk, max_psk_len); 138 return callback->call(psk_ctx); 139 } 140 141 return 0; 122 142 } 123 143 124 144 engine::want engine::handshake( -
asio/ssl/detail/psk_callback.hpp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/detail/psk_callback.hpp asio/ssl/detail/psk_callback.hpp
old new 1 // 2 // ssl/detail/psk_callback.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2012 Roman Bovsunovskiy (a2k0001 at gmail dot com) 6 // 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // 10 11 #ifndef BOOST_ASIO_SSL_DETAIL_PSK_CALLBACK_HPP 12 #define BOOST_ASIO_SSL_DETAIL_PSK_CALLBACK_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 20 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) 21 # include <boost/asio/ssl/psk_context.hpp> 22 #endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL) 23 24 #include <boost/asio/detail/push_options.hpp> 25 26 namespace boost { 27 namespace asio { 28 namespace ssl { 29 namespace detail { 30 31 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) 32 33 class psk_callback_base 34 { 35 public: 36 virtual ~psk_callback_base() 37 { 38 } 39 40 virtual unsigned int call(psk_context& ctx) = 0; 41 }; 42 43 template <typename PSKCallback> 44 class psk_callback : public psk_callback_base 45 { 46 public: 47 explicit psk_callback(PSKCallback callback) 48 : callback_(callback) 49 { 50 } 51 52 virtual unsigned int call(psk_context& ctx) 53 { 54 return callback_(ctx); 55 } 56 57 private: 58 PSKCallback callback_; 59 }; 60 61 #endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL) 62 63 } // namespace detail 64 } // namespace ssl 65 } // namespace asio 66 } // namespace boost 67 68 #include <boost/asio/detail/pop_options.hpp> 69 70 #endif // BOOST_ASIO_SSL_DETAIL_PSK_CALLBACK_HPP -
asio/ssl/impl/context.hpp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/impl/context.hpp asio/ssl/impl/context.hpp
old new namespace ssl { 30 30 31 31 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) 32 32 33 template <typename PSKCallback> 34 void context::set_psk_server_callback(PSKCallback callback) 35 { 36 boost::system::error_code ec; 37 this->set_psk_server_callback(callback, ec); 38 boost::asio::detail::throw_error(ec, "set_psk_callback"); 39 } 40 41 template <typename PSKCallback> 42 boost::system::error_code context::set_psk_server_callback(PSKCallback callback, 43 boost::system::error_code& ec) 44 { 45 return do_set_psk_server_callback( 46 new detail::psk_callback<PSKCallback>(callback), ec); 47 } 48 33 49 template <typename VerifyCallback> 34 50 void context::set_verify_callback(VerifyCallback callback) 35 51 { -
asio/ssl/impl/context.ipp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/impl/context.ipp asio/ssl/impl/context.ipp
old new int context::verify_callback_function(in 475 487 return 0; 476 488 } 477 489 490 BOOST_ASIO_DECL void context::set_psk_identity(const char* identity) 491 { 492 SSL_CTX_use_psk_identity_hint(handle_, identity); 493 } 494 495 boost::system::error_code context::do_set_psk_server_callback( 496 detail::psk_callback_base* callback, boost::system::error_code& ec) 497 { 498 SSL_CTX_set_app_data(handle_, callback); 499 500 ::SSL_CTX_set_psk_server_callback(handle_, 501 &context::psk_server_callback_function); 502 503 ec = boost::system::error_code(); 504 return ec; 505 } 506 507 unsigned int context::psk_server_callback_function(SSL *ssl, 508 const char* identity, unsigned char* psk, unsigned int max_psk_len) 509 { 510 SSL_CTX* handle = ::SSL_get_SSL_CTX(ssl); 511 512 detail::psk_callback_base* callback = 513 static_cast<detail::psk_callback_base*>( 514 SSL_CTX_get_app_data(handle)); 515 516 psk_context psk_ctx(ssl, identity, psk, max_psk_len); 517 return callback->call(psk_ctx); 518 } 519 478 520 boost::system::error_code context::do_set_password_callback( 479 521 detail::password_callback_base* callback, boost::system::error_code& ec) 480 522 { -
asio/ssl/psk_context.hpp
diff -rupN '-x*DS*' /home/a2k/tmp/boost_1_52_0_beta1/boost/asio/ssl/psk_context.hpp asio/ssl/psk_context.hpp
old new 1 // 2 // ssl/psk_context.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2012 Roman Bovsunovskiy (a2k0001 at gmail dot com) 6 // 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // 10 11 #ifndef BOOST_ASIO_SSL_PSK_CONTEXT_HPP 12 #define BOOST_ASIO_SSL_PSK_CONTEXT_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 20 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) 21 # include <boost/asio/detail/noncopyable.hpp> 22 # include <boost/asio/ssl/detail/openssl_types.hpp> 23 #endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL) 24 25 #include <boost/asio/detail/push_options.hpp> 26 27 namespace boost { 28 namespace asio { 29 namespace ssl { 30 31 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) 32 33 /** 34 * @note The psk_context does not own the underlying PSK string. 35 */ 36 class psk_context 37 : private noncopyable 38 { 39 public: 40 /// The native handle type of the PSK context. 41 typedef SSL* native_handle_ssl_type; 42 typedef const char* native_handle_identity_type; 43 typedef unsigned char* native_handle_psk_type; 44 typedef unsigned int native_handle_psk_maxlen_type; 45 46 /// Constructor. 47 explicit psk_context(native_handle_ssl_type ssl_handle, 48 native_handle_identity_type identity_handle, 49 native_handle_psk_type psk_handle, 50 native_handle_psk_maxlen_type psk_maxlen_handle) 51 : ssl_handle_(ssl_handle_), 52 identity_handle_(identity_handle), 53 psk_handle_(psk_handle), 54 psk_maxlen_handle_(psk_maxlen_handle) 55 { 56 } 57 58 /// Get the underlying implementation in the native type. 59 /** 60 * This function may be used to obtain the underlying implementation of the 61 * context. This is intended to allow access to context functionality that is 62 * not otherwise provided. 63 */ 64 native_handle_ssl_type native_ssl_handle() 65 { 66 return ssl_handle_; 67 } 68 69 native_handle_identity_type native_identity_handle() 70 { 71 return identity_handle_; 72 } 73 74 native_handle_psk_type native_psk_handle() 75 { 76 return psk_handle_; 77 } 78 native_handle_psk_maxlen_type native_psk_maxlen_handle() 79 { 80 return psk_maxlen_handle_; 81 } 82 83 private: 84 // The underlying native implementation. 85 native_handle_ssl_type ssl_handle_; 86 native_handle_identity_type identity_handle_; 87 native_handle_psk_type psk_handle_; 88 native_handle_psk_maxlen_type psk_maxlen_handle_; 89 }; 90 91 #endif // defined(BOOST_ASIO_ENABLE_OLD_SSL) 92 93 } // namespace ssl 94 } // namespace asio 95 } // namespace boost 96 97 #include <boost/asio/detail/pop_options.hpp> 98 99 #endif // BOOST_ASIO_SSL_PSK_CONTEXT_HPP