OpenSSL thread safe secure connections

Time ago I wrote some articles to explain, with simple examples, the use of OpenSSL API s for file encryption:

Now, in this article, I’ll show how to add secure thread safe connections to your software using OpenSSL .

As reported by official FAQs, Multi-threaded applications must provide two callback functions to OpenSSL by calling CRYPTO_set_locking_callback() and CRYPTO_set_id_callback() . The library below, sslc ( Secure Sockets Layer Connections ) , sets up this two callbacks and offers two functions to the application to handle secure connections : open_sslc and close_sslc .

Version: 0.1

Changelog: initial release

OpenSSL Thread Safe Secure Connections source code

Here is an example of usage of the above library :

int main() {
    struct hostent *he;
    SSL *ssl;    if(!(he = gethostbyname("mail.example.com"))) {
        fprintf(stderr, "Error: failed gethostbyname(localhost)\n");
        exit(EXIT_FAILURE);
    }
 
    ssl = open_pop3s(he, 995, "username", "password");
    close_pop3s(ssl);
}

:-)

Simple enough?

3 Comments OpenSSL thread safe secure connections

  1. Amir

    Hi Paolo,
    Thank you for the sample code. but It’s the first time dealing with cryptography.
    I would appreciate if you can recommend me a book that explain from beginig , how to set up an SSL Server, what libraries are needed and sample codes that show how to deal with OpenSSL library.
    BTW, I am doing programming under Linux Suse 10.2

    Thanks again Paolo,

    Amir

  2. orit

    Hi Paolo,
    Thanks for the source code! :)
    But your example uses open_pop3s function and not open_sslc function from the source code.
    Can you please send an example that use the API of the library sslc?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>