2012年9月17日 星期一

Interesting things with openSSL programing.

    It's not hard to find a OpenSSL programming tutorial or some example code on the internet, but there are some interesting detail that is not mentioned in most of the articles online.
    A while ago, I was involved in a new project that gave me the chance to play with libSSL for a while, I did read some tutorials and studied some examples on the Internet; but when I was testing the actual source code, I found out that It was quite unstable; the software that I wrote acts unexpectedly as if It has its own mind and wound crash due to segmentation faults or memory violations unpredictably.
    After tracing the actual source code of the OpenSSL library, I figured out a few interesting things that I would like to share.
  1.  OpenSSL library could be build without multi-thread support; since most commercial software products are designed with multi-thread, please be sure to check if the library that you're using is build with multi-thread enabled.
  2. Even if you have enabled the multi-thread support, OpenSSL library is not thread safe right outside of the box, you have to implement two operations:
    1. first is a function that will return the current thread ID.
    2. the second is a function that will handle the mutex lock and unlock actuion.
  3. the two operation functions mentioned in the previous section should be introduced  to the OpenSSL library by using some provided APIs like:
    • CRYPTO_set_id_callback
    • CRYPTO_set_locking_callback
if you are looking for a example code you can download the openssl source code and checkout the demo code (crypto/threads/mttest.c), which comes with the  source.



沒有留言: