BVB Source Codes

uWebSockets Show Networking.cpp Source code

Return Download uWebSockets: download Networking.cpp Source code - Download uWebSockets Source code - Type:.cpp
  1. #include "Networking.h"
  2.  
  3. namespace uS {
  4.  
  5. namespace TLS {
  6.  
  7. Context::Context(const Context &other)
  8. {
  9.     if (other.context) {
  10.         context = other.context;
  11.         SSL_CTX_up_ref(context);
  12.     }
  13. }
  14.  
  15. Context &Context::operator=(const Context &other) {
  16.     if (other.context) {
  17.         context = other.context;
  18.         SSL_CTX_up_ref(context);
  19.     }
  20.     return *this;
  21. }
  22.  
  23. Context::~Context()
  24. {
  25.     if (context) {
  26.         SSL_CTX_free(context);
  27.     }
  28. }
  29.  
  30. struct Init {
  31.     Init() {SSL_library_init();}
  32.     ~Init() {/*EVP_cleanup();*/}
  33. } init;
  34.  
  35. Context createContext(std::string certChainFileName, std::string keyFileName, std::string keyFilePassword)
  36. {
  37.     Context context(SSL_CTX_new(SSLv23_server_method()));
  38.     if (!context.context) {
  39.         return nullptr;
  40.     }
  41.  
  42.     if (keyFilePassword.length()) {
  43.         context.password.reset(new std::string(keyFilePassword));
  44.         SSL_CTX_set_default_passwd_cb_userdata(context.context, context.password.get());
  45.         SSL_CTX_set_default_passwd_cb(context.context, Context::passwordCallback);
  46.     }
  47.  
  48.     SSL_CTX_set_options(context.context, SSL_OP_NO_SSLv3);
  49.  
  50.     if (SSL_CTX_use_certificate_chain_file(context.context, certChainFileName.c_str()) != 1) {
  51.         return nullptr;
  52.     } else if (SSL_CTX_use_PrivateKey_file(context.context, keyFileName.c_str(), SSL_FILETYPE_PEM) != 1) {
  53.         return nullptr;
  54.     }
  55.  
  56.     return context;
  57. }
  58.  
  59. }
  60.  
  61. #ifndef _WIN32
  62. struct Init {
  63.     Init() {signal(SIGPIPE, SIG_IGN);}
  64. } init;
  65. #endif
  66.  
  67. #ifdef _WIN32
  68. #pragma comment(lib, "Ws2_32.lib")
  69.  
  70. struct WindowsInit {
  71.     WSADATA wsaData;
  72.     WindowsInit() {WSAStartup(MAKEWORD(2, 2), &wsaData);}
  73.     ~WindowsInit() {WSACleanup();}
  74. } windowsInit;
  75.  
  76. #endif
  77.  
  78. }
  79.  
downloadNetworking.cpp Source code - Download uWebSockets Source code
Related Source Codes/Software:
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11

 Back to top