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
+
1
37
#include < websocketpp/config/asio.hpp>
2
38
3
39
#include < websocketpp/server.hpp>
@@ -12,7 +48,7 @@ using websocketpp::lib::bind;
12
48
13
49
// pull out the type of messages sent by our config
14
50
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;
16
52
17
53
void on_message (server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
18
54
std::cout << " on_message called with hdl: " << hdl.lock ().get ()
@@ -46,27 +82,30 @@ enum tls_mode {
46
82
};
47
83
48
84
context_ptr on_tls_init (tls_mode mode, websocketpp::connection_hdl hdl) {
85
+ namespace asio = websocketpp::lib::asio;
86
+
49
87
std::cout << " on_tls_init called with hdl: " << hdl.lock ().get () << std::endl;
50
88
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);
52
91
53
92
try {
54
93
if (mode == MOZILLA_MODERN) {
55
94
// 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);
61
100
} 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);
66
105
}
67
106
ctx->set_password_callback (bind (&get_password));
68
107
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);
70
109
71
110
// Example method of generating this file:
72
111
// `openssl dhparam -out dh.pem 2048`
0 commit comments