summaryrefslogtreecommitdiff
path: root/sockets.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-12 00:42:57 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-12 00:42:57 +0100
commit01c0e36bb3f6c8345d4a94b157b68a0c0f4c85cf (patch)
tree6d71e15784e052380de8747430e5fb0702db73aa /sockets.c
parent34d410dc82e05f4255ec23a9deaff212b7903955 (diff)
Implement TLS using OpenSSL.
Diffstat (limited to 'sockets.c')
-rw-r--r--sockets.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/sockets.c b/sockets.c
index 40079c2..142be21 100644
--- a/sockets.c
+++ b/sockets.c
@@ -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);
+ }
+}