Check private key file permissions before starting server.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 9 Mar 2003 15:09:20 +0000 (15:09 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 9 Mar 2003 15:09:20 +0000 (15:09 +0000)
CHANGES
apps/silcd/serverconfig.c

diff --git a/CHANGES b/CHANGES
index 28ac4aa3125fa88e65049f7b1bcfdb39995a2b67..9aba09233780e74df0f797e9846b164f4a451e3a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,9 @@ Sun Mar  9 16:29:20 EET 2003  Pekka Riikonen <priikone@silcnet.org>
          files are lib/silcclient/client.c and 
          irssi/src/silc/core/client_ops.c.
 
+       * Check server private key file permissions before starting
+         the server.  Affected file silcd/serverconfig.c.
+
 Tue Feb  4 22:53:26 EET 2003  Pekka Riikonen <priikone@silcnet.org>
 
        * NULL terminate allocated string in silc_buffer_strformat.
index 2121264101e7665917e15b7519a0166af7f7642a..e6da9f20ed1bb2d98bdd62c97427a8a42d9dbe5c 100644 (file)
@@ -460,7 +460,7 @@ SILC_CONFIG_CALLBACK(fetch_pkcs)
   SERVER_CONFIG_DEBUG(("Received PKCS type=%d name=\"%s\" (val=%x)",
                       type, name, context));
   if (type == SILC_CONFIG_ARG_BLOCK) {
-    /* check the temporary struct's fields */
+    /* Check the temporary struct's fields */
     if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
     if (!tmp->name) {
@@ -498,7 +498,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
   SERVER_CONFIG_DEBUG(("Received SERVERINFO type=%d name=\"%s\" (val=%x)",
                       type, name, context));
 
-  /* if there isn't the main struct alloc it */
+  /* If there isn't the main struct alloc it */
   if (!server_info)
     config->server_info = server_info = (SilcServerConfigServerInfo *)
                silc_calloc(1, sizeof(*server_info));
@@ -594,7 +594,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
     char *file_tmp = (char *) val;
     CONFIG_IS_DOUBLE(server_info->public_key);
 
-    /* try to load specified file, if fail stop config parsing */
+    /* Try to load specified file, if fail stop config parsing */
     if (!silc_pkcs_load_public_key(file_tmp, &server_info->public_key,
                                   SILC_PKCS_FILE_PEM))
       if (!silc_pkcs_load_public_key(file_tmp, &server_info->public_key,
@@ -604,10 +604,21 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
       }
   }
   else if (!strcmp(name, "privatekey")) {
+    struct stat st;
     char *file_tmp = (char *) val;
     CONFIG_IS_DOUBLE(server_info->private_key);
 
-    /* try to load specified file, if fail stop config parsing */
+    /* Check the private key file permissions. */
+    if ((stat(file_tmp, &st)) != -1) {
+      if ((st.st_mode & 0777) != 0600) {
+       SILC_SERVER_LOG_ERROR(("Wrong permissions in private key "
+                             "file \"%s\".  The permissions must be "
+                             "0600.", file_tmp));
+        return SILC_CONFIG_ESILENT;
+      }
+    }
+
+    /* Try to load specified file, if fail stop config parsing */
     if (!silc_pkcs_load_private_key(file_tmp, &server_info->private_key,
                                    "", 0, SILC_PKCS_FILE_BIN))
       if (!silc_pkcs_load_private_key(file_tmp, &server_info->private_key,
@@ -621,7 +632,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
   return SILC_CONFIG_OK;
 
  got_err:
-  /* here we need to check if tmp exists because this function handles
+  /* Here we need to check if tmp exists because this function handles
    * misc data (multiple fields and single-only fields) */
   if (tmp) {
     silc_free(tmp->server_ip);