gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21890 - in gnunet/src: gns include


From: gnunet
Subject: [GNUnet-SVN] r21890 - in gnunet/src: gns include
Date: Mon, 11 Jun 2012 16:59:04 +0200

Author: schanzen
Date: 2012-06-11 16:59:04 +0200 (Mon, 11 Jun 2012)
New Revision: 21890

Modified:
   gnunet/src/gns/gns.conf.in
   gnunet/src/gns/gns.h
   gnunet/src/gns/gns_api.c
   gnunet/src/gns/gnunet-gns-proxy.c
   gnunet/src/gns/gnunet-gns.c
   gnunet/src/gns/gnunet-service-gns.c
   gnunet/src/gns/test_gns_pseu_shorten.c
   gnunet/src/include/gnunet_gns_service.h
Log:
new API for shorten key

Modified: gnunet/src/gns/gns.conf.in
===================================================================
--- gnunet/src/gns/gns.conf.in  2012-06-11 13:56:55 UTC (rev 21889)
+++ gnunet/src/gns/gns.conf.in  2012-06-11 14:59:04 UTC (rev 21890)
@@ -8,6 +8,7 @@
 ZONEKEY = $SERVICEHOME/gns/zonekey.zkey
 HIJACK_DNS = NO
 AUTO_IMPORT_PKEY = YES
+AUTO_IMPORT_ZONEKEY = $SERVICEHOME/gns/shorten_zonekey.zkey
 AUTO_IMPORT_CONFIRMATION_REQ = NO
 MAX_PARALLEL_BACKGROUND_QUERIES = 25
 DEFAULT_LOOKUP_TIMEOUT = 10

Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h        2012-06-11 13:56:55 UTC (rev 21889)
+++ gnunet/src/gns/gns.h        2012-06-11 14:59:04 UTC (rev 21890)
@@ -63,6 +63,16 @@
   struct GNUNET_CRYPTO_ShortHashCode zone;
 
   /**
+   * Should we use a shorten zone?
+   */
+  uint32_t use_shorten_zone GNUNET_PACKED;
+
+  /**
+   * If use_shorten_zone is set use this zone for shortening
+   */
+  struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
+
+  /**
    * the type of record to look up
    */
   enum GNUNET_GNS_RecordType type;
@@ -120,7 +130,17 @@
    * If use_default_zone is empty this zone is used for lookup
    */
   struct GNUNET_CRYPTO_ShortHashCode zone;
+  
+  /**
+   * Should we use a shorten zone?
+   */
+  uint32_t use_shorten_zone GNUNET_PACKED;
 
+  /**
+   * If use_shorten_zone is set use this zone for shortening
+   */
+  struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
+  
   /* Followed by the name to shorten up */
 };
 

Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c    2012-06-11 13:56:55 UTC (rev 21889)
+++ gnunet/src/gns/gns_api.c    2012-06-11 14:59:04 UTC (rev 21890)
@@ -640,6 +640,7 @@
  * @param handle handle to the GNS service
  * @param name the name to look up
  * @param zone the zone to start the resolution in
+ * @param shorten_zone the zone where to shorten names into
  * @param type the record type to look up
  * @param proc processor to call on result
  * @param proc_cls closure for processor
@@ -649,6 +650,7 @@
 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
                    const char * name,
                    struct GNUNET_CRYPTO_ShortHashCode *zone,
+                   struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                    enum GNUNET_GNS_RecordType type,
                    GNUNET_GNS_LookupResultProcessor proc,
                    void *proc_cls)
@@ -695,7 +697,20 @@
     lookup_msg->use_default_zone = htonl(1);
     memset(&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
   }
-
+  
+  if (NULL != shorten_zone)
+  {
+    lookup_msg->use_shorten_zone = htonl(1);
+    memcpy(&lookup_msg->shorten_zone, shorten_zone,
+           sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+  }
+  else
+  {
+    lookup_msg->use_shorten_zone = htonl(0);
+    memset(&lookup_msg->shorten_zone, 0,
+           sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+  }
+  
   lookup_msg->type = htonl(type);
 
   memcpy(&lookup_msg[1], name, strlen(name));
@@ -724,7 +739,9 @@
                    GNUNET_GNS_LookupResultProcessor proc,
                    void *proc_cls)
 {
-  return GNUNET_GNS_lookup_zone (handle, name, NULL, type, proc, proc_cls);
+  return GNUNET_GNS_lookup_zone (handle, name,
+                                 NULL, NULL,
+                                 type, proc, proc_cls);
 }
 
 /**
@@ -733,6 +750,7 @@
  * @param handle handle to the GNS service
  * @param name the name to look up
  * @param zone the zone to start the resolution in
+ * @param shorten_zone the zone where to shorten names into
  * @param proc function to call on result
  * @param proc_cls closure for processor
  * @return handle to the operation
@@ -741,6 +759,7 @@
 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
                     const char * name,
                     struct GNUNET_CRYPTO_ShortHashCode *zone,
+                    struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                     GNUNET_GNS_ShortenResultProcessor proc,
                     void *proc_cls)
 {
@@ -787,7 +806,20 @@
     shorten_msg->use_default_zone = htonl(1);
     memset(&shorten_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
   }
-
+  
+  if (NULL != shorten_zone)
+  {
+    shorten_msg->use_shorten_zone = htonl(1);
+    memcpy(&shorten_msg->shorten_zone, shorten_zone,
+           sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+  }
+  else
+  {
+    shorten_msg->use_shorten_zone = htonl(0);
+    memset(&shorten_msg->shorten_zone, 0,
+           sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+  }
+  
   memcpy(&shorten_msg[1], name, strlen(name));
 
   GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
@@ -812,7 +844,7 @@
                     GNUNET_GNS_ShortenResultProcessor proc,
                     void *proc_cls)
 {
-  return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls);
+  return GNUNET_GNS_shorten_zone (handle, name, NULL, NULL, proc, proc_cls);
 }
 /**
  * Perform an authority lookup for a given name.

Modified: gnunet/src/gns/gnunet-gns-proxy.c
===================================================================
--- gnunet/src/gns/gnunet-gns-proxy.c   2012-06-11 13:56:55 UTC (rev 21889)
+++ gnunet/src/gns/gnunet-gns-proxy.c   2012-06-11 14:59:04 UTC (rev 21890)
@@ -269,12 +269,18 @@
 /* The users local GNS zone hash */
 static struct GNUNET_CRYPTO_ShortHashCode local_gns_zone;
 
+/* The users local shorten zone hash */
+static struct GNUNET_CRYPTO_ShortHashCode local_shorten_zone;
+
 /* The CA for SSL certificate generation */
 static struct ProxyCA proxy_ca;
 
 /* UNIX domain socket for mhd */
 struct GNUNET_NETWORK_Handle *mhd_unix_socket;
 
+/* Shorten names? */
+int use_shorten;
+
 /**
  * Checks if name is in tld
  *
@@ -1059,6 +1065,7 @@
   GNUNET_GNS_lookup_zone (gns_handle,
                           ctask->host,
                           &local_gns_zone,
+                          &local_shorten_zone,
                           GNUNET_GNS_RECORD_LEHO,
                           &process_leho_lookup,
                           ctask);
@@ -2254,8 +2261,58 @@
   return GNUNET_YES;
 }
 
+/**
+ * Loads the users local shorten zone key
+ *
+ * @return GNUNET_YES on success
+ */
+static int
+load_local_shorten_key (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  char *keyfile;
+  struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+  struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
+  struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
 
+  if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "gns",
+                                                "AUTO_IMPORT_PKEY"))
+  {
+    return GNUNET_NO;
+  }
 
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                          
"AUTO_IMPORT_ZONEKEY",
+                                                          &keyfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to load zone key config value!\n");
+    return GNUNET_NO;
+  }
+
+  if (GNUNET_NO == GNUNET_DISK_file_test (keyfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to load zone key!\n");
+    GNUNET_free(keyfile);
+    return GNUNET_NO;
+  }
+
+  key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+  GNUNET_CRYPTO_short_hash(&pkey,
+                           sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           &local_shorten_zone);
+  zone = &local_gns_zone;
+  GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using shorten zone: %s!\n", &zonename);
+  GNUNET_CRYPTO_rsa_key_free(key);
+  GNUNET_free(keyfile);
+
+  return GNUNET_YES;
+}
+
 /**
  * Main function that will be run
  *
@@ -2299,6 +2356,8 @@
     return;
   }
 
+  use_shorten = load_local_shorten_key (cfg);
+
   if (NULL == gns_handle)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2364,7 +2423,7 @@
                                                             &proxy_sockfile))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Specify PROXY_UNIX_SOCK in gns-proxy config section!\n");
+                "Specify PROXY_UNIXPATH in gns-proxy config section!\n");
     return;
   }
   

Modified: gnunet/src/gns/gnunet-gns.c
===================================================================
--- gnunet/src/gns/gnunet-gns.c 2012-06-11 13:56:55 UTC (rev 21889)
+++ gnunet/src/gns/gnunet-gns.c 2012-06-11 14:59:04 UTC (rev 21890)
@@ -149,6 +149,7 @@
   struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
   struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
+  struct GNUNET_CRYPTO_ShortHashCode *shorten_zone = NULL;
   struct GNUNET_CRYPTO_ShortHashCode user_zone;
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
 
@@ -178,7 +179,35 @@
     }
     GNUNET_free(keyfile);
   }
-
+  
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                          
"AUTO_IMPORT_ZONEKEY",
+                                                          &keyfile))
+  {
+    if (!raw)
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "No private key for shorten zone found!\n");
+    shorten_zone = NULL;
+  }
+  else
+  {
+    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
+    {
+      key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+      GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+      GNUNET_CRYPTO_short_hash(&pkey,
+                         sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                         &user_zone);
+      shorten_zone = &user_zone;
+      GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename);
+      if (!raw)
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Using zone: %s!\n", &zonename);
+      GNUNET_CRYPTO_rsa_key_free(key);
+    }
+    GNUNET_free(keyfile);
+  }
+  
   gns = GNUNET_GNS_connect (cfg);
   if (lookup_type != NULL)
     rtype = GNUNET_NAMESTORE_typename_to_number(lookup_type);
@@ -195,16 +224,20 @@
   if (shorten_name != NULL)
   {
     /** shorten name */
-    GNUNET_GNS_shorten_zone (gns, shorten_name, zone, &process_shorten_result,
-                       shorten_name);
+    GNUNET_GNS_shorten_zone (gns, shorten_name,
+                             zone, shorten_zone,
+                             &process_shorten_result,
+                             shorten_name);
   }
 
   if (lookup_name != NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Lookup\n");
-    GNUNET_GNS_lookup_zone (gns, lookup_name, zone, rtype,
-                      &process_lookup_result, lookup_name);
+    GNUNET_GNS_lookup_zone (gns, lookup_name,
+                            zone, shorten_zone,
+                            rtype,
+                            &process_lookup_result, lookup_name);
   }
 
   if (auth_name != NULL)

Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-06-11 13:56:55 UTC (rev 21889)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-06-11 14:59:04 UTC (rev 21890)
@@ -60,8 +60,8 @@
   /* request type */
   enum GNUNET_GNS_RecordType type;
 
-  /* optional zone private key used for lookup */
-  struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
+  /* optional zone private key used for shorten */
+  struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
   
   /* name to shorten */
   char* name;
@@ -100,8 +100,8 @@
   /* request type */
   enum GNUNET_GNS_RecordType type;
 
-  /* optional zone private key used for lookup */
-  struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
+  /* optional zone private key used for shorten */
+  struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
 
   /* the name to look up */
   char* name; //Needed?
@@ -425,13 +425,13 @@
 }
 
 /**
- * Lookup the private key for the zone
+ * Lookup the shorten key for the zone
  *
  * @param zone the zone we want a private key for
  * @return NULL of not found else the key
  */
 struct GNUNET_CRYPTO_RsaPrivateKey*
-lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone)
+lookup_shorten_key(struct GNUNET_CRYPTO_ShortHashCode *short_zone)
 {
   char* keydir;
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
@@ -439,7 +439,7 @@
   struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
   
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Looking for private key\n");
+              "Looking for shorten zonekey\n");
 
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg,
                                                             "namestore",
@@ -453,10 +453,10 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Zonefile directory is %s\n", keydir);
 
-  GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+  GNUNET_CRYPTO_short_hash_to_enc (short_zone, &zonename);
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Zonefile is %s.zkey\n", &zonename);
+              "Zonefile for shorten is %s.zkey\n", &zonename);
 
   GNUNET_asprintf(&location, "%s%s%s.zkey", keydir,
                   DIR_SEPARATOR_STR, &zonename);
@@ -513,7 +513,7 @@
   
   GNUNET_free(rmsg);
   GNUNET_free_non_null(csh->name);
-  GNUNET_free_non_null(csh->zone_key);
+  GNUNET_free_non_null(csh->shorten_key);
   GNUNET_free(csh);
 
 }
@@ -561,7 +561,7 @@
   csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
   csh->client = client;
   csh->unique_id = sh_msg->id;
-  csh->zone_key = NULL;
+  csh->shorten_key = NULL;
   
   GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
@@ -600,12 +600,12 @@
   /* Start shortening */
   if (GNUNET_YES == auto_import_pkey)
   {
-    if (1 == ntohl(sh_msg->use_default_zone))
-      key = zone_key;
+    if (0 == ntohl(sh_msg->use_shorten_zone))
+      key = NULL;
     else
     {
-      key = lookup_private_key(&sh_msg->zone);
-      csh->zone_key = key;
+      key = lookup_shorten_key(&sh_msg->shorten_zone);
+      csh->shorten_key = key;
     }
     gns_resolver_shorten_name(zone, zone, name, key,
                               &send_shorten_response, csh);
@@ -796,8 +796,8 @@
   GNUNET_free(rmsg);
   GNUNET_free(clh->name);
   
-  if (NULL != clh->zone_key)
-    GNUNET_free(clh->zone_key);
+  if (NULL != clh->shorten_key)
+    GNUNET_free(clh->shorten_key);
 
   GNUNET_free(clh);
 
@@ -855,7 +855,7 @@
   strcpy(clh->name, name);
   clh->unique_id = sh_msg->id;
   clh->type = ntohl(sh_msg->type);
-  clh->zone_key = NULL;
+  clh->shorten_key = NULL;
   
   if (strlen (name) > MAX_DNS_NAME_LENGTH) {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -872,12 +872,12 @@
   
   if (GNUNET_YES == auto_import_pkey)
   {
-    if (1 == ntohl(sh_msg->use_default_zone))
+    if (1 == ntohl(sh_msg->use_shorten_zone))
       key = zone_key;
     else
     {
-      key = lookup_private_key(&zone);
-      clh->zone_key = key;
+      key = lookup_shorten_key(&sh_msg->shorten_zone);
+      clh->shorten_key = key;
     }
     
     gns_resolver_lookup_record(zone, zone, clh->type, name,

Modified: gnunet/src/gns/test_gns_pseu_shorten.c
===================================================================
--- gnunet/src/gns/test_gns_pseu_shorten.c      2012-06-11 13:56:55 UTC (rev 
21889)
+++ gnunet/src/gns/test_gns_pseu_shorten.c      2012-06-11 14:59:04 UTC (rev 
21890)
@@ -90,6 +90,7 @@
 struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
 struct GNUNET_CRYPTO_ShortHashCode alice_hash;
 struct GNUNET_CRYPTO_ShortHashCode bob_hash;
+struct GNUNET_CRYPTO_ShortHashCode our_zone;
 
 /**
  * Check whether peers successfully shut down.
@@ -161,7 +162,9 @@
 static void
 do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result,
+  GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN,
+                     &our_zone, &our_zone,
+                     &process_shorten_result,
 TEST_DOMAIN);
 }
 
@@ -231,7 +234,9 @@
                 "Failed to connect to GNS!\n");
   }
 
-  GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
+  GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN,
+                          &our_zone, &our_zone,
+                          GNUNET_GNS_RECORD_TYPE_A,
                     &on_lookup_result, TEST_DOMAIN);
 }
 
@@ -545,6 +550,7 @@
   GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
   GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
   GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
+  GNUNET_CRYPTO_short_hash(&our_pkey, sizeof(our_pkey), &our_zone);
 
   struct GNUNET_NAMESTORE_RecordData rd;
   rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;

Modified: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h     2012-06-11 13:56:55 UTC (rev 
21889)
+++ gnunet/src/include/gnunet_gns_service.h     2012-06-11 14:59:04 UTC (rev 
21890)
@@ -146,6 +146,7 @@
  * @param handle handle to the GNS service
  * @param name the name to look up
  * @param zone the zone to start the resolution in
+ * @param shorten_zone the zone where to shorten names into
  * @param type the GNUNET_GNS_RecordType to look for
  * @param proc function to call on result
  * @param proc_cls closure for processor
@@ -156,6 +157,7 @@
 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
                          const char * name,
                          struct GNUNET_CRYPTO_ShortHashCode *zone,
+                         struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                          enum GNUNET_GNS_RecordType type,
                          GNUNET_GNS_LookupResultProcessor proc,
                          void *proc_cls);
@@ -196,6 +198,7 @@
  * @param handle handle to the GNS service
  * @param name the name to look up
  * @param zone the zone to start the resolution in
+ * @param shorten_zone the zone where to shorten names into
  * @param proc function to call on result
  * @param proc_cls closure for processor
  * @return handle to the operation
@@ -204,6 +207,7 @@
 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
                     const char * name,
                     struct GNUNET_CRYPTO_ShortHashCode *zone,
+                    struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                     GNUNET_GNS_ShortenResultProcessor proc,
                     void *proc_cls);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]