-switching GNS from RSA to ECC
[oweals/gnunet.git] / src / gns / gnunet-service-gns.c
index dc22efdab82bc1c08e40492a834dbfaddfd69166..517722643a80f31b8cef9d25ff99d40ce881aff5 100644 (file)
@@ -116,17 +116,17 @@ struct ClientShortenHandle
   /** 
    * name to shorten
    */
-  char name[MAX_DNS_NAME_LENGTH];
+  char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
 
   /**
    * name of private zone (relative to root)
    */
-  char private_zone_id[MAX_DNS_NAME_LENGTH];
+  char private_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
   
   /**
    * name of shorten zone (relative to root)
    */
-  char shorten_zone_id[MAX_DNS_NAME_LENGTH];
+  char shorten_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
 
 };
 
@@ -168,7 +168,7 @@ struct ClientLookupHandle
   /**
    * optional zone private key used for shorten
    */
-  struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
+  struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
 
   /**
    * the name to look up
@@ -205,7 +205,7 @@ static struct GNUNET_DHT_Handle *dht_handle;
 /**
  * Our zone's private key
  */
-static struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
+static struct GNUNET_CRYPTO_EccPrivateKey *zone_key;
 
 /**
  * Our handle to the namestore service
@@ -306,7 +306,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct ClientShortenHandle *csh_tmp;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-             "Shutting down!");
+             "Shutting down!\n");
   while (NULL != (csh_tmp = csh_head))
   {
     GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp);
@@ -382,12 +382,12 @@ publish_zone_dht_start (void *cls,
  */
 static void
 put_gns_record (void *cls,
-                const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                 struct GNUNET_TIME_Absolute expiration,
                 const char *name,
                 unsigned int rd_count,
                 const struct GNUNET_NAMESTORE_RecordData *rd,
-                const struct GNUNET_CRYPTO_RsaSignature *signature)
+                const struct GNUNET_CRYPTO_EccSignature *signature)
 {  
   struct GNSNameRecordBlock *nrb;
   struct GNUNET_CRYPTO_ShortHashCode zhash;
@@ -475,7 +475,7 @@ put_gns_record (void *cls,
   nrb_data += namelen;
   rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
   GNUNET_CRYPTO_short_hash (key,
-                           sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                            &zhash);
   if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count,
                                                 rd,
@@ -626,12 +626,12 @@ send_shorten_response (void* cls, const char* name)
  */
 static void
 process_shorten_in_private_zone_lookup (void *cls,
-                                       const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                                       const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                                        struct GNUNET_TIME_Absolute expiration,
                                        const char *name,
                                        unsigned int rd_count,
                                        const struct GNUNET_NAMESTORE_RecordData *rd,
-                                       const struct GNUNET_CRYPTO_RsaSignature *signature)
+                                       const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ClientShortenHandle *csh = cls;
   struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
@@ -682,12 +682,12 @@ process_shorten_in_private_zone_lookup (void *cls,
  */
 static void
 process_shorten_in_root_zone_lookup (void *cls,
-                                    const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                                    const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                                     struct GNUNET_TIME_Absolute expiration,
                                     const char *name,
                                     unsigned int rd_count,
                                     const struct GNUNET_NAMESTORE_RecordData *rd,
-                                    const struct GNUNET_CRYPTO_RsaSignature *signature)
+                                    const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ClientShortenHandle *csh = cls;
   struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
@@ -738,12 +738,12 @@ process_shorten_in_root_zone_lookup (void *cls,
  */
 static void
 process_private_in_root_zone_lookup (void *cls,
-                                    const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                                    const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                                     struct GNUNET_TIME_Absolute expiration,
                                     const char *name,
                                     unsigned int rd_count,
                                     const struct GNUNET_NAMESTORE_RecordData *rd,
-                                    const struct GNUNET_CRYPTO_RsaSignature *signature)
+                                    const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ClientShortenHandle *csh = cls;
 
@@ -787,7 +787,7 @@ handle_shorten (void *cls,
 {
   struct ClientShortenHandle *csh;
   const char *utf_in;
-  char name[MAX_DNS_NAME_LENGTH];
+  char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
   char* nameptr = name;
   uint16_t msg_size;
   const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
@@ -815,7 +815,7 @@ handle_shorten (void *cls,
   GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); 
   GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "SHORTEN: Converted `%s' to `%s'\n", 
+            "SHORTEN: Converted `%s' to `%s'\n", 
             utf_in, 
             nameptr);
   GNUNET_SERVER_notification_context_add (nc, client);  
@@ -828,7 +828,7 @@ handle_shorten (void *cls,
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
-  if (strlen (name) > MAX_DNS_NAME_LENGTH) 
+  if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) 
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "SHORTEN: %s is too long\n", name);
@@ -837,7 +837,7 @@ handle_shorten (void *cls,
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }  
-  if ( (! is_gnunet_tld (name)) && 
+  if ( (! is_gads_tld (name)) && 
        (! is_zkey_tld (name)) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -922,7 +922,7 @@ handle_get_authority (void *cls,
 {
   struct ClientGetAuthHandle *cah;
   const char *utf_in;
-  char name[MAX_DNS_NAME_LENGTH];
+  char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
   char* nameptr = name;
   uint16_t msg_size;
   const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg;
@@ -957,7 +957,7 @@ handle_get_authority (void *cls,
     send_get_auth_response(cah, name);
     return;
   }  
-  if (strlen (name) > MAX_DNS_NAME_LENGTH) 
+  if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) 
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "GET_AUTH: `%s' is too long", name);
@@ -1036,7 +1036,7 @@ send_lookup_response (void* cls,
   GNUNET_free(clh->name);
   
   if (NULL != clh->shorten_key)
-    GNUNET_CRYPTO_rsa_key_free (clh->shorten_key);
+    GNUNET_CRYPTO_ecc_key_free (clh->shorten_key);
   GNUNET_free (clh);
   GNUNET_STATISTICS_update (statistics,
                             "Completed lookups", 1, GNUNET_NO);
@@ -1059,13 +1059,13 @@ handle_lookup (void *cls,
               const struct GNUNET_MessageHeader * message)
 {
   size_t namelen;
-  char name[MAX_DNS_NAME_LENGTH];
+  char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
   struct ClientLookupHandle *clh;
   char* nameptr = name;
   const char *utf_in;
   int only_cached;
-  struct GNUNET_CRYPTO_RsaPrivateKey *key;
-  struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey;
+  struct GNUNET_CRYPTO_EccPrivateKey *key;
+  struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkey;
   char* tmp_pkey;
   uint16_t msg_size;
   const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
@@ -1083,10 +1083,11 @@ handle_lookup (void *cls,
   GNUNET_SERVER_notification_context_add (nc, client);
   if (GNUNET_YES == ntohl (sh_msg->have_key))
   {
-    pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *) &sh_msg[1];
+    pkey = (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *) &sh_msg[1];
     tmp_pkey = (char*) &sh_msg[1];
-    key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs (pkey->len));
-    GNUNET_STRINGS_utf8_tolower (&tmp_pkey[ntohs (pkey->len)], &nameptr);
+    key = GNUNET_CRYPTO_ecc_decode_key (tmp_pkey, ntohs (pkey->size),
+                                       GNUNET_NO);
+    GNUNET_STRINGS_utf8_tolower (&tmp_pkey[ntohs (pkey->size)], &nameptr);
   }
   else
   {
@@ -1113,7 +1114,7 @@ handle_lookup (void *cls,
 
   only_cached = ntohl (sh_msg->only_cached);
   
-  if (strlen (name) > MAX_DNS_NAME_LENGTH) {
+  if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "LOOKUP: %s is too long", name);
     clh->name = NULL;
@@ -1142,7 +1143,7 @@ handle_lookup (void *cls,
   }
   
   if (1 == ntohl (sh_msg->use_default_zone))
-    clh->zone = zone_hash; //Default zone
+    clh->zone = zone_hash;  /* Default zone */
   else
     clh->zone = sh_msg->zone;
   
@@ -1184,7 +1185,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
   };
   char* keyfile;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
   unsigned long long max_parallel_bg_queries = 0;
   int ignore_pending = GNUNET_NO;
 
@@ -1203,10 +1204,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
              "Using keyfile %s for root zone.\n", keyfile);
 
-  zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
-  GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
+  zone_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
+  GNUNET_CRYPTO_ecc_key_get_public (zone_key, &pkey);
   GNUNET_CRYPTO_short_hash(&pkey,
-                     sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                     sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                      &zone_hash);
   GNUNET_free(keyfile);
   namestore_handle = GNUNET_NAMESTORE_connect (c);
@@ -1293,13 +1294,14 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   if (GNUNET_YES ==
       GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS"))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-               "DNS hijacking enabled... connecting to service.\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               "DNS hijacking enabled. Connecting to DNS service.\n");
 
-    if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR)
+    if (GNUNET_SYSERR ==
+       gns_interceptor_init (zone_hash, zone_key, c))
     {
       GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-               "Failed to enable the dns interceptor!\n");
+               "Failed to enable the DNS interceptor!\n");
     }
   }