diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-12 00:42:57 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-12 00:42:57 +0100 |
commit | 01c0e36bb3f6c8345d4a94b157b68a0c0f4c85cf (patch) | |
tree | 6d71e15784e052380de8747430e5fb0702db73aa /sockets.c | |
parent | 34d410dc82e05f4255ec23a9deaff212b7903955 (diff) |
Implement TLS using OpenSSL.
Diffstat (limited to 'sockets.c')
-rw-r--r-- | sockets.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -126,3 +126,44 @@ int createclientsocket(char *listenport) { return listener; } + +void init_openssl() { + SSL_load_error_strings(); + OpenSSL_add_ssl_algorithms(); +} + + +void cleanup_openssl() { + EVP_cleanup(); +} + +SSL_CTX *create_context() { + const SSL_METHOD *method; + SSL_CTX *ctx; + + method = SSLv23_server_method(); + + ctx = SSL_CTX_new(method); + if (!ctx) { + perror("Unable to create SSL context"); + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } + + return ctx; +} + +void configure_context(SSL_CTX *ctx) { + SSL_CTX_set_ecdh_auto(ctx, 1); + + /* Set the key and cert */ + if (SSL_CTX_use_certificate_file(ctx, "cert.pem", SSL_FILETYPE_PEM) <= 0) { + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } + + if (SSL_CTX_use_PrivateKey_file(ctx, "key.pem", SSL_FILETYPE_PEM) <= 0 ) { + ERR_print_errors_fp(stderr); + exit(EXIT_FAILURE); + } +} |