diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-11 14:59:04 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-11 14:59:04 +0000 |
commit | 8338aebe1b4be9e8cb27be564851a14a9ebb6b14 (patch) | |
tree | d9b37c09a7bf1226d899671765548d5fe0bad145 /src/gns/gnunet-gns-proxy.c | |
parent | c4ea2585c71c4d619f3f24f32c277a5fa6b5772a (diff) | |
download | gnunet-8338aebe1b4be9e8cb27be564851a14a9ebb6b14.tar.gz gnunet-8338aebe1b4be9e8cb27be564851a14a9ebb6b14.zip |
new API for shorten key
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 61 |
1 files changed, 60 insertions, 1 deletions
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; | |||
269 | /* The users local GNS zone hash */ | 269 | /* The users local GNS zone hash */ |
270 | static struct GNUNET_CRYPTO_ShortHashCode local_gns_zone; | 270 | static struct GNUNET_CRYPTO_ShortHashCode local_gns_zone; |
271 | 271 | ||
272 | /* The users local shorten zone hash */ | ||
273 | static struct GNUNET_CRYPTO_ShortHashCode local_shorten_zone; | ||
274 | |||
272 | /* The CA for SSL certificate generation */ | 275 | /* The CA for SSL certificate generation */ |
273 | static struct ProxyCA proxy_ca; | 276 | static struct ProxyCA proxy_ca; |
274 | 277 | ||
275 | /* UNIX domain socket for mhd */ | 278 | /* UNIX domain socket for mhd */ |
276 | struct GNUNET_NETWORK_Handle *mhd_unix_socket; | 279 | struct GNUNET_NETWORK_Handle *mhd_unix_socket; |
277 | 280 | ||
281 | /* Shorten names? */ | ||
282 | int use_shorten; | ||
283 | |||
278 | /** | 284 | /** |
279 | * Checks if name is in tld | 285 | * Checks if name is in tld |
280 | * | 286 | * |
@@ -1059,6 +1065,7 @@ process_get_authority (void *cls, | |||
1059 | GNUNET_GNS_lookup_zone (gns_handle, | 1065 | GNUNET_GNS_lookup_zone (gns_handle, |
1060 | ctask->host, | 1066 | ctask->host, |
1061 | &local_gns_zone, | 1067 | &local_gns_zone, |
1068 | &local_shorten_zone, | ||
1062 | GNUNET_GNS_RECORD_LEHO, | 1069 | GNUNET_GNS_RECORD_LEHO, |
1063 | &process_leho_lookup, | 1070 | &process_leho_lookup, |
1064 | ctask); | 1071 | ctask); |
@@ -2254,7 +2261,57 @@ load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
2254 | return GNUNET_YES; | 2261 | return GNUNET_YES; |
2255 | } | 2262 | } |
2256 | 2263 | ||
2264 | /** | ||
2265 | * Loads the users local shorten zone key | ||
2266 | * | ||
2267 | * @return GNUNET_YES on success | ||
2268 | */ | ||
2269 | static int | ||
2270 | load_local_shorten_key (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
2271 | { | ||
2272 | char *keyfile; | ||
2273 | struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; | ||
2274 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | ||
2275 | struct GNUNET_CRYPTO_ShortHashCode *zone = NULL; | ||
2276 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; | ||
2277 | |||
2278 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "gns", | ||
2279 | "AUTO_IMPORT_PKEY")) | ||
2280 | { | ||
2281 | return GNUNET_NO; | ||
2282 | } | ||
2257 | 2283 | ||
2284 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
2285 | "AUTO_IMPORT_ZONEKEY", | ||
2286 | &keyfile)) | ||
2287 | { | ||
2288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2289 | "Unable to load zone key config value!\n"); | ||
2290 | return GNUNET_NO; | ||
2291 | } | ||
2292 | |||
2293 | if (GNUNET_NO == GNUNET_DISK_file_test (keyfile)) | ||
2294 | { | ||
2295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2296 | "Unable to load zone key!\n"); | ||
2297 | GNUNET_free(keyfile); | ||
2298 | return GNUNET_NO; | ||
2299 | } | ||
2300 | |||
2301 | key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
2302 | GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); | ||
2303 | GNUNET_CRYPTO_short_hash(&pkey, | ||
2304 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
2305 | &local_shorten_zone); | ||
2306 | zone = &local_gns_zone; | ||
2307 | GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename); | ||
2308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2309 | "Using shorten zone: %s!\n", &zonename); | ||
2310 | GNUNET_CRYPTO_rsa_key_free(key); | ||
2311 | GNUNET_free(keyfile); | ||
2312 | |||
2313 | return GNUNET_YES; | ||
2314 | } | ||
2258 | 2315 | ||
2259 | /** | 2316 | /** |
2260 | * Main function that will be run | 2317 | * Main function that will be run |
@@ -2299,6 +2356,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
2299 | return; | 2356 | return; |
2300 | } | 2357 | } |
2301 | 2358 | ||
2359 | use_shorten = load_local_shorten_key (cfg); | ||
2360 | |||
2302 | if (NULL == gns_handle) | 2361 | if (NULL == gns_handle) |
2303 | { | 2362 | { |
2304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2363 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -2364,7 +2423,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
2364 | &proxy_sockfile)) | 2423 | &proxy_sockfile)) |
2365 | { | 2424 | { |
2366 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2425 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2367 | "Specify PROXY_UNIX_SOCK in gns-proxy config section!\n"); | 2426 | "Specify PROXY_UNIXPATH in gns-proxy config section!\n"); |
2368 | return; | 2427 | return; |
2369 | } | 2428 | } |
2370 | 2429 | ||