From 67fdec20726e48ba3a934cb25bb30d47ec4a4f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20De=20La=20Pe=C3=B1a=20Smirnov?= Date: Wed, 29 Nov 2017 11:44:34 +0300 Subject: Initial commit, version 0.5.3 --- node_modules/uws/src/Networking.cpp | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 node_modules/uws/src/Networking.cpp (limited to 'node_modules/uws/src/Networking.cpp') diff --git a/node_modules/uws/src/Networking.cpp b/node_modules/uws/src/Networking.cpp new file mode 100644 index 0000000..743f83b --- /dev/null +++ b/node_modules/uws/src/Networking.cpp @@ -0,0 +1,78 @@ +#include "Networking.h" + +namespace uS { + +namespace TLS { + +Context::Context(const Context &other) +{ + if (other.context) { + context = other.context; + SSL_CTX_up_ref(context); + } +} + +Context &Context::operator=(const Context &other) { + if (other.context) { + context = other.context; + SSL_CTX_up_ref(context); + } + return *this; +} + +Context::~Context() +{ + if (context) { + SSL_CTX_free(context); + } +} + +struct Init { + Init() {SSL_library_init();} + ~Init() {/*EVP_cleanup();*/} +} init; + +Context createContext(std::string certChainFileName, std::string keyFileName, std::string keyFilePassword) +{ + Context context(SSL_CTX_new(SSLv23_server_method())); + if (!context.context) { + return nullptr; + } + + if (keyFilePassword.length()) { + context.password.reset(new std::string(keyFilePassword)); + SSL_CTX_set_default_passwd_cb_userdata(context.context, context.password.get()); + SSL_CTX_set_default_passwd_cb(context.context, Context::passwordCallback); + } + + SSL_CTX_set_options(context.context, SSL_OP_NO_SSLv3); + + if (SSL_CTX_use_certificate_chain_file(context.context, certChainFileName.c_str()) != 1) { + return nullptr; + } else if (SSL_CTX_use_PrivateKey_file(context.context, keyFileName.c_str(), SSL_FILETYPE_PEM) != 1) { + return nullptr; + } + + return context; +} + +} + +#ifndef _WIN32 +struct Init { + Init() {signal(SIGPIPE, SIG_IGN);} +} init; +#endif + +#ifdef _WIN32 +#pragma comment(lib, "Ws2_32.lib") + +struct WindowsInit { + WSADATA wsaData; + WindowsInit() {WSAStartup(MAKEWORD(2, 2), &wsaData);} + ~WindowsInit() {WSACleanup();} +} windowsInit; + +#endif + +} -- cgit v1.2.3