Reader small image

You're reading from  Hands-On Network Programming with C

Product typeBook
Published inMay 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789349863
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Lewis Van Winkle
Lewis Van Winkle
author image
Lewis Van Winkle

Lewis Van Winkle is a software programming consultant, entrepreneur, and founder of a successful IoT company. He has over 20 years of programming experience after publishing his first successful software product at age 12. He has over 15 years of programming experience with the C programming language on a variety of operating systems and platforms. He is active in the open-source community and has published several popular open-source programs and librariesmany of them in C. Today, Lewis spends much of his time consulting, where he loves taking on difficult projects that other programmers have given up on. He specializes in network systems, financial systems, machine learning, and interoperation between different programming languages.
Read more about Lewis Van Winkle

Right arrow

HTTPS server with OpenSSL


Let's go over some basics of using the OpenSSL library in server applications before beginning a concrete example.

Before OpenSSL can be used, it must be initialized. The following code initializes the OpenSSL library, loads the requisite encryption algorithms, and loads useful error strings:

SSL_library_init();
OpenSSL_add_all_algorithms();
SSL_load_error_strings();

Refer to the previous Chapter 9, Loading Secure Web Pages with HTTPS and OpenSSL, for more information.

Our server also needs to create an SSL context object. This object works as a sort of factory from which we can create TLS/SSL connections.

The following code creates the SSL_CTX object:

SSL_CTX *ctx = SSL_CTX_new(TLS_server_method());
if (!ctx) {
    fprintf(stderr, "SSL_CTX_new() failed.\n");
    return 1;
}

If you're using an older version of OpenSSL, you may need to replace TLS_server_method() with TLSv1_2_server_method() in the preceding code. However, a better solution is to upgrade to a newer OpenSSL...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On Network Programming with C
Published in: May 2019Publisher: PacktISBN-13: 9781789349863

Author (1)

author image
Lewis Van Winkle

Lewis Van Winkle is a software programming consultant, entrepreneur, and founder of a successful IoT company. He has over 20 years of programming experience after publishing his first successful software product at age 12. He has over 15 years of programming experience with the C programming language on a variety of operating systems and platforms. He is active in the open-source community and has published several popular open-source programs and librariesmany of them in C. Today, Lewis spends much of his time consulting, where he loves taking on difficult projects that other programmers have given up on. He specializes in network systems, financial systems, machine learning, and interoperation between different programming languages.
Read more about Lewis Van Winkle