aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/tls_server.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-01 16:36:48 -0400
committerJack Lloyd <[email protected]>2017-09-02 05:18:49 -0400
commitfc19681e0bafb0647e1627bb5f79422dfbb463c1 (patch)
tree738f1815f8ad7eb015f510e0b98f715b2d74ebad /src/cli/tls_server.cpp
parent7e36654aeaf18a869412a8ff2330ddcab14cd920 (diff)
Add --dump-traces option to tls_server
Diffstat (limited to 'src/cli/tls_server.cpp')
-rw-r--r--src/cli/tls_server.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cli/tls_server.cpp b/src/cli/tls_server.cpp
index 0ec45dc42..fba0aa95f 100644
--- a/src/cli/tls_server.cpp
+++ b/src/cli/tls_server.cpp
@@ -12,6 +12,7 @@
#include <botan/tls_server.h>
#include <botan/hex.h>
+#include <botan/internal/os_utils.h>
#include "credentials.h"
#include <list>
@@ -46,7 +47,7 @@ namespace Botan_CLI {
class TLS_Server final : public Command
{
public:
- TLS_Server() : Command("tls_server cert key --port=443 --type=tcp --policy=")
+ TLS_Server() : Command("tls_server cert key --port=443 --type=tcp --policy= --dump-traces=")
{
#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
WSAData wsa_data;
@@ -78,6 +79,7 @@ class TLS_Server final : public Command
const std::string server_key = get_arg("key");
const int port = get_arg_sz("port");
const std::string transport = get_arg("type");
+ const std::string dump_traces_to = get_arg("dump-traces");
if(transport != "tcp" && transport != "udp")
{
@@ -179,6 +181,16 @@ class TLS_Server final : public Command
protocol_chooser,
!is_tcp);
+ std::unique_ptr<std::ostream> dump_stream;
+
+ if(!dump_traces_to.empty())
+ {
+ uint64_t timestamp = Botan::OS::get_high_resolution_clock();
+ const std::string dump_file =
+ dump_traces_to + "/tls_" + std::to_string(timestamp) + ".bin";
+ dump_stream.reset(new std::ofstream(dump_file.c_str()));
+ }
+
try
{
while(!server.is_closed())
@@ -188,6 +200,11 @@ class TLS_Server final : public Command
uint8_t buf[4 * 1024] = { 0 };
ssize_t got = ::read(fd, buf, sizeof(buf));
+ if(dump_stream)
+ {
+ dump_stream->write(reinterpret_cast<const char*>(buf), got);
+ }
+
if(got == -1)
{
error_output() << "Error in socket read - " << strerror(errno) << std::endl;