1

I want to enable multithreading in openssl s_client. Basically, I want to run, say 5 different handshakes on 5 different threads when i run the s_client program.

Currently, this is how I'm going about it.

$ apps/openssl s_client -connect <host>:<port> -multithread

So, I take in a switch called -multithread and set it to true in apps/s_client.c if multithreading needs to be enabled.

Now, the request and handshake is taken care of in lines 1005 to 1923 in this program. So, I create an inner function from 1005 to 1923, and try running that function in a different thread.

That is,

int function_handshake()
{
    OpenSSL_add_ssl_algorithms();
    SSL_load_error_strings();
    ....
    ....
    apps_shutdown();
    OPENSSL_EXIT(ret);
}

This is a function inside a function(the parent function being main) After this function, I run this for loop to create a certain number_of_threads.

  for(current_thread_count=0; current_thread_count < number_of_threads; current_thread_count++)
     {
           init_locks();
           thread_error = pthread_create(&(tid[current_thread_count]), NULL, function_handshake, NULL);
           if(thread_error!=0)
           {
                printf("Can't create thread, [%s]\n", strerror(thread_error));
                goto end;
           }
           printf("----------thread created------------\n\n");
           thread_error = pthread_join(tid[current_thread_count], NULL);
           if(thread_error!=0)
           {
                printf("Can't join thread, [%s]\n", strerror(thread_error));
                goto end;
           }
           kill_locks();
    }

The init_locks() and kill_locks() functions are got from here

When I try running this program, it works fine in one iteration - The first handshake is successful. However, I run into memory errors and segmentation faults in the second handshake.

Please let me know what is wrong, or if there's any better / other way to do multithreading in the openssl s_client.

Community
  • 1
  • 1
Randomly Named User
  • 1,889
  • 7
  • 27
  • 47
  • You must call `init_locks()` only once in your program, i.e. before launching your threads. Similarly, call `kill_locks()` only once (after you've joined if joinable threads) at termination. – Zaxter Mar 07 '16 at 17:16

0 Answers0