OpenSSL is a widely used open source library that provides SSL and TLS services to applications. We use it in this chapter for secure connections required by HTTPS.
OpenSSL can be challenging to install. Refer to Appendices B, Setting Up Your C Compiler on Windows, Appendices C, Setting Up Your C Compiler on Linux, and Appendices D, Setting Up Your C Compiler on macOS, for more information.
You can check whether you have the OpenSSL command-line tools installed by running the following command:
openssl version
The following screenshot shows this on Ubuntu Linux:
You'll also need to ensure that you have the OpenSSL library installed. The following program can be used to test this. If it compiles and runs successfully, then you do have the OpenSSL library installed and working:
/*openssl_version.c*/
#include <openssl/ssl.h>
int main(int argc, char *argv[]) {
printf("OpenSSL version: %s\n", OpenSSL_version(SSLEAY_VERSION));
return 0;
}
If you're using an older version of OpenSSL, you may need to replace the OpenSSL_version() function call with SSLeay_version() instead. However, a better solution is to just upgrade to a newer OpenSSL version.
The preceding openssl_version.c program is compiled on macOS and Linux using the following command:
gcc openssl_version.c -o openssl_version -lcrypto
./openssl_version
The following screenshot shows compiling and running openssl_version.c:
On Windows, openssl_version can be compiled using MinGW and the following commands:
gcc openssl_version.c -o openssl_version.exe -lcrypto
openssl_version.exe
Once the OpenSSL library is installed and usable, we are ready to begin using encrypted sockets.