More helpful error message for failure to create an SSL context
[hcoop/domtool2.git] / src / main.sml
index aca57ed..e106823 100644 (file)
@@ -170,6 +170,12 @@ val dispatcher =
 val self =
     "localhost:" ^ Int.toString Config.slavePort
 
+fun context x =
+    (OpenSSL.context false x)
+    handle e as OpenSSL.OpenSSL _ =>
+          (print "Couldn't find your certificate.\nYou probably haven't been given any Domtool privileges.\n";
+           raise e)
+
 fun requestContext f =
     let
        val user =
@@ -187,9 +193,9 @@ fun requestContext f =
                 
        val () = f ()
 
-       val context = OpenSSL.context (Config.certDir ^ "/" ^ user ^ ".pem",
-                                      Config.keyDir ^ "/" ^ user ^ "/key.pem",
-                                      Config.trustStore)
+       val context = context (Config.certDir ^ "/" ^ user ^ ".pem",
+                              Config.keyDir ^ "/" ^ user ^ "/key.pem",
+                              Config.trustStore)
     in
        (user, context)
     end
@@ -897,9 +903,9 @@ fun service () =
     let
        val () = Acl.read Config.aclFile
        
-       val context = OpenSSL.context (Config.serverCert,
-                                      Config.serverKey,
-                                      Config.trustStore)
+       val context = context (Config.serverCert,
+                              Config.serverKey,
+                              Config.trustStore)
        val _ = Domain.set_context context
 
        val sock = OpenSSL.listen (context, Config.dispatcherPort)
@@ -1282,9 +1288,9 @@ fun slave () =
     let
        val host = Slave.hostname ()
 
-       val context = OpenSSL.context (Config.certDir ^ "/" ^ host ^ ".pem",
-                                      Config.keyDir ^ "/" ^ host ^ "/key.pem",
-                                      Config.trustStore)
+       val context = context (Config.certDir ^ "/" ^ host ^ ".pem",
+                              Config.keyDir ^ "/" ^ host ^ "/key.pem",
+                              Config.trustStore)
 
        val sock = OpenSSL.listen (context, Config.slavePort)