From: Martin Schanzenbach Date: Mon, 11 Jun 2012 14:59:04 +0000 (+0000) Subject: new API for shorten key X-Git-Tag: initial-import-from-subversion-38251~13147 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8338aebe1b4be9e8cb27be564851a14a9ebb6b14;p=oweals%2Fgnunet.git new API for shorten key --- diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in index 6a44ae40c..2fe10ca34 100644 --- a/src/gns/gns.conf.in +++ b/src/gns/gns.conf.in @@ -8,6 +8,7 @@ UNIXPATH = /tmp/gnunet-service-gns.sock 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 diff --git a/src/gns/gns.h b/src/gns/gns.h index 408b68606..80ebb1288 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h @@ -62,6 +62,16 @@ struct GNUNET_GNS_ClientLookupMessage */ 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 */ @@ -120,7 +130,17 @@ struct GNUNET_GNS_ClientShortenMessage * 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 */ }; diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index a92280f25..2cdb58a31 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -640,6 +640,7 @@ get_request_id (struct GNUNET_GNS_Handle *h) * @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 @@ struct GNUNET_GNS_QueueEntry * 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 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, 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_lookup (struct GNUNET_GNS_Handle *handle, 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 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, * @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 @@ struct GNUNET_GNS_QueueEntry * 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 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, 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_shorten (struct GNUNET_GNS_Handle *handle, 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. diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 367eb02ec..eff7fbfbd 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c @@ -269,12 +269,18 @@ static regex_t re_dotplus; /* 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 @@ process_get_authority (void *cls, GNUNET_GNS_lookup_zone (gns_handle, ctask->host, &local_gns_zone, + &local_shorten_zone, GNUNET_GNS_RECORD_LEHO, &process_leho_lookup, ctask); @@ -2254,7 +2261,57 @@ load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg) 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 @@ run (void *cls, char *const *args, const char *cfgfile, return; } + use_shorten = load_local_shorten_key (cfg); + if (NULL == gns_handle) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -2364,7 +2423,7 @@ run (void *cls, char *const *args, const char *cfgfile, &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; } diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 1efe74842..78fe513ec 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -149,6 +149,7 @@ run (void *cls, char *const *args, const char *cfgfile, 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 @@ run (void *cls, char *const *args, const char *cfgfile, } 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 @@ run (void *cls, char *const *args, const char *cfgfile, 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) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 5e2280111..8f8fbe41b 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -60,8 +60,8 @@ struct ClientShortenHandle /* 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 @@ struct ClientLookupHandle /* 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 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } /** - * 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 @@ lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone) 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 @@ lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone) 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 @@ send_shorten_response(void* cls, const char* name) 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 @@ static void handle_shorten(void *cls, 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 @@ static void handle_shorten(void *cls, /* 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 @@ send_lookup_response(void* cls, 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 @@ handle_lookup(void *cls, 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 @@ handle_lookup(void *cls, 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, diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c index 3c2d20420..c6fd28884 100644 --- a/src/gns/test_gns_pseu_shorten.c +++ b/src/gns/test_gns_pseu_shorten.c @@ -90,6 +90,7 @@ struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; 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 @@ process_shorten_result(void* cls, const char* sname) 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 @@ commence_testing (void *cls, int success) "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 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 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; diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index 64dbcd25a..1906aba45 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -146,6 +146,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, * @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 @@ struct GNUNET_GNS_QueueEntry * 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 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, * @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 @@ struct GNUNET_GNS_QueueEntry * 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);