Added support for configuring certificate and key files.
[cascardo/rnetproxy.git] / popproxy.c
index f54c77c..a10b61b 100644 (file)
@@ -181,6 +181,8 @@ int main (int argc, char **argv)
   gchar *port;
   gchar *server_address;
   gchar *server_port;
+  gchar *certfile;
+  gchar *ssl_keyfile;
   struct pop_address pop_address;
 
   gnutls_global_init ();
@@ -211,6 +213,26 @@ int main (int argc, char **argv)
       exit (1);
     }
 
+  error = NULL;
+  certfile = g_key_file_get_string (keyfile, "global", "certfile",
+                                    &error);
+  if (certfile == NULL && error != NULL)
+    {
+      g_critical ("No certification file specified: %s.",
+                  error->message);
+      g_error_free (error);
+      exit (1);
+    }
+  error = NULL;
+  ssl_keyfile = g_key_file_get_string (keyfile, "global", "keyfile",
+                                       &error);
+  if (ssl_keyfile == NULL && error != NULL)
+    {
+      ssl_keyfile = g_strdup (certfile);
+      g_error_free (error);
+    }
+
+
   error = NULL;
   conf_address = g_key_file_get_string (keyfile, "global", "address",
                                         &error);
@@ -264,7 +286,10 @@ int main (int argc, char **argv)
   g_free (conf_address);
   g_free (port);
 
-  hc_conn_ssl_server_init_credentials ("cert.pem", "key.pem");
+  hc_conn_ssl_server_init_credentials (certfile, ssl_keyfile);
+
+  g_free (certfile);
+  g_free (ssl_keyfile);
 
   g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE));