[or-cvs] Check directory signatures based on name of signer, not on ...

Nick Mathewson nickm at seul.org
Wed Jun 2 20:00:59 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv26683/src/or

Modified Files:
	directory.c or.h routerlist.c routerparse.c 
Log Message:
Check directory signatures based on name of signer, not on whom we got the directory from.

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- directory.c	2 Jun 2004 19:44:41 -0000	1.107
+++ directory.c	2 Jun 2004 20:00:57 -0000	1.108
@@ -336,7 +336,7 @@
         connection_mark_for_close(conn);
         return -1;
       }
-      if(router_load_routerlist_from_directory(body, conn->identity_pkey) < 0){
+      if(router_load_routerlist_from_directory(body, NULL) < 0){
         log_fn(LOG_INFO,"...but parsing failed. Ignoring.");
       } else {
         log_fn(LOG_INFO,"updated routers.");

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.362
retrieving revision 1.363
diff -u -d -r1.362 -r1.363
--- or.h	2 Jun 2004 19:44:41 -0000	1.362
+++ or.h	2 Jun 2004 20:00:57 -0000	1.363
@@ -578,6 +578,8 @@
    * published?
    */
   time_t published_on;
+  /** Which router is claimed to have signed it? */
+  char *signing_router;
 } routerlist_t;
 
 /** Holds accounting information for a single step in the layered encryption

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- routerlist.c	1 Jun 2004 18:19:01 -0000	1.83
+++ routerlist.c	2 Jun 2004 20:00:57 -0000	1.84
@@ -212,7 +212,8 @@
   routerinfo_t *router;
 
   tor_assert(nickname);
-  tor_assert(routerlist);
+  if (!routerlist)
+    return NULL;
 
   for(i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
@@ -446,9 +447,10 @@
 }
 
 /** Add to the current routerlist each router stored in the
- * signed directory <b>s</b>.  If pkey is provided, make sure that <b>s</b> is
- * signed with pkey. */
-int router_load_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey)
+ * signed directory <b>s</b>.  If pkey is provided, check the signature against
+ * pkey; else check against the pkey of the signing directory server. */
+int router_load_routerlist_from_directory(const char *s,
+                                          crypto_pk_env_t *pkey)
 {
   routerlist_t *new_list = NULL;
   check_software_version_against_directory(s, options.IgnoreVersion);

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerparse.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- routerparse.c	1 Jun 2004 18:19:01 -0000	1.4
+++ routerparse.c	2 Jun 2004 20:00:57 -0000	1.5
@@ -366,10 +366,27 @@
   }
 
   if (smartlist_len(tokens) != 1 ||
-   ((directory_token_t*)smartlist_get(tokens,0))->tp != K_DIRECTORY_SIGNATURE){
+      (!(tok=smartlist_get(tokens,0))) || /* always succeeds */
+      (tok->tp != K_DIRECTORY_SIGNATURE)) {
     log_fn(LOG_WARN,"Expected a single directory signature"); goto err;
   }
-  tok = smartlist_get(tokens,0);
+  if (tok->n_args == 1) {
+    routerinfo_t *r = router_get_by_nickname(tok->args[0]);
+    log_fn(LOG_DEBUG, "Got directory signed by %s", tok->args[0]);
+    if (r && r->is_trusted_dir) {
+      pkey = r->identity_pkey;
+    } else if (!r && pkey) {
+      /* pkey provided for debugging purposes. */
+    } else if (!r) {
+      log_fn(LOG_WARN, "Directory was signed by unrecognized server %s",
+             tok->args[0]);
+      goto err;
+    } else if (r && !r->is_trusted_dir) {
+      log_fn(LOG_WARN, "Directory was signed by non-trusted server %s",
+             tok->args[0]);
+      goto err;
+    }
+  }
   if (strcmp(tok->object_type, "SIGNATURE") || tok->object_size != 128) {
     log_fn(LOG_WARN, "Bad object type or length on directory signature");
     goto err;



More information about the tor-commits mailing list