Esempio n. 1
0
int		main(int argc, char **argv)
{
  int		cfd;
  SSL_CTX	*ctx;
  SSL		*ssl;
  char		buf[4096];
  int		ret;

  SSL_library_init();
  SSL_load_error_strings();
  OPENSSL_no_config();
  //  cfd = create_connected_socket("localhost", "4242");
  cfd = create_connected_socket("::1", "4242");
  std::cout << cfd << std::endl;
  ctx = SSL_CTX_new(SSLv3_client_method());
  // if (SSL_CTX_use_certificate_file(ctx, "cert.pem", SSL_FILETYPE_PEM) != 1) {
  //   ERR_print_errors_fp(stderr);
  //   exit(EXIT_FAILURE);
  // }
  // if (SSL_CTX_use_PrivateKey_file(ctx, "localhost.key", SSL_FILETYPE_PEM) != 1 ) {
  //   ERR_print_errors_fp(stderr);
  //   exit(EXIT_FAILURE);
  // }
  ssl = SSL_new(ctx);
  if (ssl == NULL)
    exit(1);
  ret = SSL_set_fd(ssl, cfd);
  if (ret != 1)
    {
      ERR_print_errors_fp(stderr);
      std::cout << "SSL_sed_fd : " << SSL_get_error(ssl, ret) << std::endl;
    }
  ret = SSL_connect(ssl);
  if (ret != 1)
    {
      ERR_print_errors_fp(stderr);
      std::cout << "SSL_connect : " << SSL_get_error(ssl, ret) << std::endl;
    }
  SSL_write(ssl, "coucou", 6);
  ret = SSL_read(ssl, buf, 4096);
  write(1, buf, ret);
}
Esempio n. 2
0
    CInit()
    {
        // Init OpenSSL library multithreading support
        ppmutexOpenSSL.reset(new CCriticalSection[CRYPTO_num_locks()]);
        CRYPTO_set_locking_callback(locking_callback);

        // OpenSSL can optionally load a config file which lists optional loadable modules and engines.
        // We don't use them so we don't require the config. However some of our libs may call functions
        // which attempt to load the config file, possibly resulting in an exit() or crash if it is missing
        // or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
        // that the config appears to have been loaded and there are no modules/engines available.
        OPENSSL_no_config();

#ifdef WIN32
        // Seed OpenSSL PRNG with current contents of the screen
        RAND_screen();
#endif

        // Seed OpenSSL PRNG with performance counter
        RandAddSeed();
    }