summaryrefslogtreecommitdiffhomepage
path: root/error.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-09 13:15:18 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-09 13:15:18 +0100
commitdc2e2b3e293a8374a2627982b521cc6865129c49 (patch)
treebd34d6c13e330be5937aec29503cbe6649d0fa74 /error.cpp
parentd747193e76baf689211d9f1e42335360288d43c0 (diff)
Separated out websocket
Diffstat (limited to 'error.cpp')
-rw-r--r--error.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/error.cpp b/error.cpp
new file mode 100644
index 0000000..d7a26de
--- /dev/null
+++ b/error.cpp
@@ -0,0 +1,32 @@
+#include "error.h"
+
+#include <iostream>
+
+#include <boost/asio/ssl/error.hpp>
+
+// Report a failure
+void fail(boost::beast::error_code ec, char const* what)
+{
+ // ssl::error::stream_truncated, also known as an SSL "short read",
+ // indicates the peer closed the connection without performing the
+ // required closing handshake (for example, Google does this to
+ // improve performance). Generally this can be a security issue,
+ // but if your communication protocol is self-terminated (as
+ // it is with both HTTP and WebSocket) then you may simply
+ // ignore the lack of close_notify.
+ //
+ // https://github.com/boostorg/beast/issues/38
+ //
+ // https://security.stackexchange.com/questions/91435/how-to-handle-a-malicious-ssl-tls-shutdown
+ //
+ // When a short read would cut off the end of an HTTP message,
+ // Beast returns the error beast::http::error::partial_message.
+ // Therefore, if we see a short read here, it has occurred
+ // after the message has been completed, so it is safe to ignore it.
+
+ if (ec == boost::asio::ssl::error::stream_truncated)
+ return;
+
+ std::cerr << what << ": " << ec.message() << "\n";
+}
+