document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <openssl/err.h>
  2. #include <openssl/ssl.h>
  3. #include <openssl/rand.h>
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. __attribute__((constructor)) void construct_ssl()
  12. {
  13.     SSL_load_error_strings();
  14.     SSL_library_init();
  15.     OpenSSL_add_all_algorithms();
  16. }
  17.  
  18. __attribute__((destructor)) void destruct_ssl()
  19. {
  20.     ERR_free_strings();
  21.     EVP_cleanup();
  22. }
  23.  
  24.  int main(int argc, char *argv[])
  25.  {
  26.  BIO *acc, *client;
  27.  SSL *ssl;
  28.  SSL_CTX *ctx;
  29.  
  30. // init_OpenSSL();
  31. // seed_prng();
  32.  
  33.     ctx = SSL_CTX_new( TLSv1_server_method());
  34. //  tlsctx = SSL_CTX_new( SSLv3_server_method() );
  35.     SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
  36.     SSL_CTX_use_certificate_file(ctx, "server.crt" , SSL_FILETYPE_PEM);
  37.     SSL_CTX_use_PrivateKey_file(ctx, "server.key", SSL_FILETYPE_PEM);
  38.  
  39. // ctx = setup_server_ctx();
  40.  
  41.  acc = BIO_new_accept("12120");
  42.  if (!acc)
  43.  cout << "Error creating server socket\\n";
  44.  
  45. // if (BIO_do_accept(acc) <= 0)
  46. // cout << "Error binding server socket\\n";
  47.  
  48.  for (;;)
  49.  {
  50.  if (BIO_do_accept(acc) <= 0)
  51.  cout << "Error accepting connection\\n";
  52.  
  53.  client = BIO_pop(acc);
  54.  if (!(ssl = SSL_new(ctx)))
  55.  cout << "Error creating SSL context\\n";
  56.  SSL_set_accept_state(ssl);
  57.  SSL_set_bio(ssl, client, client);
  58.  
  59.  if (SSL_accept(ssl) <= 0)
  60.  cout << "Error accepting SSL connection\\n";
  61.  }
  62.  
  63.  SSL_CTX_free(ctx);
  64.  BIO_free(acc);
  65.  return 0;
  66.  }
');