aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/tls_client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/tls_client.cpp')
-rw-r--r--src/cli/tls_client.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/cli/tls_client.cpp b/src/cli/tls_client.cpp
index 642e60373..4625ca3f1 100644
--- a/src/cli/tls_client.cpp
+++ b/src/cli/tls_client.cpp
@@ -1,6 +1,7 @@
/*
* (C) 2014,2015 Jack Lloyd
* 2016 Matthias Gierlings
+* 2017 René Korthaus, Rohde & Schwarz Cybersecurity
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -21,6 +22,28 @@
#include <string>
#include <memory>
+#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+#include <winsock2.h>
+#include <WS2tcpip.h>
+
+int close(int fd)
+ {
+ return ::closesocket(fd);
+ }
+
+int read(int s, void* buf, size_t len)
+ {
+ return ::recv(s, reinterpret_cast<char*>(buf), static_cast<int>(len), 0);
+ }
+
+int send(int s, const uint8_t* buf, size_t len, int flags)
+ {
+ return ::send(s, reinterpret_cast<const char*>(buf), static_cast<int>(len), flags);
+ }
+
+#define STDIN_FILENO _fileno(stdin)
+typedef size_t ssize_t;
+#else
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
@@ -30,6 +53,7 @@
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
+#endif
#if !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
@@ -45,7 +69,31 @@ class TLS_Client final : public Command, public Botan::TLS::Callbacks
TLS_Client()
: Command("tls_client host --port=443 --print-certs --policy= "
"--tls1.0 --tls1.1 --tls1.2 "
- "--session-db= --session-db-pass= --next-protocols= --type=tcp") {}
+ "--session-db= --session-db-pass= --next-protocols= --type=tcp")
+ {
+#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+ WSAData wsa_data;
+ WORD wsa_version = MAKEWORD(2, 2);
+
+ if(::WSAStartup(wsa_version, &wsa_data) != 0)
+ {
+ throw CLI_Error("WSAStartup() failed: " + std::to_string(WSAGetLastError()));
+ }
+
+ if(LOBYTE(wsa_data.wVersion) != 2 || HIBYTE(wsa_data.wVersion) != 2)
+ {
+ ::WSACleanup();
+ throw CLI_Error("Could not find a usable version of Winsock.dll");
+ }
+#endif
+ }
+
+ ~TLS_Client()
+ {
+#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+ ::WSACleanup();
+#endif
+ }
void go() override
{
@@ -343,7 +391,7 @@ class TLS_Client final : public Command, public Botan::TLS::Callbacks
static void dgram_socket_write(int sockfd, const uint8_t buf[], size_t length)
{
- int r = send(sockfd, buf, length, MSG_NOSIGNAL);
+ int r = ::send(sockfd, buf, length, MSG_NOSIGNAL);
if(r == -1)
{