summaryrefslogtreecommitdiff
path: root/sockets.c
diff options
context:
space:
mode:
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);
+ }
+}