/** * If listing is enabled, prints information about the egos. * * This function is initially called for all egos and then again * whenever a ego's identifier changes or if it is deleted. At the * end of the initial pass over all egos, the function is once called * with 'NULL' for 'ego'. That does NOT mean that the callback won't * be invoked in the future or that there was an error. * * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', * this function is only called ONCE, and 'NULL' being passed in * 'ego' does indicate an error (i.e. name is taken or no default * value is known). If 'ego' is non-NULL and if '*ctx' * is set in those callbacks, the value WILL be passed to a subsequent * call to the identity callback of 'GNUNET_IDENTITY_connect' (if * that one was not NULL). * * When an identity is renamed, this function is called with the * (known) ego but the NEW identifier. * * When an identity is deleted, this function is called with the * (known) ego and "NULL" for the 'identifier'. In this case, * the 'ego' is henceforth invalid (and the 'ctx' should also be * cleaned up). * * @param cls closure * @param ego ego handle * @param ctx context for application to store data for this ego * (during the lifetime of this process, initially NULL) * @param identifier identifier assigned by the user for this ego, * NULL if the user just deleted the ego and it * must thus no longer be used */ static void print_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier) { struct GNUNET_CRYPTO_EcdsaPublicKey pk; char *s; if ( (NULL != set_ego) && (NULL != ego) && (NULL != identifier) && (0 == strcmp (identifier, set_ego)) ) { set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL); GNUNET_free (set_subsystem); set_subsystem = NULL; GNUNET_free (set_ego); set_ego = NULL; } if ( (NULL == ego) && (NULL != set_ego) ) { fprintf (stderr, "Could not set ego to `%s' for subsystem `%s', ego not known\n", set_ego, set_subsystem); GNUNET_free (set_subsystem); set_subsystem = NULL; GNUNET_free (set_ego); set_ego = NULL; } if ( (NULL == ego) && (! monitor) ) { GNUNET_SCHEDULER_shutdown (); return; } if (! (list | monitor)) return; if (NULL == ego) return; GNUNET_IDENTITY_ego_get_public_key (ego, &pk); s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); if ( (monitor) || (NULL != identifier) ) fprintf (stdout, "%s - %s\n", identifier, s); GNUNET_free (s); }
/** * Convert public key to the respective absolute domain name in the * ".zkey" pTLD. * This is one of the very few calls in the entire API that is * NOT reentrant! * * @param pkey a public key with a point on the eliptic curve * @return string "X.zkey" where X is the public * key in an encoding suitable for DNS labels. */ const char * GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) { static char ret[128]; char *pkeys; pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string (pkey); GNUNET_snprintf (ret, sizeof (ret), "%s.zkey", pkeys); GNUNET_free (pkeys); return ret; }
/** * Convert the 'value' of a record to a string. * * @param cls closure, unused * @param type type of the record * @param data value in binary encoding * @param data_size number of bytes in @a data * @return NULL on error, otherwise human-readable representation of the value */ static char * gns_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) { const char *cdata; switch (type) { case GNUNET_GNSRECORD_TYPE_PKEY: if (data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) return NULL; return GNUNET_CRYPTO_ecdsa_public_key_to_string (data); case GNUNET_GNSRECORD_TYPE_NICK: return GNUNET_strndup (data, data_size); case GNUNET_GNSRECORD_TYPE_LEHO: return GNUNET_strndup (data, data_size); case GNUNET_GNSRECORD_TYPE_GNS2DNS: { char *ns; char *ip; size_t off; char *nstr; off = 0; ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off); ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off); if ( (NULL == ns) || (NULL == ip) || (off != data_size) ) { GNUNET_break_op (0); GNUNET_free_non_null (ns); GNUNET_free_non_null (ip); return NULL; } GNUNET_asprintf (&nstr, "%s@%s", ns, ip); GNUNET_free_non_null (ns); GNUNET_free_non_null (ip); return nstr; } case GNUNET_GNSRECORD_TYPE_VPN: { const struct GNUNET_TUN_GnsVpnRecord *vpn; char* vpn_str; cdata = data; if ( (data_size <= sizeof (struct GNUNET_TUN_GnsVpnRecord)) || ('\0' != cdata[data_size - 1]) ) return NULL; /* malformed */ vpn = data; GNUNET_asprintf (&vpn_str, "%u %s %s", (unsigned int) ntohs (vpn->proto), (const char*) GNUNET_i2s_full (&vpn->peer), (const char*) &vpn[1]); return vpn_str; } case GNUNET_GNSRECORD_TYPE_BOX: { const struct GNUNET_GNSRECORD_BoxRecord *box; uint32_t rt; char *box_str; char *ival; if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) return NULL; /* malformed */ box = data; rt = ntohl (box->record_type); ival = GNUNET_GNSRECORD_value_to_string (rt, &box[1], data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord)); if (NULL == ival) return NULL; /* malformed */ GNUNET_asprintf (&box_str, "%u %u %u %s", (unsigned int) ntohs (box->protocol), (unsigned int) ntohs (box->service), (unsigned int) rt, ival); GNUNET_free (ival); return box_str; } default: return NULL; } }
/** * Convert the 'value' of a record to a string. * * @param cls closure, unused * @param type type of the record * @param data value in binary encoding * @param data_size number of bytes in @a data * @return NULL on error, otherwise human-readable representation of the value */ static char * gns_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) { const char *cdata; switch (type) { case GNUNET_GNSRECORD_TYPE_PKEY: if (data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) return NULL; return GNUNET_CRYPTO_ecdsa_public_key_to_string (data); case GNUNET_GNSRECORD_TYPE_NICK: return GNUNET_strndup (data, data_size); case GNUNET_GNSRECORD_TYPE_LEHO: return GNUNET_strndup (data, data_size); case GNUNET_GNSRECORD_TYPE_GNS2DNS: { char *ns; char *ip; size_t off; char *nstr; off = 0; ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off); ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off); if ( (NULL == ns) || (NULL == ip) || (off != data_size) ) { GNUNET_break_op (0); GNUNET_free_non_null (ns); GNUNET_free_non_null (ip); return NULL; } GNUNET_asprintf (&nstr, "%s@%s", ns, ip); GNUNET_free_non_null (ns); GNUNET_free_non_null (ip); return nstr; } case GNUNET_GNSRECORD_TYPE_VPN: { struct GNUNET_TUN_GnsVpnRecord vpn; char* vpn_str; cdata = data; if ( (data_size <= sizeof (vpn)) || ('\0' != cdata[data_size - 1]) ) return NULL; /* malformed */ /* need to memcpy for alignment */ memcpy (&vpn, data, sizeof (vpn)); GNUNET_asprintf (&vpn_str, "%u %s %s", (unsigned int) ntohs (vpn.proto), (const char*) GNUNET_i2s_full (&vpn.peer), (const char*) &cdata[sizeof (vpn)]); return vpn_str; } case GNUNET_GNSRECORD_TYPE_BOX: { struct GNUNET_GNSRECORD_BoxRecord box; uint32_t rt; char *box_str; char *ival; cdata = data; if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) return NULL; /* malformed */ memcpy (&box, data, sizeof (box)); rt = ntohl (box.record_type); ival = GNUNET_GNSRECORD_value_to_string (rt, &cdata[sizeof (box)], data_size - sizeof (box)); if (NULL == ival) return NULL; /* malformed */ GNUNET_asprintf (&box_str, "%u %u %u %s", (unsigned int) ntohs (box.protocol), (unsigned int) ntohs (box.service), (unsigned int) rt, ival); GNUNET_free (ival); return box_str; } case GNUNET_GNSRECORD_TYPE_REVERSE: { struct GNUNET_GNSRECORD_ReverseRecord rev; char *rev_str; char *pkey_str; if (data_size < sizeof (struct GNUNET_GNSRECORD_ReverseRecord)) return NULL; /* malformed */ memcpy (&rev, data, sizeof (rev)); cdata = data; pkey_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&rev.pkey); GNUNET_asprintf (&rev_str, "%s %s %"SCNu64, &cdata[sizeof (rev)], pkey_str, rev.expiration.abs_value_us); GNUNET_free (pkey_str); return rev_str; } default: return NULL; } }