- rename
[oweals/gnunet.git] / src / identity / gnunet-service-identity.c
index 95fb79c386f98da30e28845114c249baebb14bce..7d635c2912df655f95649c5980b2f265633ff6ef 100644 (file)
@@ -26,9 +26,9 @@
  * The purpose of this service is to manage private keys that
  * represent the various egos/pseudonyms/identities of a GNUnet user.
  *
- * TODO:
- * - disk operations
- * - default identity set/get handlers
+ * Todo:
+ * - auto-initialze default egos; maybe trigger default
+ *   initializations (such as gnunet-gns-import.sh?)
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -47,18 +47,18 @@ struct Ego
 
   /**
    * We keep egos in a DLL.
-   */ 
+   */
   struct Ego *next;
 
   /**
    * We keep egos in a DLL.
-   */ 
+   */
   struct Ego *prev;
 
   /**
    * Private key of the ego.
    */
-  struct GNUNET_CRYPTO_EccPrivateKey *pk;
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
 
   /**
    * String identifier for the ego.
@@ -110,6 +110,26 @@ static struct Ego *ego_head;
 static struct Ego *ego_tail;
 
 
+/**
+ * Get the name of the file we use to store a given ego.
+ *
+ * @param ego ego for which we need the filename
+ * @return full filename for the given ego
+ */
+static char *
+get_ego_filename (struct Ego *ego)
+{
+  char *filename;
+
+  GNUNET_asprintf (&filename,
+                  "%s%s%s",
+                  ego_directory,
+                  DIR_SEPARATOR_STR,
+                  ego->identifier);
+  return filename;
+}
+
+
 /**
  * Task run during shutdown.
  *
@@ -140,7 +160,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   while (NULL != (e = ego_head))
   {
     GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
-    GNUNET_CRYPTO_ecc_key_free (e->pk);
+    GNUNET_free (e->pk);
+    GNUNET_free (e->identifier);
     GNUNET_free (e);
   }
 }
@@ -169,8 +190,13 @@ send_result_code (struct GNUNET_SERVER_Client *client,
   rcm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
   rcm->header.size = htons (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen);
   rcm->result_code = htonl (result_code);
-  memcpy (&rcm[1], emsg, elen);
-  GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_YES);  
+  if (0 < elen)
+    memcpy (&rcm[1], emsg, elen);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Sending result %d (%s) to client\n",
+             (int) result_code,
+             emsg);
+  GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_NO);
   GNUNET_free (rcm);
 }
 
@@ -185,23 +211,16 @@ static struct GNUNET_IDENTITY_UpdateMessage *
 create_update_message (struct Ego *ego)
 {
   struct GNUNET_IDENTITY_UpdateMessage *um;
-  char *str;
-  uint16_t pk_len;
   size_t name_len;
-  struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
 
   name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
-  enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
-  pk_len = ntohs (enc->size);
-  um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
+  um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len);
   um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
-  um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
+  um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len);
   um->name_len = htons (name_len);
-  um->pk_len = htons (pk_len);
-  str = (char *) &um[1];
-  memcpy (str, enc, pk_len);
-  memcpy (&str[pk_len], ego->identifier, name_len);
-  GNUNET_free (enc);
+  um->end_of_list = htons (GNUNET_NO);
+  um->private_key = *ego->pk;
+  memcpy (&um[1], ego->identifier, name_len);
   return um;
 }
 
@@ -218,30 +237,23 @@ create_set_default_message (struct Ego *ego,
                            const char *servicename)
 {
   struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
-  char *str;
-  uint16_t pk_len;
   size_t name_len;
-  struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
 
   name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
-  enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
-  pk_len = ntohs (enc->size);
-  sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
+  sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len);
   sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
-  sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
+  sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len);
   sdm->name_len = htons (name_len);
-  sdm->pk_len = htons (pk_len);
-  str = (char *) &sdm[1];
-  memcpy (str, enc, pk_len);
-  memcpy (&str[pk_len], servicename, name_len);
-  GNUNET_free (enc);
+  sdm->reserved = htons (0);
+  sdm->private_key = *ego->pk;
+  memcpy (&sdm[1], servicename, name_len);
   return sdm;
 }
 
 
 /**
  * Handler for START message from client, sends information
- * about all identities to the client immediately and 
+ * about all identities to the client immediately and
  * adds the client to the notification context for future
  * updates.
  *
@@ -254,17 +266,24 @@ handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
                       const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_IDENTITY_UpdateMessage *um;
+  struct GNUNET_IDENTITY_UpdateMessage ume;
   struct Ego *ego;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received START message from client\n");
   GNUNET_SERVER_notification_context_add (nc, client);
   for (ego = ego_head; NULL != ego; ego = ego->next)
   {
     um = create_update_message (ego);
-    GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_YES);
+    GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_NO);
     GNUNET_free (um);
   }
+  memset (&ume, 0, sizeof (ume));
+  ume.header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
+  ume.header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage));
+  ume.end_of_list = htons (GNUNET_YES);
+  ume.name_len = htons (0);
+  GNUNET_SERVER_notification_context_unicast (nc, client, &ume.header, GNUNET_NO);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -289,8 +308,6 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
   const char *name;
   char *identifier;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-             "Received GET_DEFAULT message from client\n");
   size = ntohs (message->size);
   if (size <= sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
   {
@@ -309,15 +326,17 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Received GET_DEFAULT for service `%s' from client\n",
+             name);
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
                                             name,
                                             "DEFAULT_IDENTIFIER",
                                             &identifier))
   {
-    /* FIXME: not sure client API handles this case correctly right now... */
     send_result_code (client, 1, gettext_noop ("no default known"));
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);   
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   for (ego = ego_head; NULL != ego; ego = ego->next)
@@ -327,19 +346,39 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
     {
       sdm = create_set_default_message (ego,
                                        name);
-      GNUNET_SERVER_notification_context_broadcast (nc, &sdm->header, GNUNET_YES);
+      GNUNET_SERVER_notification_context_unicast (nc, client,
+                                                  &sdm->header, GNUNET_NO);
       GNUNET_free (sdm);
       GNUNET_SERVER_receive_done (client, GNUNET_OK);
+      GNUNET_free (identifier);
       return;
     }
   }
-  /* FIXME: not sure client API handles this case correctly right now... */
-  send_result_code (client, 1, 
+  GNUNET_free (identifier);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Failed to find ego `%s'\n",
+             name);
+  send_result_code (client, 1,
                    gettext_noop ("default configured, but ego unknown (internal error)"));
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
+/**
+ * Compare the given two private keys for equality.
+ *
+ * @param pk1 one private key
+ * @param pk2 another private key
+ * @return 0 if the keys are equal
+ */
+static int
+key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
+        const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
+{
+  return memcmp (pk1, pk2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
+}
+
+
 /**
  * Handler for SET_DEFAULT message from client, updates
  * default identity for some service.
@@ -352,12 +391,60 @@ static void
 handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
                            const struct GNUNET_MessageHeader *message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-             "Received SET_DEFAULT message from client\n");
-  // setup_estimate_message (&em);
-  // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
-  GNUNET_break (0); // not implemented!
-  GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+  const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
+  uint16_t size;
+  uint16_t name_len;
+  struct Ego *ego;
+  const char *str;
+
+  size = ntohs (message->size);
+  if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message;
+  name_len = ntohs (sdm->name_len);
+  GNUNET_break (0 == ntohs (sdm->reserved));
+  if (name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size)
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  str = (const char *) &sdm[1];
+  if ('\0' != str[name_len - 1])
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Received SET_DEFAULT for service `%s' from client\n",
+             str);
+  for (ego = ego_head; NULL != ego; ego = ego->next)
+  {
+    if (0 == key_cmp (ego->pk,
+                     &sdm->private_key))
+    {
+      GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
+                                            str,
+                                            "DEFAULT_IDENTIFIER",
+                                            ego->identifier);
+      if (GNUNET_OK !=
+         GNUNET_CONFIGURATION_write (subsystem_cfg,
+                                     subsystem_cfg_file))
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                   _("Failed to write subsystem default identifier map to `%s'.\n"),
+                   subsystem_cfg_file);
+      send_result_code (client, 0, NULL);
+      GNUNET_SERVER_receive_done (client, GNUNET_OK);
+      return;
+    }
+  }
+  send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -372,7 +459,7 @@ notify_listeners (struct Ego *ego)
   struct GNUNET_IDENTITY_UpdateMessage *um;
 
   um = create_update_message (ego);
-  GNUNET_SERVER_notification_context_broadcast (nc, &um->header, GNUNET_YES);
+  GNUNET_SERVER_notification_context_broadcast (nc, &um->header, GNUNET_NO);
   GNUNET_free (um);
 }
 
@@ -392,12 +479,11 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
   const struct GNUNET_IDENTITY_CreateRequestMessage *crm;
   uint16_t size;
   uint16_t name_len;
-  uint16_t pk_len;
   struct Ego *ego;
   const char *str;
-  struct GNUNET_CRYPTO_EccPrivateKey *pk;
+  char *fn;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received CREATE message from client\n");
   size = ntohs (message->size);
   if (size <= sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
@@ -408,16 +494,14 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
   }
   crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message;
   name_len = ntohs (crm->name_len);
-  pk_len = ntohs (crm->pk_len);
-  str = (const char *) &crm[1];
-  if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) ||
-       (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) )
+  GNUNET_break (0 == ntohs (crm->reserved));
+  if (name_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size)
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  str = &str[pk_len];
+  str = (const char *) &crm[1];
   if ('\0' != str[name_len - 1])
   {
     GNUNET_break (0);
@@ -431,23 +515,82 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
     {
       send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
       GNUNET_SERVER_receive_done (client, GNUNET_OK);
-      GNUNET_CRYPTO_ecc_key_free (pk);
       return;
     }
   }
   ego = GNUNET_new (struct Ego);
-  ego->pk = pk;
+  ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
+  *ego->pk = crm->private_key;
   ego->identifier = GNUNET_strdup (str);
   GNUNET_CONTAINER_DLL_insert (ego_head,
                               ego_tail,
                               ego);
   send_result_code (client, 0, NULL);
-  /* FIXME: also write to file! */
-  notify_listeners (ego);  
+  fn = get_ego_filename (ego);
+  (void) GNUNET_DISK_directory_create_for_file (fn);
+  if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
+      GNUNET_DISK_fn_write (fn,
+                           &crm->private_key,
+                           sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
+                           GNUNET_DISK_PERM_USER_READ |
+                           GNUNET_DISK_PERM_USER_WRITE))
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                             "write", fn);
+  GNUNET_free (fn);
+  notify_listeners (ego);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
+/**
+ * Closure for 'handle_ego_rename'.
+ */
+struct RenameContext
+{
+  /**
+   * Old name.
+   */
+  const char *old_name;
+
+  /**
+   * New name.
+   */
+  const char *new_name;
+};
+
+
+/**
+ * An ego was renamed; rename it in all subsystems where it is
+ * currently set as the default.
+ *
+ * @param cls the 'struct RenameContext'
+ * @param section a section in the configuration to process
+ */
+static void
+handle_ego_rename (void *cls,
+                  const char *section)
+{
+  struct RenameContext *rc = cls;
+  char *id;
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+                                            section,
+                                            "DEFAULT_IDENTIFIER",
+                                            &id))
+    return;
+  if (0 != strcmp (id, rc->old_name))
+  {
+    GNUNET_free (id);
+    return;
+  }
+  GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
+                                        section,
+                                        "DEFAULT_IDENTIFIER",
+                                        rc->new_name);
+  GNUNET_free (id);
+}
+
 
 /**
  * Handler for RENAME message from client, creates
@@ -468,8 +611,11 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
   struct Ego *ego;
   const char *old_name;
   const char *new_name;
+  struct RenameContext rename_ctx;
+  char *fn_old;
+  char *fn_new;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received RENAME message from client\n");
   size = ntohs (message->size);
   if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage))
@@ -491,14 +637,44 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+
+  /* check if new name is already in use */
+  for (ego = ego_head; NULL != ego; ego = ego->next)
+  {
+    if (0 == strcmp (ego->identifier,
+                    new_name))
+    {
+      send_result_code (client, 1, gettext_noop ("target name already exists"));
+      GNUNET_SERVER_receive_done (client, GNUNET_OK);
+      return;
+    }
+  }
+
+  /* locate old name and, if found, perform rename */
   for (ego = ego_head; NULL != ego; ego = ego->next)
   {
     if (0 == strcmp (ego->identifier,
                     old_name))
     {
+      fn_old = get_ego_filename (ego);
       GNUNET_free (ego->identifier);
+      rename_ctx.old_name = old_name;
+      rename_ctx.new_name = new_name;
+      GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
+                                            &handle_ego_rename,
+                                            &rename_ctx);
+      if (GNUNET_OK !=
+         GNUNET_CONFIGURATION_write (subsystem_cfg,
+                                     subsystem_cfg_file))
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                   _("Failed to write subsystem default identifier map to `%s'.\n"),
+                   subsystem_cfg_file);
       ego->identifier = GNUNET_strdup (new_name);
-      /* FIXME: also rename file! */
+      fn_new = get_ego_filename (ego);
+      if (0 != RENAME (fn_old, fn_new))
+       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
+      GNUNET_free (fn_old);
+      GNUNET_free (fn_new);
       notify_listeners (ego);
       send_result_code (client, 0, NULL);
       GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -506,11 +682,45 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
     }
   }
 
+  /* failed to locate old name */
   send_result_code (client, 1, gettext_noop ("no matching ego found"));
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
+/**
+ * An ego was removed, remove it from all subsystems where it is
+ * currently set as the default.
+ *
+ * @param cls name of the removed ego (const char *)
+ * @param section a section in the configuration to process
+ */
+static void
+handle_ego_delete (void *cls,
+                  const char *section)
+{
+  const char *identifier = cls;
+  char *id;
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+                                            section,
+                                            "DEFAULT_IDENTIFIER",
+                                            &id))
+    return;
+  if (0 != strcmp (id, identifier))
+  {
+    GNUNET_free (id);
+    return;
+  }
+  GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
+                                        section,
+                                        "DEFAULT_IDENTIFIER",
+                                        NULL);
+  GNUNET_free (id);
+}
+
+
 /**
  * Handler for DELETE message from client, creates
  * new identity.
@@ -528,8 +738,9 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
   uint16_t name_len;
   struct Ego *ego;
   const char *name;
+  char *fn;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received DELETE message from client\n");
   size = ntohs (message->size);
   if (size <= sizeof (struct GNUNET_IDENTITY_DeleteMessage))
@@ -557,11 +768,23 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
       GNUNET_CONTAINER_DLL_remove (ego_head,
                                   ego_tail,
                                   ego);
-      /* FIXME: also delete file! */
+      GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
+                                            &handle_ego_delete,
+                                            ego->identifier);
+      if (GNUNET_OK !=
+         GNUNET_CONFIGURATION_write (subsystem_cfg,
+                                     subsystem_cfg_file))
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                   _("Failed to write subsystem default identifier map to `%s'.\n"),
+                   subsystem_cfg_file);
+      fn = get_ego_filename (ego);
+      if (0 != UNLINK (fn))
+       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
+      GNUNET_free (fn);
       GNUNET_free (ego->identifier);
       ego->identifier = NULL;
       notify_listeners (ego);
-      GNUNET_CRYPTO_ecc_key_free (ego->pk);
+      GNUNET_free (ego->pk);
       GNUNET_free (ego);
       send_result_code (client, 0, NULL);
       GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -580,15 +803,40 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
  *
  * @param cls NULL
  * @param filename name of the file to parse
- * @return GNUNET_OK to continue to iterate,
- *  GNUNET_NO to stop iteration with no error,
- *  GNUNET_SYSERR to abort iteration with error!
+ * @return #GNUNET_OK to continue to iterate,
+ *  #GNUNET_NO to stop iteration with no error,
+ *  #GNUNET_SYSERR to abort iteration with error!
  */
 static int
 process_ego_file (void *cls,
                  const char *filename)
 {
-  GNUNET_break (0); // not implemented
+  struct Ego *ego;
+  const char *fn;
+
+  fn = strrchr (filename, (int) DIR_SEPARATOR);
+  if (NULL == fn)
+  {
+    GNUNET_break (0);
+    return GNUNET_OK;
+  }
+  ego = GNUNET_new (struct Ego);
+  ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename);
+  if (NULL == ego->pk)
+  {
+    GNUNET_free (ego);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                _("Failed to parse ego information in `%s'\n"),
+                filename);
+    return GNUNET_OK;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Loaded ego `%s'\n",
+             fn + 1);
+  ego->identifier = GNUNET_strdup (fn + 1);
+  GNUNET_CONTAINER_DLL_insert (ego_head,
+                              ego_tail,
+                              ego);
   return GNUNET_OK;
 }
 
@@ -601,7 +849,7 @@ process_ego_file (void *cls,
  * @param c configuration to use
  */
 static void
-run (void *cls, 
+run (void *cls,
      struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
@@ -640,10 +888,13 @@ run (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Loading subsystem configuration `%s'\n",
+             subsystem_cfg_file);
   subsystem_cfg = GNUNET_CONFIGURATION_create ();
   if ( (GNUNET_YES ==
        GNUNET_DISK_file_test (subsystem_cfg_file)) &&
-       (GNUNET_OK != 
+       (GNUNET_OK !=
        GNUNET_CONFIGURATION_parse (subsystem_cfg,
                                    subsystem_cfg_file)) )
   {
@@ -656,6 +907,13 @@ run (void *cls,
   stats = GNUNET_STATISTICS_create ("identity", cfg);
   GNUNET_SERVER_add_handlers (server, handlers);
   nc = GNUNET_SERVER_notification_context_create (server, 1);
+  if (GNUNET_OK !=
+      GNUNET_DISK_directory_create (ego_directory))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("Failed to create directory `%s' for storing egos\n"),
+               ego_directory);
+  }
   GNUNET_DISK_directory_scan (ego_directory,
                              &process_ego_file,
                              NULL);
@@ -675,7 +933,7 @@ int
 main (int argc, char *const *argv)
 {
   return (GNUNET_OK ==
-          GNUNET_SERVICE_run (argc, argv, "identity", 
+          GNUNET_SERVICE_run (argc, argv, "identity",
                              GNUNET_SERVICE_OPTION_NONE,
                               &run, NULL)) ? 0 : 1;
 }