- namespace_priv_key = GNUNET_RSA_create_key ();
- if (GNUNET_OK != write_namespace_key (cfg, namespace_priv_key))
- {
- GNUNET_RSA_free_key (namespace_priv_key);
- return NULL;
- }
-
- /* create advertisements */
- mdsize = GNUNET_meta_data_get_serialized_size (meta, GNUNET_SERIALIZE_PART);
- size = mdsize + sizeof (GNUNET_EC_SBlock) + strlen (rootEntry) + 2;
- if (size > MAX_SBLOCK_SIZE)
- {
- size = MAX_SBLOCK_SIZE;
- mdsize = size - sizeof (GNUNET_EC_SBlock) - strlen (rootEntry) - 2;
- }
- value = GNUNET_malloc (sizeof (GNUNET_DatastoreValue) + size);
- memset (value, 0, sizeof (GNUNET_DatastoreValue) + size);
- sb = (GNUNET_EC_SBlock *) & value[1];
- sb->type = htonl (GNUNET_ECRS_BLOCKTYPE_SIGNED);
- GNUNET_RSA_get_public_key (namespace_priv_key, &sb->subspace);
- rtgt = (char *) &sb[1];
- memcpy (rtgt, rootEntry, strlen (rootEntry) + 1);
- mdsize = GNUNET_meta_data_serialize (ectx,
- meta,
- &rtgt[strlen (rootEntry) + 2],
- mdsize, GNUNET_SERIALIZE_PART);
- if (mdsize == -1)
- {
- GNUNET_GE_BREAK (ectx, 0);
- GNUNET_RSA_free_key (namespace_priv_key);
- GNUNET_free (value);
- return NULL;
- }
- size = mdsize + sizeof (GNUNET_EC_SBlock) + strlen (rootEntry) + 2;
- GNUNET_GE_ASSERT (ectx,
- GNUNET_OK == GNUNET_RSA_sign (namespace_priv_key,
- size
- -
- sizeof
- (GNUNET_RSA_Signature) -
- sizeof
- (GNUNET_RSA_PublicKey) -
- sizeof (unsigned int),
- &sb->identifier,
- &sb->signature));
- value->size = htonl (sizeof (GNUNET_DatastoreValue) + size);
- value->type = htonl (GNUNET_ECRS_BLOCKTYPE_SIGNED);
- value->priority = htonl (priority);
- value->anonymity_level = htonl (anonymityLevel);
- value->expiration_time = GNUNET_htonll (expiration);
- sock = GNUNET_client_connection_create (ectx, cfg);
- if (sock == NULL)
- {
- GNUNET_free (value);
- GNUNET_RSA_free_key (namespace_priv_key);
- return NULL;
- }
- if (GNUNET_OK != GNUNET_FS_insert (sock, value))
- {
- GNUNET_free (value);
- GNUNET_client_connection_destroy (sock);
- GNUNET_RSA_free_key (namespace_priv_key);
- return NULL;
- }
-
-
- /* publish KNBlocks */
- size += sizeof (GNUNET_EC_KSBlock) - sizeof (GNUNET_EC_SBlock);
- knvalue = GNUNET_malloc (sizeof (GNUNET_DatastoreValue) + size);
- *knvalue = *value;
- knvalue->type = htonl (GNUNET_ECRS_BLOCKTYPE_KEYWORD_SIGNED);
- knvalue->size = htonl (sizeof (GNUNET_DatastoreValue) + size);
- ksb = (GNUNET_EC_KSBlock *) & knvalue[1];
- ksb->type = htonl (GNUNET_ECRS_BLOCKTYPE_KEYWORD_SIGNED);
- memcpy (&ksb->sblock,
- sb, sizeof (GNUNET_EC_SBlock) + mdsize + strlen (rootEntry) + 2);
-
- if (advertisementURI != NULL)
- {
- keywords = advertisementURI->data.ksk.keywords;
- keywordCount = advertisementURI->data.ksk.keywordCount;
- cpy =
- GNUNET_malloc (size - sizeof (GNUNET_EC_KBlock) -
- sizeof (unsigned int));
- memcpy (cpy,
- &ksb->sblock,
- size - sizeof (GNUNET_EC_KBlock) - sizeof (unsigned int));
- for (i = 0; i < keywordCount; i++)
- {
- keyword = keywords[i];
- /* first character of keyword indicates
- mandatory or not -- ignore for hashing! */
- GNUNET_hash (&keyword[1], strlen (&keyword[1]), &hc);
- pk = GNUNET_RSA_create_key_from_hash (&hc);
- GNUNET_RSA_get_public_key (pk, &ksb->kblock.keyspace);
- GNUNET_GE_ASSERT (ectx,
- size - sizeof (GNUNET_EC_KBlock) -
- sizeof (unsigned int) ==
- sizeof (GNUNET_EC_SBlock) + mdsize +
- strlen (rootEntry) + 2);
- GNUNET_ECRS_encryptInPlace (&hc, &ksb->sblock,
- size - sizeof (GNUNET_EC_KBlock) -
- sizeof (unsigned int));
-
- GNUNET_GE_ASSERT (ectx,
- GNUNET_OK == GNUNET_RSA_sign (pk,
- size -
- sizeof
- (GNUNET_EC_KBlock) -
- sizeof (unsigned
- int),
- &ksb->sblock,
- &ksb->
- kblock.signature));
- /* extra check: verify sig */
- GNUNET_RSA_free_key (pk);
- if (GNUNET_OK != GNUNET_FS_insert (sock, knvalue))
- {
- GNUNET_GE_BREAK (ectx, 0);
- GNUNET_free (cpy);
- GNUNET_free (knvalue);
- GNUNET_free (value);
- GNUNET_client_connection_destroy (sock);
- GNUNET_RSA_free_key (namespace_priv_key);
- return NULL;
- }
- /* restore nblock to avoid re-encryption! */
- memcpy (&ksb->sblock,
- cpy,
- size - sizeof (GNUNET_EC_KBlock) - sizeof (unsigned int));
- }
- GNUNET_free (cpy);
- }
- rootURI = GNUNET_malloc (sizeof (URI));
- rootURI->type = sks;
- GNUNET_hash (&sb->subspace,
- sizeof (GNUNET_RSA_PublicKey), &rootURI->data.sks.namespace);
- rootURI->data.sks.identifier = GNUNET_strdup (rootEntry);
- GNUNET_free (knvalue);
- GNUNET_free (value);
- GNUNET_client_connection_destroy (sock);
- GNUNET_RSA_free_key (namespace_priv_key);
-
- return rootURI;