BINARY = gnunet-service-gns
UNIXPATH = /tmp/gnunet-service-gns.sock
ZONEKEY = $SERVICEHOME/gns/zonekey.zkey
+PRIVATE_ZONE = private
+PRIVATE_ZONEKEY = $SERVICEHOME/gns/zonekey_priv.zkey
+SHORTEN_ZONE = short
+SHORTEN_ZONEKEY = $SERVICEHOME/gns/zonekey_short.zkey
HIJACK_DNS = NO
AUTO_IMPORT_PKEY = YES
AUTO_IMPORT_ZONEKEY = $SERVICEHOME/gns/shorten_zonekey.zkey
uint32_t use_default_zone GNUNET_PACKED;
/**
- * If use_default_zone is empty this zone is used for lookup
+ * Is a shorten key attached?
*/
- struct GNUNET_CRYPTO_ShortHashCode zone;
+ uint32_t have_key GNUNET_PACKED;
/**
- * Should we use a shorten zone?
- */
- uint32_t use_shorten_zone GNUNET_PACKED;
-
- /**
- * If use_shorten_zone is set use this zone for shortening
+ * If use_default_zone is empty this zone is used for lookup
*/
- struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
+ struct GNUNET_CRYPTO_ShortHashCode zone;
/**
* the type of record to look up
*/
enum GNUNET_GNS_RecordType type;
+ /* Followed by the key for shorten (optional) see have_key */
+
/* Followed by the name to look up */
};
*/
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 */
};
* @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 only_cached GNUNET_NO to only check locally not DHT for performance
+ * @param shorten_key the private key of the shorten zone (can be NULL)
* @param proc processor to call on result
* @param proc_cls closure for processor
* @return handle to the get
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,
int only_cached,
+ struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
GNUNET_GNS_LookupResultProcessor proc,
void *proc_cls)
{
struct GNUNET_GNS_QueueEntry *qe;
size_t msize;
struct PendingMessage *pending;
+ struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc=NULL;
+ size_t key_len = 0;
+ char* pkey_tmp;
+
+ if (NULL != shorten_key)
+ {
+ pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key);
+ GNUNET_assert (pkey_enc != NULL);
+ key_len = ntohs (pkey_enc->len);
+ }
if (NULL == name)
{
return NULL;
}
- msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1;
+ msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
+ + key_len + strlen(name) + 1;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name);
qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
memset(&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
}
- if (NULL != shorten_zone)
+ lookup_msg->type = htonl(type);
+
+ pkey_tmp = (char *) &lookup_msg[1];
+
+ if (pkey_enc != NULL)
{
- lookup_msg->use_shorten_zone = htonl(1);
- memcpy(&lookup_msg->shorten_zone, shorten_zone,
- sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+ lookup_msg->have_key = htonl(1);
+ memcpy(pkey_tmp, pkey_enc, key_len);
}
else
- {
- lookup_msg->use_shorten_zone = htonl(0);
- memset(&lookup_msg->shorten_zone, 0,
- sizeof(struct GNUNET_CRYPTO_ShortHashCode));
- }
-
- lookup_msg->type = htonl(type);
+ lookup_msg->have_key = htonl(0);
- memcpy(&lookup_msg[1], name, strlen(name));
+ memcpy(&pkey_tmp[key_len], name, strlen(name));
GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
pending);
-
+ GNUNET_free_non_null (pkey_enc);
process_pending_messages (handle);
return qe;
}
* @param name the name to look up
* @param type the record type to look up
* @param only_cached GNUNET_NO to only check locally not DHT for performance
+ * @param shorten_key the private key of the shorten zone (can be NULL)
* @param proc processor to call on result
* @param proc_cls closure for processor
* @return handle to the get
const char * name,
enum GNUNET_GNS_RecordType type,
int only_cached,
+ struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
GNUNET_GNS_LookupResultProcessor proc,
void *proc_cls)
{
return GNUNET_GNS_lookup_zone (handle, name,
- NULL, NULL,
- type, only_cached, proc, proc_cls);
+ NULL,
+ type, only_cached,
+ shorten_key,
+ proc, proc_cls);
}
/**
* @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
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)
{
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,
GNUNET_GNS_ShortenResultProcessor proc,
void *proc_cls)
{
- return GNUNET_GNS_shorten_zone (handle, name, NULL, NULL, proc, proc_cls);
+ return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls);
}
/**
* Perform an authority lookup for a given name.
/* 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;
+/* Shorten zone private key */
+struct GNUNET_CRYPTO_RsaPrivateKey *shorten_zonekey;
/**
* Checks if name is in tld
GNUNET_GNS_lookup_zone (gns_handle,
ctask->host,
&local_gns_zone,
- &local_shorten_zone,
GNUNET_GNS_RECORD_LEHO,
GNUNET_YES, //Only cached for performance
+ shorten_zonekey,
&process_leho_lookup,
ctask);
}
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 shorten key config value! (not fatal)\n");
- return GNUNET_NO;
- }
-
- if (GNUNET_NO == GNUNET_DISK_file_test (keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to load shorten key %s! (not fatal)\n", keyfile);
- 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
*
char* proxy_sockfile;
char* cafile_cfg = NULL;
char* cafile;
+ char* shorten_keyfile;
curl_multi = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Loading Template\n");
-
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
+ "PROXY_CACERT",
+ &shorten_keyfile))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unable to load shorten zonekey config value!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No shorten key provided!\n");
+ return;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Loading shorten zonekey %s!\n",
+ shorten_keyfile);
+ shorten_zonekey = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile);
+ GNUNET_free (shorten_keyfile);
+ }
+
compile_regex (&re_dotplus, (char*) RE_A_HREF);
gns_handle = GNUNET_GNS_connect (cfg);
return;
}
- use_shorten = load_local_shorten_key (cfg);
-
if (NULL == gns_handle)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
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_ShortHashCode user_shorten_zone;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
+ struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key = NULL;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
"ZONEKEY", &keyfile))
}
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
- "AUTO_IMPORT_ZONEKEY",
- &keyfile))
+ "SHORTEN_ZONEKEY", &keyfile))
{
if (!raw)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No private key for shorten zone found!\n");
- shorten_zone = NULL;
+ "No shorten key found!\n");
+ shorten_key = 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_shorten_zone);
- shorten_zone = &user_shorten_zone;
- GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename);
- if (!raw)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using shorten zone: %s!\n", &zonename);
- GNUNET_CRYPTO_rsa_key_free(key);
+ shorten_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
}
GNUNET_free(keyfile);
}
{
/** shorten name */
GNUNET_GNS_shorten_zone (gns, shorten_name,
- zone, shorten_zone,
+ zone,
&process_shorten_result,
shorten_name);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Lookup\n");
GNUNET_GNS_lookup_zone (gns, lookup_name,
- zone, shorten_zone,
+ zone,
rtype,
GNUNET_YES, //Use DHT
+ shorten_key,
&process_lookup_result, lookup_name);
}
struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
/* name to shorten */
- char* name;
+ char name[MAX_DNS_NAME_LENGTH];
+ /* root zone */
+ struct GNUNET_CRYPTO_ShortHashCode root_zone;
+
+ /* private zone */
+ struct GNUNET_CRYPTO_ShortHashCode private_zone;
+
+ /* shorten zone */
+ struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
};
/* the requesting client that */
struct GNUNET_SERVER_Client *client;
+ /* The zone we look up in */
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+
+ /* Do we only want to lookup from local cache? */
+ int only_cached;
+
/* request id */
uint64_t unique_id;
/* lookup timeout */
static struct GNUNET_TIME_Relative default_lookup_timeout;
+/* name of the private zone */
+static char *private_zone_id;
+
+/* name of the public zone */
+static char *shorten_zone_id;
+
/**
* Continue shutdown
*/
NULL);
}
-/**
- * Lookup the shorten key for the zone
- *
- * @param short_zone the zone we want a private key for
- * @return NULL of not found else the key
- */
-struct GNUNET_CRYPTO_RsaPrivateKey*
-lookup_shorten_key(struct GNUNET_CRYPTO_ShortHashCode *short_zone)
-{
- char* keydir;
- struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
- char* location;
- struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Looking for shorten zonekey\n");
-
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg,
- "namestore",
- "ZONEFILE_DIRECTORY", &keydir))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No zonefile directory!\n");
- return NULL;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Zonefile directory is %s\n", keydir);
-
- GNUNET_CRYPTO_short_hash_to_enc (short_zone, &zonename);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Zonefile for shorten is %s.zkey\n", &zonename);
-
- GNUNET_asprintf(&location, "%s%s%s.zkey", keydir,
- DIR_SEPARATOR_STR, &zonename);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Checking for %s\n", location);
-
- if (GNUNET_YES == GNUNET_DISK_file_test (location))
- key = GNUNET_CRYPTO_rsa_key_create_from_file (location);
-
- GNUNET_free(location);
- GNUNET_free(keydir);
-
- return key;
-
-}
-
/* END DHT ZONE PROPAGATION */
/**
GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
GNUNET_free(rmsg);
- GNUNET_free_non_null(csh->name);
GNUNET_free_non_null(csh->shorten_key);
GNUNET_free(csh);
}
+
+static void
+process_shorten_zone_shorten (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *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)
+{
+ struct ClientShortenHandle *csh = cls;
+ struct GNUNET_TIME_Relative remaining_time;
+
+ remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
+
+ if ((rd_count == 1) &&
+ (remaining_time.rel_value != 0))
+ {
+ remaining_time = GNUNET_TIME_absolute_get_remaining (rd->expiration);
+ if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) &&
+ (remaining_time.rel_value != 0))
+ {
+ csh->shorten_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data);
+ }
+ }
+ gns_resolver_shorten_name (&csh->root_zone,
+ &csh->private_zone,
+ &csh->shorten_zone,
+ csh->name,
+ private_zone_id,
+ shorten_zone_id,
+ &send_shorten_response, csh);
+
+}
+
+static void
+process_private_zone_shorten (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *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)
+{
+ struct GNUNET_TIME_Relative remaining_time;
+ struct ClientShortenHandle *csh = cls;
+
+ remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
+
+ if ((rd_count == 1) &&
+ (remaining_time.rel_value != 0))
+ {
+ remaining_time = GNUNET_TIME_absolute_get_remaining (rd->expiration);
+ if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) &&
+ (remaining_time.rel_value != 0))
+ {
+
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Looking for shorten zone in private zone\n");
+ csh->private_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data);
+ GNUNET_NAMESTORE_lookup_record (namestore_handle,
+ &csh->private_zone,
+ shorten_zone_id,
+ GNUNET_GNS_RECORD_ANY,
+ &process_shorten_zone_shorten,
+ cls);
+ }
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No private zone found!\n");
+ gns_resolver_shorten_name (&csh->root_zone,
+ &csh->private_zone,
+ &csh->shorten_zone,
+ csh->name,
+ private_zone_id,
+ shorten_zone_id,
+ &send_shorten_response, csh);
+
+}
+
+/**
+ * Lookup the zone infos and shorten name
+ *
+ * @param csh the shorten handle
+ *
+ */
+static void
+start_shorten_name (struct ClientShortenHandle *csh)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Looking for private zone in root zone\n");
+
+ GNUNET_NAMESTORE_lookup_record (namestore_handle,
+ &csh->root_zone,
+ private_zone_id,
+ GNUNET_GNS_RECORD_ANY,
+ &process_private_zone_shorten,
+ csh);
+}
+
+
/**
* Handle a shorten message from the api
*
* @param client the client
* @param message the message
*/
-static void handle_shorten(void *cls,
- struct GNUNET_SERVER_Client * client,
- const struct GNUNET_MessageHeader * message)
+static void handle_shorten (void *cls,
+ struct GNUNET_SERVER_Client * client,
+ const struct GNUNET_MessageHeader * message)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
struct ClientShortenHandle *csh;
char name[MAX_DNS_NAME_LENGTH];
char* nameptr = name;
- struct GNUNET_CRYPTO_ShortHashCode zone;
- struct GNUNET_CRYPTO_RsaPrivateKey *key;
if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
{
if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"SHORTEN: %s is too short", name);
- csh->name = NULL;
send_shorten_response(csh, name);
return;
}
if (strlen (name) > MAX_DNS_NAME_LENGTH) {
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"SHORTEN: %s is too long", name);
- csh->name = NULL;
send_shorten_response(csh, name);
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s is not our domain. Returning\n", name);
- csh->name = NULL;
send_shorten_response(csh, name);
return;
}
+
+ strcpy (csh->name, name);
GNUNET_SERVER_notification_context_add (nc, client);
if (1 == ntohl(sh_msg->use_default_zone))
- zone = zone_hash; //Default zone
+ csh->root_zone = zone_hash; //Default zone
else
- zone = sh_msg->zone;
+ csh->root_zone = sh_msg->zone;
+
+ start_shorten_name (csh);
- /* Start shortening */
- if (GNUNET_YES == auto_import_pkey)
- {
- if (0 == ntohl(sh_msg->use_shorten_zone))
- key = NULL;
- else
- {
- key = lookup_shorten_key(&sh_msg->shorten_zone);
- csh->shorten_key = key;
- }
- gns_resolver_shorten_name(zone, zone, name, key,
- &send_shorten_response, csh);
- }
- else
- gns_resolver_shorten_name(zone, zone, name, NULL,
- &send_shorten_response, csh);
}
char name[MAX_DNS_NAME_LENGTH];
struct ClientLookupHandle *clh;
char* nameptr = name;
- struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
- struct GNUNET_CRYPTO_ShortHashCode zone;
int only_cached;
+ struct GNUNET_CRYPTO_RsaPrivateKey *key;
+ struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey;
+ char* tmp_pkey;
if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
{
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
+
+ if (1 == ntohl(sh_msg->have_key))
+ {
+ pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&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);
+ }
+ else
+ {
+ key = NULL;
+ GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
+ }
- GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
namelen = strlen(name)+1;
clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
clh->client = client;
strcpy(clh->name, name);
clh->unique_id = sh_msg->id;
clh->type = ntohl(sh_msg->type);
- clh->shorten_key = NULL;
+ clh->shorten_key = key;
only_cached = ntohl(sh_msg->only_cached);
}
if (1 == ntohl(sh_msg->use_default_zone))
- zone = zone_hash; //Default zone
+ clh->zone = zone_hash; //Default zone
else
- zone = sh_msg->zone;
+ clh->zone = sh_msg->zone;
if (GNUNET_YES == auto_import_pkey)
{
- if (1 == ntohl(sh_msg->use_shorten_zone))
- key = zone_key;
- else
- {
- key = lookup_shorten_key(&sh_msg->shorten_zone);
- clh->shorten_key = key;
- }
-
- gns_resolver_lookup_record(zone, zone, clh->type, name,
- key,
- default_lookup_timeout,
- only_cached,
- &send_lookup_response, clh);
+ gns_resolver_lookup_record (clh->zone, clh->zone, clh->type, clh->name,
+ clh->shorten_key,
+ default_lookup_timeout,
+ clh->only_cached,
+ &send_lookup_response, clh);
}
else
{
- gns_resolver_lookup_record(zone, zone, clh->type, name,
- NULL,
- default_lookup_timeout,
- only_cached,
- &send_lookup_response, clh);
+ gns_resolver_lookup_record (clh->zone, clh->zone, clh->type, name,
+ NULL,
+ default_lookup_timeout,
+ only_cached,
+ &send_lookup_response, clh);
}
}
}
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns",
+ "PRIVATE_ZONE",
+ &private_zone_id))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Private zone id: %s\n", private_zone_id);
+ }
+
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns",
+ "SHORTEN_ZONE",
+ &shorten_zone_id))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Shorten zone id: %s\n", shorten_zone_id);
+ }
+
dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
if (GNUNET_OK ==
GNUNET_free (gph->ahead);
gph->ahead = iter;
} while (iter != NULL);
+ GNUNET_CRYPTO_rsa_key_free (gph->key);
GNUNET_free (gph);
return;
GNUNET_free (gph->ahead);
gph->ahead = iter;
} while (iter != NULL);
-
- GNUNET_free(gph);
+ GNUNET_CRYPTO_rsa_key_free (gph->key);
+ GNUNET_free (gph);
}
GNUNET_free (gph->ahead);
gph->ahead = iter;
} while (iter != NULL);
-
+ GNUNET_CRYPTO_rsa_key_free (gph->key);
GNUNET_free (gph);
return;
}
GNUNET_free (gph->ahead);
gph->ahead = iter;
} while (iter != NULL);
-
+ GNUNET_CRYPTO_rsa_key_free (gph->key);
GNUNET_free (gph);
}
else
struct AuthorityChain *acopy;
struct GetPseuAuthorityHandle *gph;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+ struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pb_key;
/* First copy the authority chain in reverse order */
for (iter = atail; iter != NULL; iter = iter->prev)
gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle));
GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
- gph->key = key;//GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
+ pb_key = GNUNET_CRYPTO_rsa_encode_key (key);
+ gph->key = GNUNET_CRYPTO_rsa_decode_key ((char*)pb_key, ntohs (pb_key->len));
+ //gph->key = key;//GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
//memcpy (gph->key, key, sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
GNUNET_CRYPTO_short_hash (&pkey,
rh->get_handle = NULL;
rh->private_local_zone = pzone;
rh->only_cached = only_cached;
+
+ if (NULL == key)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No shorten key for resolution\n");
+ }
if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
{
/******** END Record Resolver ***********/
-
/**
* Callback calles by namestore for a zone to name
* result
* @param signature the signature for the record data
*/
static void
-process_zone_to_name_shorten(void *cls,
+process_zone_to_name_shorten_root (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature);
+
+
+/**
+ * Callback called by namestore for a zone to name
+ * result
+ *
+ * @param cls the closure
+ * @param zone_key the zone we queried
+ * @param expire the expiration time of the name
+ * @param name the name found or NULL
+ * @param rd_len number of records for the name
+ * @param rd the record data (PKEY) for the name
+ * @param signature the signature for the record data
+ */
+static void
+process_zone_to_name_shorten_shorten (void *cls,
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
struct GNUNET_TIME_Absolute expire,
const char *name,
char tmp_name[MAX_DNS_NAME_LENGTH];
size_t answer_len;
- /* we found a match in our own zone */
+ /* we found a match in our own root zone */
if (rd_len != 0)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"result strlen %d\n", strlen(name));
answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
memset(result, 0, answer_len);
+
if (strlen(rh->name) > 0)
{
- strcpy(result, rh->name);
- strcpy(result+strlen(rh->name), ".");
+ sprintf (result, "%s.%s.%s.%s.%s",
+ rh->name, name,
+ nsh->shorten_zone_name, nsh->private_zone_name,
+ GNUNET_GNS_TLD);
+ }
+ else
+ {
+ sprintf (result, "%s.%s.%s.%s", name,
+ nsh->shorten_zone_name, nsh->private_zone_name,
+ GNUNET_GNS_TLD);
}
-
- strcpy(result+strlen(result), name);
- strcpy(result+strlen(result), ".");
- strcpy(result+strlen(result), GNUNET_GNS_TLD);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending shorten result %s\n", result);
-
- nsh->proc(nsh->proc_cls, result);
- GNUNET_free(nsh);
- free_resolver_handle(rh);
+ "Found shorten result %s\n", result);
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
}
else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
- &rh->private_local_zone) == 0)
+ nsh->shorten_zone) == 0)
+ {
+ /**
+ * This is our zone append .gnunet unless name is empty
+ * (it shouldn't be, usually FIXME what happens if we
+ * shorten to our zone to a "" record??)
+ */
+
+ sprintf (result, "%s.%s.%s.%s",
+ rh->name,
+ nsh->shorten_zone_name, nsh->private_zone_name,
+ GNUNET_GNS_TLD);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Our zone: Found %s as shorten result\n", result);
+
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
+ //nsh->proc(nsh->proc_cls, result);
+ //GNUNET_free(nsh);
+ //free_resolver_handle(rh);
+ //return;
+ }
+
+
+ /**
+ * No PSEU found.
+ * continue with next authority if exists
+ */
+ if ((rh->authority_chain_head->next == NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %s as shorten result\n", nsh->result);
+ nsh->proc(nsh->proc_cls, nsh->result);
+ GNUNET_free (nsh);
+ free_resolver_handle (rh);
+ return;
+ }
+ next_authority = rh->authority_chain_head;
+
+ GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH,
+ "%s.%s", rh->name, next_authority->name);
+
+ strcpy(rh->name, tmp_name);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "No PSEU found for authority %s. Promoting back: %s\n",
+ next_authority->name, rh->name);
+
+ GNUNET_CONTAINER_DLL_remove(rh->authority_chain_head,
+ rh->authority_chain_tail,
+ next_authority);
+
+ GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+ &rh->authority_chain_tail->zone,
+ &rh->authority_chain_head->zone,
+ &process_zone_to_name_shorten_root,
+ rh);
+}
+
+/**
+ * Callback calles by namestore for a zone to name
+ * result
+ *
+ * @param cls the closure
+ * @param zone_key the zone we queried
+ * @param expire the expiration time of the name
+ * @param name the name found or NULL
+ * @param rd_len number of records for the name
+ * @param rd the record data (PKEY) for the name
+ * @param signature the signature for the record data
+ */
+static void
+process_zone_to_name_shorten_private (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+ struct ResolverHandle *rh = (struct ResolverHandle *)cls;
+ struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls;
+ struct AuthorityChain *next_authority;
+
+ char result[MAX_DNS_NAME_LENGTH];
+ char tmp_name[MAX_DNS_NAME_LENGTH];
+ size_t answer_len;
+
+ /* we found a match in our own root zone */
+ if (rd_len != 0)
{
- /* our zone, just append .gnunet */
- answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "result strlen %d\n", strlen(name));
+ answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
memset(result, 0, answer_len);
- strcpy(result, rh->name);
- strcpy(result+strlen(rh->name), ".");
- strcpy(result+strlen(rh->name)+1, GNUNET_GNS_TLD);
+ if (strlen(rh->name) > 0)
+ {
+ sprintf (result, "%s.%s.%s", rh->name, name, GNUNET_GNS_TLD);
+ }
+ else
+ {
+ sprintf (result, "%s.%s", name, GNUNET_GNS_TLD);
+ }
+
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Our zone: Sending name as shorten result %s\n", rh->name);
+ "Found shorten result %s\n", result);
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
+ }
+ else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
+ nsh->private_zone) == 0)
+ {
+ /**
+ * This is our zone append .gnunet unless name is empty
+ * (it shouldn't be, usually FIXME what happens if we
+ * shorten to our zone to a "" record??)
+ */
- nsh->proc(nsh->proc_cls, result);
- GNUNET_free(nsh);
- free_resolver_handle(rh);
+ sprintf (result, "%s.%s.%s",
+ rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Our private zone: Found %s as shorten result %s\n", result);
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
+ }
+
+ if (nsh->shorten_zone != NULL)
+ {
+ /* backtrack authorities for names in priv zone */
+ GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+ nsh->shorten_zone,
+ &rh->authority_chain_head->zone,
+ &process_zone_to_name_shorten_shorten,
+ rh);
}
else
{
/**
* No PSEU found.
- * continue with next authority
+ * continue with next authority if exists
*/
+ if ((rh->authority_chain_head->next == NULL))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %s as shorten result\n", nsh->result);
+ nsh->proc(nsh->proc_cls, nsh->result);
+ GNUNET_free(nsh);
+ free_resolver_handle(rh);
+ return;
+ }
next_authority = rh->authority_chain_head;
GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH,
GNUNET_NAMESTORE_zone_to_name (namestore_handle,
&rh->authority_chain_tail->zone,
&rh->authority_chain_head->zone,
- &process_zone_to_name_shorten,
+ &process_zone_to_name_shorten_root,
rh);
}
}
/**
- * DHT resolution for delegation. Processing result.
+ * Callback calles by namestore for a zone to name
+ * result
*
* @param cls the closure
- * @param rh resolver handle
- * @param rd_count number of results
- * @param rd record data
+ * @param zone_key the zone we queried
+ * @param expire the expiration time of the name
+ * @param name the name found or NULL
+ * @param rd_len number of records for the name
+ * @param rd the record data (PKEY) for the name
+ * @param signature the signature for the record data
*/
static void
-handle_delegation_dht_bg_shorten(void* cls, struct ResolverHandle *rh,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd)
+process_zone_to_name_shorten_root (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_len,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
{
+ struct ResolverHandle *rh = (struct ResolverHandle *)cls;
+ struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls;
+ struct AuthorityChain *next_authority;
+
+ char result[MAX_DNS_NAME_LENGTH];
+ char tmp_name[MAX_DNS_NAME_LENGTH];
+ size_t answer_len;
- /* We resolved full name for delegation. resolving record */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_SHORTEN: Resolved up to %s for delegation via DHT in background.\n",
- rh->name);
- free_resolver_handle(rh);
+ /* we found a match in our own root zone */
+ if (rd_len != 0)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "result strlen %d\n", strlen(name));
+ answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
+ memset(result, 0, answer_len);
+
+ if (strlen(rh->name) > 0)
+ {
+ sprintf (result, "%s.%s.%s", rh->name, name, GNUNET_GNS_TLD);
+ }
+ else
+ {
+ sprintf (result, "%s.%s", name, GNUNET_GNS_TLD);
+ }
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Found shorten result %s\n", result);
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
+ }
+ else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
+ nsh->root_zone) == 0)
+ {
+ /**
+ * This is our zone append .gnunet unless name is empty
+ * (it shouldn't be, usually FIXME what happens if we
+ * shorten to our zone to a "" record??)
+ */
+
+ sprintf (result, "%s.%s", rh->name, GNUNET_GNS_TLD);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Our zone: Found %s as shorten result\n", result);
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
+ }
+
+ if (nsh->private_zone != NULL)
+ {
+ /* backtrack authorities for names in priv zone */
+ GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+ nsh->private_zone,
+ &rh->authority_chain_head->zone,
+ &process_zone_to_name_shorten_private,
+ rh);
+ }
+ else
+ {
+ /**
+ * No PSEU found.
+ * continue with next authority if exists
+ */
+ if ((rh->authority_chain_head->next == NULL))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %s as shorten result\n", nsh->result);
+ nsh->proc(nsh->proc_cls, nsh->result);
+ GNUNET_free(nsh);
+ free_resolver_handle(rh);
+ return;
+ }
+ next_authority = rh->authority_chain_head;
+
+ GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH,
+ "%s.%s", rh->name, next_authority->name);
+
+ strcpy(rh->name, tmp_name);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "No PSEU found for authority %s. Promoting back: %s\n",
+ next_authority->name, rh->name);
+
+ GNUNET_CONTAINER_DLL_remove(rh->authority_chain_head,
+ rh->authority_chain_tail,
+ next_authority);
+
+ GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+ &rh->authority_chain_tail->zone,
+ &rh->authority_chain_head->zone,
+ &process_zone_to_name_shorten_root,
+ rh);
+ }
}
+
/**
* Process result from namestore delegation lookup
* for shorten operation
{
struct NameShortenHandle *nsh;
char result[MAX_DNS_NAME_LENGTH];
- size_t answer_len;
- struct ResolverHandle *rh_bg;
nsh = (struct NameShortenHandle *)cls;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"PKEY resolved as far as possible in ns up to %s!\n", rh->name);
+ memset(result, 0, sizeof (result));
if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
- &rh->private_local_zone) == 0)
+ nsh->root_zone) == 0)
{
/**
* This is our zone append .gnunet unless name is empty
* shorten to our zone to a "" record??)
*/
- answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2;
- memset(result, 0, answer_len);
- strcpy(result, rh->name);
- strcpy(result+strlen(rh->name), ".");
- strcpy(result+strlen(rh->name)+1, GNUNET_GNS_TLD);
+ sprintf (result, "%s.%s", rh->name, GNUNET_GNS_TLD);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Our zone: Found %s as shorten result\n", result);
+
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
+ }
+ else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
+ nsh->private_zone) == 0)
+ {
+ /**
+ * This is our zone append .gnunet unless name is empty
+ * (it shouldn't be, usually FIXME what happens if we
+ * shorten to our zone to a "" record??)
+ */
+
+ sprintf (result, "%s.%s.%s",
+ rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Our zone: Sending name as shorten result %s\n", rh->name);
+ "Our zone: Found %s as shorten result %s\n", result);
- nsh->proc(nsh->proc_cls, result);
- GNUNET_free(nsh);
- free_resolver_handle(rh);
- return;
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
}
-
- /**
- * we have to this before zone to name for rh might
- * be freed by then
- */
- rh_bg = NULL;
- if (!is_canonical(rh->name))
+ else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
+ nsh->shorten_zone) == 0)
{
- rh_bg = GNUNET_malloc(sizeof(struct ResolverHandle));
- memcpy(rh_bg, rh, sizeof(struct ResolverHandle));
- rh_bg->id = rid++;
+ /**
+ * This is our zone append .gnunet unless name is empty
+ * (it shouldn't be, usually FIXME what happens if we
+ * shorten to our zone to a "" record??)
+ */
+
+ sprintf (result, "%s.%s.%s",
+ rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Our zone: Found %s as shorten result\n", result);
+
+ if (strlen (nsh->result) > strlen (result))
+ strcpy (nsh->result, result);
}
-
+
+
/* backtrack authorities for names */
GNUNET_NAMESTORE_zone_to_name (namestore_handle,
- &rh->authority_chain_tail->zone, //ours
+ nsh->root_zone,
&rh->authority_chain_head->zone,
- &process_zone_to_name_shorten,
+ &process_zone_to_name_shorten_root,
rh);
- if (rh_bg == NULL)
- {
- return;
- }
-
- /**
- * If authority resolution is incomplete we can do a background lookup
- * of the full name so that next time we can (likely) fully or at least
- * further shorten the name
- */
- rh_bg->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain));
- rh_bg->authority_chain_tail = rh_bg->authority_chain_head;
- rh_bg->authority_chain_head->zone = rh_bg->authority;
-
- rh_bg->proc = &handle_delegation_dht_bg_shorten;
- rh_bg->proc_cls = NULL;
- rh_bg->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_SHORTEN: Starting background lookup for %s\n",
- rh_bg->name);
-
- resolve_delegation_dht(rh_bg);
-
}
else
GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s",
enc, GNUNET_GNS_TLD_ZKEY);
+
+ strcpy (nsh->result, new_name);
+
nsh->proc(nsh->proc_cls, new_name);
GNUNET_free(nsh);
free_resolver_handle(rh);
/**
* Shorten api from resolver
*
- * @param zone the zone to use
- * @param pzone the private local zone
+ * @param zone the root zone to use
+ * @param pzone the private zone to use
+ * @param szone the shorten zone to use
* @param name the name to shorten
- * @param key optional private key for background lookups and PSEU import
+ * @param private_zone_name name of the private zone
+ * @param shorten_zone_name name of the shorten zone
* @param proc the processor to call with result
* @param proc_cls closure to pass to proc
*/
void
-gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
- struct GNUNET_CRYPTO_ShortHashCode pzone,
- const char* name,
- struct GNUNET_CRYPTO_RsaPrivateKey *key,
- ShortenResultProcessor proc,
- void* proc_cls)
+gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
+ struct GNUNET_CRYPTO_ShortHashCode *pzone,
+ struct GNUNET_CRYPTO_ShortHashCode *szone,
+ const char* name,
+ const char* private_zone_name,
+ const char* shorten_zone_name,
+ ShortenResultProcessor proc,
+ void* proc_cls)
{
struct ResolverHandle *rh;
struct NameShortenHandle *nsh;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting shorten for %s!\n", name);
- if (is_canonical((char*)name))
+ if (is_canonical ((char*)name))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s is canonical. Returning verbatim\n", name);
- proc(proc_cls, name);
+ proc (proc_cls, name);
return;
}
- nsh = GNUNET_malloc(sizeof (struct NameShortenHandle));
+ nsh = GNUNET_malloc (sizeof (struct NameShortenHandle));
nsh->proc = proc;
nsh->proc_cls = proc_cls;
-
- rh = GNUNET_malloc(sizeof (struct ResolverHandle));
- rh->authority = zone;
+ nsh->root_zone = zone;
+ nsh->private_zone = pzone;
+ nsh->shorten_zone = szone;
+ strcpy (nsh->private_zone_name, private_zone_name);
+ strcpy (nsh->shorten_zone_name, shorten_zone_name);
+ strcpy (nsh->result, name);
+
+ rh = GNUNET_malloc (sizeof (struct ResolverHandle));
+ rh->authority = *zone;
rh->id = rid++;
- rh->priv_key = key;
+ rh->priv_key = NULL;
rh->proc = &handle_delegation_ns_shorten;
rh->proc_cls = nsh;
rh->id = rid++;
- rh->private_local_zone = pzone;
+ rh->private_local_zone = *zone;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking for TLD...\n");
- if (is_zkey_tld(name) == GNUNET_YES)
+ if (is_zkey_tld (name) == GNUNET_YES)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"TLD is zkey\n");
* build hash and use as initial authority
* FIXME sscanf
*/
- memset(rh->name, 0,
- strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY));
- memcpy(rh->name, name,
- strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY) - 1);
- pop_tld(rh->name, string_hash);
+ memset (rh->name, 0,
+ strlen (name)-strlen (GNUNET_GNS_TLD_ZKEY));
+ memcpy (rh->name, name,
+ strlen(name)-strlen (GNUNET_GNS_TLD_ZKEY) - 1);
+ pop_tld (rh->name, string_hash);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"ZKEY is %s!\n", string_hash);
- GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
+ GNUNET_STRINGS_utf8_toupper (string_hash, &nzkey_ptr);
- if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
- &zkey))
+ if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string (nzkey,
+ &zkey))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Cannot convert ZKEY %s to hash!\n", nzkey);
- GNUNET_free(rh);
- GNUNET_free(nsh);
- proc(proc_cls, name);
+ GNUNET_free (rh);
+ GNUNET_free (nsh);
+ proc (proc_cls, name);
return;
}
GNUNET_NAMESTORE_zone_to_name (namestore_handle,
- &zone, //ours
+ zone, //ours
&zkey,
&process_zone_to_name_zkey,
rh);
/**
* Presumably GNUNET tld
*/
- memset(rh->name, 0,
- strlen(name)-strlen(GNUNET_GNS_TLD));
- memcpy(rh->name, name,
- strlen(name)-strlen(GNUNET_GNS_TLD) - 1);
+ memset (rh->name, 0,
+ strlen (name)-strlen (GNUNET_GNS_TLD));
+ memcpy (rh->name, name,
+ strlen (name)-strlen (GNUNET_GNS_TLD) - 1);
}
- rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain));
+ rh->authority_chain_head = GNUNET_malloc (sizeof (struct AuthorityChain));
rh->authority_chain_tail = rh->authority_chain_head;
- rh->authority_chain_head->zone = zone;
+ rh->authority_chain_head->zone = *zone;
/* Start delegation resolution in our namestore */
- resolve_delegation_ns(rh);
+ resolve_delegation_ns (rh);
}
/*********** END NAME SHORTEN ********************/
/* closure to pass to proc */
void* proc_cls;
+
+ /* result of shorten */
+ char result[MAX_DNS_NAME_LENGTH];
+
+ /* root zone */
+ struct GNUNET_CRYPTO_ShortHashCode *root_zone;
+
+ /* private zone */
+ struct GNUNET_CRYPTO_ShortHashCode *private_zone;
+
+ /* name of private zone */
+ char private_zone_name[MAX_DNS_LABEL_LENGTH];
+
+ /* shorten zone */
+ struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
+
+ /* name of shorten zone */
+ char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
+
};
/**
* There is no guarantee that the shortened name will
* actually be canonical/short etc.
*
- * @param zone the zone to perform the operation in
- * @param pzone the private local zone
+ * @param zone the root zone to use
+ * @param pzone the private zone to use
+ * @param szone the shorten zone to use
* @param name name to shorten
- * @param key optional private key for background lookups and PSEU import
+ * @param private_zone_name name of the private zone
+ * @param shorten_zone_name name of the shorten zone
* @param proc the processor to call on shorten result
* @param proc_cls the closure to pass to proc
*/
void
-gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
- struct GNUNET_CRYPTO_ShortHashCode pzone,
+gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
+ struct GNUNET_CRYPTO_ShortHashCode *pzone,
+ struct GNUNET_CRYPTO_ShortHashCode *szone,
const char* name,
- struct GNUNET_CRYPTO_RsaPrivateKey *key,
+ const char* private_zone_name,
+ const char* shorten_zone_name,
ShortenResultProcessor proc,
void* proc_cls);
GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
+ NULL,
&on_lookup_result, TEST_DOMAIN);
}
GNUNET_GNS_lookup(gh, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
+ NULL,
&on_lookup_result, TEST_DOMAIN);
die_task =
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from lookup");
"www.doesnotexist-%d.bob.gnunet", i);
GNUNET_GNS_lookup(gns_handle, lookup_name, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
+ NULL,
&on_lookup_result_dummy, NULL);
}
GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
+ NULL,
&on_lookup_result, TEST_DOMAIN);
}
#define DEFAULT_NUM_PEERS 2
/* test records to resolve */
-#define TEST_DOMAIN "www.alice.bob.gnunet"
+#define TEST_DOMAIN "www.alicewonderland.bobbuilder.gnunet"
#define TEST_IP "127.0.0.1"
#define TEST_RECORD_NAME "www"
-#define TEST_AUTHORITY_BOB "bob"
-#define TEST_AUTHORITY_ALICE "alice"
+#define TEST_PRIVATE_ZONE "private"
+#define TEST_SHORTEN_ZONE "short"
+#define TEST_AUTHORITY_BOB "bobbuilder"
+#define TEST_AUTHORITY_ALICE "alicewonderland"
#define TEST_PSEU_ALICE "carol"
-#define TEST_EXPECTED_RESULT "www.carol.gnunet"
+#define TEST_EXPECTED_RESULT "www.carol.short.private.gnunet"
#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey;
+struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded priv_pkey;
+struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded short_pkey;
struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
+struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
+struct GNUNET_CRYPTO_RsaPrivateKey *short_key;
struct GNUNET_CRYPTO_ShortHashCode alice_hash;
struct GNUNET_CRYPTO_ShortHashCode bob_hash;
struct GNUNET_CRYPTO_ShortHashCode our_zone;
+struct GNUNET_CRYPTO_ShortHashCode priv_zone;
+struct GNUNET_CRYPTO_ShortHashCode short_zone;
/**
* Check whether peers successfully shut down.
do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN,
- &our_zone, &our_zone,
+ &our_zone,
&process_shorten_result,
-TEST_DOMAIN);
+ TEST_DOMAIN);
}
static void
}
GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN,
- &our_zone, &our_zone,
+ &our_zone,
GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
- &on_lookup_result, TEST_DOMAIN);
+ short_key,
+ &on_lookup_result, TEST_DOMAIN);
}
/**
}
static void
-do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *_cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+fin_init_zone (void *cls, int32_t success, const char *emsg)
+{
+ struct GNUNET_NAMESTORE_RecordData rd;
+ rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
+ rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
+ rd.data = &bob_hash;
+ rd.record_type = GNUNET_GNS_RECORD_PKEY;
+
+ GNUNET_NAMESTORE_record_create (namestore_handle,
+ our_key,
+ TEST_AUTHORITY_BOB,
+ &rd,
+ &put_pkey_dht,
+ NULL);
+
+}
+
+static void
+cont_init_zone (void *cls, int32_t success, const char *emsg)
+{
+
+ struct GNUNET_NAMESTORE_RecordData rd;
+ rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
+ rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
+ rd.data = &short_zone;
+ rd.record_type = GNUNET_GNS_RECORD_PKEY;
+
+ GNUNET_NAMESTORE_record_create (namestore_handle,
+ priv_key,
+ TEST_SHORTEN_ZONE,
+ &rd,
+ &fin_init_zone,
+ NULL);
+}
+
+static void
+do_lookup (void *cls, const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *_cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
-
+ char* private_keyfile;
+ char* shorten_keyfile;
char* our_keyfile;
cfg = _cfg;
ok = -1;
return;
}
-
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+ "SHORTEN_ZONEKEY",
+ &shorten_keyfile))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+ "Failed to get shorten zone key from cfg\n");
+ ok = -1;
+ return;
+ }
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+ "PRIVATE_ZONEKEY",
+ &private_keyfile))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+ "Failed to get private zone key from cfg\n");
+ ok = -1;
+ return;
+ }
our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile);
+ priv_key = GNUNET_CRYPTO_rsa_key_create_from_file (private_keyfile);
+ short_key = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile);
bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE);
GNUNET_free(our_keyfile);
+ GNUNET_free(shorten_keyfile);
+ GNUNET_free(private_keyfile);
GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey);
+ GNUNET_CRYPTO_rsa_key_get_public (priv_key, &priv_pkey);
+ GNUNET_CRYPTO_rsa_key_get_public (short_key, &short_pkey);
GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
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);
-
+ GNUNET_CRYPTO_short_hash(&priv_pkey, sizeof(priv_pkey), &priv_zone);
+ GNUNET_CRYPTO_short_hash(&short_pkey, sizeof(short_pkey), &short_zone);
+
struct GNUNET_NAMESTORE_RecordData rd;
rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
- rd.data = &bob_hash;
+ rd.data = &priv_zone;
rd.record_type = GNUNET_GNS_RECORD_PKEY;
GNUNET_NAMESTORE_record_create (namestore_handle,
our_key,
- TEST_AUTHORITY_BOB,
+ TEST_PRIVATE_ZONE,
&rd,
- &put_pkey_dht,
+ &cont_init_zone,
NULL);
+
+
}
static void
GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
+ NULL,
&on_lookup_result, TEST_DOMAIN);
}
GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_YES,
+ NULL,
&on_lookup_result, TEST_DOMAIN);
}
AUTOSTART = YES
BINARY = gnunet-service-gns
ZONEKEY = $SERVICEHOME/.hostkey
+PRIVATE_ZONE = private
+PRIVATE_ZONEKEY = $SERVICEHOME/gns/zonekey_priv.zkey
+SHORTEN_ZONE = short
+SHORTEN_ZONEKEY = $SERVICEHOME/gns/zonekey_short.zkey
#ZONEKEY = $SERVICEHOME/gns/zonekey.zkey
HIJACK_DNS = NO
UNIXPATH = /tmp/gnunet-service-gns.sock
GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_MX,
GNUNET_NO,
+ NULL,
&on_lookup_result, TEST_DOMAIN);
}
GNUNET_GNS_lookup(gns_handle, name, GNUNET_GNS_RECORD_TYPE_A,
GNUNET_NO,
+ NULL,
&on_lookup_result, NULL);
}
* @param name the name to look up
* @param type the GNUNET_GNS_RecordType to look for
* @param only_cached GNUNET_NO to only check locally not DHT for performance
+ * @param shorten_key the private key of the shorten zone (can be NULL)
* @param proc function to call on result
* @param proc_cls closure for processor
*
const char * name,
enum GNUNET_GNS_RecordType type,
int only_cached,
+ struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
GNUNET_GNS_LookupResultProcessor proc,
void *proc_cls);
* @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 only_cached GNUNET_NO to only check locally not DHT for performance
+ * @param shorten_key the private key of the shorten zone (can be NULL)
* @param proc function to call on result
* @param proc_cls closure for processor
*
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,
int only_cached,
+ struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
GNUNET_GNS_LookupResultProcessor proc,
void *proc_cls);
* @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
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);