/** * Convert a UTF-8 string to UTF-8 lowercase * @param src source string * @return converted result */ char * GNUNET_GNSRECORD_string_to_lowercase (const char *src) { char *res; res = GNUNET_strdup (src); GNUNET_STRINGS_utf8_tolower (src, res); return res; }
GNUNET_NETWORK_STRUCT_END /** * Convert a UTF-8 string to UTF-8 lowercase * @param src source string * @return converted result */ char * GNUNET_NAMESTORE_normalize_string (const char *src) { GNUNET_assert (NULL != src); char *res = strdup (src); /* normalize */ GNUNET_STRINGS_utf8_tolower(src, &res); return res; }
/** * Handle lookup requests from client * * @param cls the closure * @param client the client * @param message the message */ static void handle_lookup(void *cls, struct GNUNET_SERVER_Client * client, const struct GNUNET_MessageHeader * message) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); size_t msg_size = 0; size_t namelen; char name[MAX_DNS_NAME_LENGTH]; struct ClientLookupHandle *clh; char* nameptr = name; struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; struct GNUNET_CRYPTO_ShortHashCode zone; if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } GNUNET_SERVER_notification_context_add (nc, client); struct GNUNET_GNS_ClientLookupMessage *sh_msg = (struct GNUNET_GNS_ClientLookupMessage *) message; msg_size = ntohs(message->size); if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); namelen = strlen(name)+1; clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); clh->client = client; clh->name = GNUNET_malloc(namelen); strcpy(clh->name, name); clh->unique_id = sh_msg->id; clh->type = ntohl(sh_msg->type); clh->zone_key = NULL; if (strlen (name) > MAX_DNS_NAME_LENGTH) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "LOOKUP: %s is too long", name); clh->name = NULL; send_lookup_response(clh, 0, NULL); return; } if (1 == ntohl(sh_msg->use_default_zone)) zone = zone_hash; //Default zone else zone = sh_msg->zone; if (GNUNET_YES == auto_import_pkey) { if (1 == ntohl(sh_msg->use_default_zone)) key = zone_key; else { key = lookup_private_key(&zone); clh->zone_key = key; } gns_resolver_lookup_record(zone, zone, clh->type, name, key, default_lookup_timeout, &send_lookup_response, clh); } else { gns_resolver_lookup_record(zone, zone, clh->type, name, NULL, default_lookup_timeout, &send_lookup_response, clh); } }
/** * Handle a get authority message from the api * * @param cls the closure * @param client the client * @param message the message */ static void handle_get_authority(void *cls, struct GNUNET_SERVER_Client * client, const struct GNUNET_MessageHeader * message) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH"); size_t msg_size = 0; struct ClientGetAuthHandle *cah; char name[MAX_DNS_NAME_LENGTH]; char* nameptr = name; if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } GNUNET_SERVER_notification_context_add (nc, client); struct GNUNET_GNS_ClientGetAuthMessage *sh_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) message; msg_size = ntohs(message->size); if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); cah->client = client; cah->unique_id = sh_msg->id; if (strlen(name) < strlen(GNUNET_GNS_TLD)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_AUTH: %s is too short. Returning\n", name); cah->name = NULL; send_get_auth_response(cah, name); return; } if (strlen (name) > MAX_DNS_NAME_LENGTH) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GET_AUTH: %s is too long", name); cah->name = NULL; send_get_auth_response(cah, name); return; } if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD), GNUNET_GNS_TLD) != 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_AUTH: %s is not our domain. Returning\n", name); cah->name = NULL; send_get_auth_response(cah, name); return; } if (strcmp(name, GNUNET_GNS_TLD) == 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_AUTH: %s is us. Returning\n", name); cah->name = NULL; send_get_auth_response(cah, name); return; } cah->name = GNUNET_malloc(strlen(name) - strlen(GNUNET_GNS_TLD) + 1); memset(cah->name, 0, strlen(name)-strlen(GNUNET_GNS_TLD) + 1); memcpy(cah->name, name, strlen(name)-strlen(GNUNET_GNS_TLD)); /* Start delegation resolution in our namestore */ gns_resolver_get_authority(zone_hash, zone_hash, name, &send_get_auth_response, cah); }
/** * Handle a shorten message from the api * * @param cls the closure * @param client the client * @param message the 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"); size_t msg_size = 0; 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)) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } struct GNUNET_GNS_ClientShortenMessage *sh_msg = (struct GNUNET_GNS_ClientShortenMessage *) message; msg_size = ntohs(message->size); if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } csh = GNUNET_malloc(sizeof(struct ClientShortenHandle)); csh->client = client; csh->unique_id = sh_msg->id; csh->zone_key = NULL; GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); 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; } if (!is_gnunet_tld(name) && !is_zkey_tld(name)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s is not our domain. Returning\n", name); csh->name = NULL; send_shorten_response(csh, name); return; } GNUNET_SERVER_notification_context_add (nc, client); if (1 == ntohl(sh_msg->use_default_zone)) zone = zone_hash; //Default zone else zone = sh_msg->zone; /* Start shortening */ if (GNUNET_YES == auto_import_pkey) { if (1 == ntohl(sh_msg->use_default_zone)) key = zone_key; else { key = lookup_private_key(&sh_msg->zone); csh->zone_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); }
/** * Function called with the result from the check if the namestore * service is actually running. If it is, we start the actual * operation. * * @param cls closure with our configuration * @param result #GNUNET_YES if the namestore service is running */ static void testservice_task (void *cls, int result) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_GNSRECORD_Data rd; if (GNUNET_YES != result) { FPRINTF (stderr, _("Service `%s' is not running\n"), "namestore"); return; } if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) ) { /* nothing more to be done */ fprintf (stderr, _("No options given\n")); GNUNET_SCHEDULER_shutdown (); return; } GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, &pub); ns = GNUNET_NAMESTORE_connect (cfg); if (NULL == ns) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to namestore\n")); return; } if (add) { if (NULL == name) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-n", _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (NULL == typestring) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-t", _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } type = GNUNET_GNSRECORD_typename_to_number (typestring); if (UINT32_MAX == type) { fprintf (stderr, _("Unsupported type `%s'\n"), typestring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (NULL == value) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-V", _("add")); ret = 1; GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (type, value, &data, &data_size)) { fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), value, typestring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (NULL == expirationstring) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-e", _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (0 == strcmp (expirationstring, "never")) { etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS; etime_is_rel = GNUNET_NO; } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel)) { etime_is_rel = GNUNET_YES; } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs)) { etime_is_rel = GNUNET_NO; } else { fprintf (stderr, _("Invalid time format `%s'\n"), expirationstring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } add_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name, &get_existing_record, NULL ); } if (del) { if (NULL == name) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-n", _("del")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } del_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name, &del_monitor, NULL); } if (list) { list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, &zone_pkey, &display_record, NULL); } if (NULL != reverse_pkey) { struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey, strlen (reverse_pkey), &pubkey)) { fprintf (stderr, _("Invalid public key for reverse lookup `%s'\n"), reverse_pkey); GNUNET_SCHEDULER_shutdown (); } reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns, &zone_pkey, &pubkey, &handle_reverse_lookup, NULL); } if (NULL != uri) { char sh[105]; char sname[64]; struct GNUNET_CRYPTO_EcdsaPublicKey pkey; GNUNET_STRINGS_utf8_tolower (uri, uri); if ( (2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname)) ) || (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)) ) { fprintf (stderr, _("Invalid URI `%s'\n"), uri); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } memset (&rd, 0, sizeof (rd)); rd.data = &pkey; rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; if (GNUNET_YES == etime_is_rel) { rd.expiration_time = etime_rel.rel_value_us; rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; } else if (GNUNET_NO == etime_is_rel) rd.expiration_time = etime_abs.abs_value_us; else rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; if (1 == is_shadow) rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; add_qe_uri = GNUNET_NAMESTORE_records_store (ns, &zone_pkey, sname, 1, &rd, &add_continuation, &add_qe_uri); } if (NULL != nickstring) { if (0 == strlen(nickstring)) { fprintf (stderr, _("Invalid nick `%s'\n"), nickstring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, &zone_pkey, nickstring, &add_continuation, &add_qe_uri); } if (monitor) { zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, &zone_pkey, GNUNET_YES, &display_record, &sync_cb, NULL); } }