Skip to content

Commit 9713455

Browse files
author
Peter Thorson
committed
Fix TLS+Asio Standalone builds
1 parent 044eda9 commit 9713455

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ HEAD
4242
reporting and providing test case details. #443
4343
- Bug: Fix an issue where the wrong type of strand was being created. Thank you
4444
Bastien Brunnenstein for reporting and a patch. #462
45+
- Bug: Fix an issue where TLS includes were broken for Asio Standalone builds.
46+
Thank you giachi and Bastien Brunnenstein for reporting. #491
47+
- Compatibility: Fixes a number of build & config issues on Visual Studio 2015
4548
- Compatibility: Removes non-standards compliant masking behavior. #395, #469
4649

4750
0.6.0

examples/echo_server_tls/echo_server_tls.cpp

+51-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
/*
2+
* Copyright (c) 2015, Peter Thorson. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* * Redistributions of source code must retain the above copyright
7+
* notice, this list of conditions and the following disclaimer.
8+
* * Redistributions in binary form must reproduce the above copyright
9+
* notice, this list of conditions and the following disclaimer in the
10+
* documentation and/or other materials provided with the distribution.
11+
* * Neither the name of the WebSocket++ Project nor the
12+
* names of its contributors may be used to endorse or promote products
13+
* derived from this software without specific prior written permission.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*
26+
*/
27+
28+
/**
29+
* NOTES
30+
*
31+
* This example uses a number of standard classes through the websocketpp::lib
32+
* namespace. This is to allow easy switching between Boost, the C++11 STL, and
33+
* the standalone Asio library. Your program need not use these namespaces if
34+
* you do not need this sort of flexibility.
35+
*/
36+
137
#include <websocketpp/config/asio.hpp>
238

339
#include <websocketpp/server.hpp>
@@ -12,7 +48,7 @@ using websocketpp::lib::bind;
1248

1349
// pull out the type of messages sent by our config
1450
typedef websocketpp::config::asio::message_type::ptr message_ptr;
15-
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
51+
typedef websocketpp::lib::shared_ptr<websocketpp::lib::asio::ssl::context> context_ptr;
1652

1753
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
1854
std::cout << "on_message called with hdl: " << hdl.lock().get()
@@ -46,27 +82,30 @@ enum tls_mode {
4682
};
4783

4884
context_ptr on_tls_init(tls_mode mode, websocketpp::connection_hdl hdl) {
85+
namespace asio = websocketpp::lib::asio;
86+
4987
std::cout << "on_tls_init called with hdl: " << hdl.lock().get() << std::endl;
5088
std::cout << "using TLS mode: " << (mode == MOZILLA_MODERN ? "Mozilla Modern" : "Mozilla Intermediate") << std::endl;
51-
context_ptr ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);
89+
90+
context_ptr ctx = websocketpp::lib::make_shared<asio::ssl::context>(asio::ssl::context::sslv23);
5291

5392
try {
5493
if (mode == MOZILLA_MODERN) {
5594
// Modern disables TLSv1
56-
ctx->set_options(boost::asio::ssl::context::default_workarounds |
57-
boost::asio::ssl::context::no_sslv2 |
58-
boost::asio::ssl::context::no_sslv3 |
59-
boost::asio::ssl::context::no_tlsv1 |
60-
boost::asio::ssl::context::single_dh_use);
95+
ctx->set_options(asio::ssl::context::default_workarounds |
96+
asio::ssl::context::no_sslv2 |
97+
asio::ssl::context::no_sslv3 |
98+
asio::ssl::context::no_tlsv1 |
99+
asio::ssl::context::single_dh_use);
61100
} else {
62-
ctx->set_options(boost::asio::ssl::context::default_workarounds |
63-
boost::asio::ssl::context::no_sslv2 |
64-
boost::asio::ssl::context::no_sslv3 |
65-
boost::asio::ssl::context::single_dh_use);
101+
ctx->set_options(asio::ssl::context::default_workarounds |
102+
asio::ssl::context::no_sslv2 |
103+
asio::ssl::context::no_sslv3 |
104+
asio::ssl::context::single_dh_use);
66105
}
67106
ctx->set_password_callback(bind(&get_password));
68107
ctx->use_certificate_chain_file("server.pem");
69-
ctx->use_private_key_file("server.pem", boost::asio::ssl::context::pem);
108+
ctx->use_private_key_file("server.pem", asio::ssl::context::pem);
70109

71110
// Example method of generating this file:
72111
// `openssl dhparam -out dh.pem 2048`

websocketpp/common/asio_ssl.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
#ifndef WEBSOCKETPP_COMMON_ASIO_SSL_HPP
2929
#define WEBSOCKETPP_COMMON_ASIO_SSL_HPP
3030

31+
// NOTE: This file must be included before common/asio.hpp
32+
3133
#ifdef ASIO_STANDALONE
32-
#include <asio/asio/ssl.hpp>
34+
#include <asio/ssl.hpp>
3335
#else
3436
#include <boost/asio/ssl.hpp>
3537
#endif

websocketpp/transport/asio/security/tls.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
#include <websocketpp/uri.hpp>
3434

35-
#include <websocketpp/common/asio.hpp>
3635
#include <websocketpp/common/asio_ssl.hpp>
36+
#include <websocketpp/common/asio.hpp>
3737
#include <websocketpp/common/connection_hdl.hpp>
3838
#include <websocketpp/common/functional.hpp>
3939
#include <websocketpp/common/memory.hpp>

0 commit comments

Comments
 (0)