GNUnet  0.10.x
Data Structures | Functions
fs_publish_ublock.c File Reference

publish a UBLOCK in GNUnet More...

#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
#include "fs_publish_ublock.h"
#include "fs_api.h"
#include "fs_tree.h"
Include dependency graph for fs_publish_ublock.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_FS_PublishUblockContext
 Context for 'ublock_put_cont'. More...
 

Functions

static void derive_ublock_encryption_key (struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const char *label, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 Derive the key for symmetric encryption/decryption from the public key and the label. More...
 
void GNUNET_FS_ublock_decrypt_ (const void *input, size_t input_len, const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, const char *label, void *output)
 Decrypt the given UBlock, storing the result in output. More...
 
static void ublock_put_cont (void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
 Continuation of GNUNET_FS_publish_ublock_(). More...
 
static void run_cont (void *cls)
 Run the continuation. More...
 
struct GNUNET_FS_PublishUblockContextGNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, struct GNUNET_DATASTORE_Handle *dsh, const char *label, const char *ulabel, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_BlockOptions *bo, enum GNUNET_FS_PublishOptions options, GNUNET_FS_UBlockContinuation cont, void *cont_cls)
 Publish a UBlock. More...
 
void GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc)
 Abort UBlock publishing operation. More...
 

Detailed Description

publish a UBLOCK in GNUnet

See also
https://gnunet.org/encoding and #2564
Author
Krista Bennett
Christian Grothoff

Definition in file fs_publish_ublock.c.

Function Documentation

◆ derive_ublock_encryption_key()

static void derive_ublock_encryption_key ( struct GNUNET_CRYPTO_SymmetricSessionKey skey,
struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const char *  label,
const struct GNUNET_CRYPTO_EcdsaPublicKey pub 
)
static

Derive the key for symmetric encryption/decryption from the public key and the label.

Parameters
skeywhere to store symmetric key
ivwhere to store the IV
labellabel to use for key derivation
pubpublic key to use for key derivation

Definition at line 46 of file fs_publish_ublock.c.

References GNUNET_assert, GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_kdf(), and GNUNET_YES.

Referenced by GNUNET_FS_publish_ublock_(), and GNUNET_FS_ublock_decrypt_().

50 {
51  struct GNUNET_HashCode key;
52 
53  /* derive key from 'label' and public key of the namespace */
55  GNUNET_CRYPTO_kdf(&key, sizeof(key),
56  "UBLOCK-ENC", strlen("UBLOCK-ENC"),
57  label, strlen(label),
58  pub, sizeof(*pub),
59  NULL, 0));
61 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A 512-bit hashcode.
void GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Convert a hashcode into a key.
Definition: crypto_hash.c:212
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_YES
Definition: gnunet_common.h:77
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_ublock_decrypt_()

void GNUNET_FS_ublock_decrypt_ ( const void *  input,
size_t  input_len,
const struct GNUNET_CRYPTO_EcdsaPublicKey ns,
const char *  label,
void *  output 
)

Decrypt the given UBlock, storing the result in output.

Parameters
inputinput data
input_lennumber of bytes in input
nspublic key under which the UBlock was stored
labellabel under which the UBlock was stored
outputwhere to write the result, has input_len bytes

Definition at line 74 of file fs_publish_ublock.c.

References derive_ublock_encryption_key(), and GNUNET_CRYPTO_symmetric_decrypt().

Referenced by decrypt_block_with_keyword(), process_kblock_for_unindex(), and process_sblock().

79 {
82 
84  label, ns);
85  GNUNET_CRYPTO_symmetric_decrypt(input, input_len,
86  &skey, &iv,
87  output);
88 }
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
static void derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const char *label, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive the key for symmetric encryption/decryption from the public key and the label.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ublock_put_cont()

static void ublock_put_cont ( void *  cls,
int32_t  success,
struct GNUNET_TIME_Absolute  min_expiration,
const char *  msg 
)
static

Continuation of GNUNET_FS_publish_ublock_().

Parameters
clsclosure of type "struct GNUNET_FS_PublishUblockContext*"
successGNUNET_SYSERR on failure (including timeout/queue drop) GNUNET_NO if content was already there GNUNET_YES (or other positive value) on success
min_expirationminimum expiration time required for 0-priority content to be stored by the datacache at this time, zero for unknown, forever if we have no space for 0-priority content
msgNULL on success, otherwise an error message

Definition at line 130 of file fs_publish_ublock.c.

References GNUNET_FS_PublishUblockContext::cont, GNUNET_FS_PublishUblockContext::cont_cls, GNUNET_free, GNUNET_FS_PublishUblockContext::qre, and uc.

Referenced by GNUNET_FS_publish_ublock_().

134 {
135  struct GNUNET_FS_PublishUblockContext *uc = cls;
136 
137  uc->qre = NULL;
138  uc->cont(uc->cont_cls, msg);
139  GNUNET_free(uc);
140 }
GNUNET_FS_UBlockContinuation cont
Function to call when done.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_FS_UnindexContext * uc
struct GNUNET_DATASTORE_QueueEntry * qre
Handle for active datastore operation.
Context for 'ublock_put_cont'.
void * cont_cls
Closure of 'cont'.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ run_cont()

static void run_cont ( void *  cls)
static

Run the continuation.

Parameters
clsthe struct GNUNET_FS_PublishUblockContext *

Definition at line 149 of file fs_publish_ublock.c.

References GNUNET_FS_PublishUblockContext::cont, GNUNET_FS_PublishUblockContext::cont_cls, GNUNET_free, GNUNET_FS_PublishUblockContext::task, and uc.

Referenced by GNUNET_FS_publish_ublock_().

150 {
151  struct GNUNET_FS_PublishUblockContext *uc = cls;
152 
153  uc->task = NULL;
154  uc->cont(uc->cont_cls, NULL);
155  GNUNET_free(uc);
156 }
GNUNET_FS_UBlockContinuation cont
Function to call when done.
static struct GNUNET_FS_UnindexContext * uc
struct GNUNET_SCHEDULER_Task * task
Task to run continuation asynchronously.
Context for 'ublock_put_cont'.
void * cont_cls
Closure of 'cont'.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_FS_publish_ublock_()

struct GNUNET_FS_PublishUblockContext* GNUNET_FS_publish_ublock_ ( struct GNUNET_FS_Handle h,
struct GNUNET_DATASTORE_Handle dsh,
const char *  label,
const char *  ulabel,
const struct GNUNET_CRYPTO_EcdsaPrivateKey ns,
const struct GNUNET_CONTAINER_MetaData meta,
const struct GNUNET_FS_Uri uri,
const struct GNUNET_FS_BlockOptions bo,
enum GNUNET_FS_PublishOptions  options,
GNUNET_FS_UBlockContinuation  cont,
void *  cont_cls 
)

Publish a UBlock.

Parameters
hhandle to the file sharing subsystem
dshdatastore handle to use for storage operation
labelidentifier to use
ulabelupdate label to use, may be an empty string for none
nsnamespace to publish in
metametadata to use
uriURI to refer to in the UBlock
boper-block options
optionspublication options
contcontinuation
cont_clsclosure for cont
Returns
NULL on error (cont will still be called)

Definition at line 176 of file fs_publish_ublock.c.

References _, GNUNET_FS_BlockOptions::anonymity_level, GNUNET_FS_PublishUblockContext::cont, GNUNET_FS_PublishUblockContext::cont_cls, GNUNET_FS_BlockOptions::content_priority, derive_ublock_encryption_key(), GNUNET_FS_BlockOptions::expiration_time, GNUNET_assert, GNUNET_BLOCK_TYPE_FS_UBLOCK, GNUNET_break, GNUNET_CONTAINER_meta_data_get_serialized_size(), GNUNET_CONTAINER_meta_data_serialize(), GNUNET_CONTAINER_META_DATA_SERIALIZE_PART, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_sign(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_DATASTORE_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_FS_uri_to_string(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, MAX_UBLOCK_SIZE, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UBlock::purpose, GNUNET_FS_PublishUblockContext::qre, GNUNET_FS_BlockOptions::replication_level, run_cont(), UBlock::signature, size, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_FS_PublishUblockContext::task, ublock_put_cont(), uc, and UBlock::verification_key.

Referenced by GNUNET_FS_publish_sks(), and publish_ksk_cont().

186 {
188  struct GNUNET_HashCode query;
191  struct GNUNET_CRYPTO_EcdsaPrivateKey *nsd;
193  char *uris;
194  size_t size;
195  char *kbe;
196  char *sptr;
197  ssize_t mdsize;
198  size_t slen;
199  size_t ulen;
200  struct UBlock *ub_plain;
201  struct UBlock *ub_enc;
202 
203  /* compute ublock to publish */
204  if (NULL == meta)
205  mdsize = 0;
206  else
208  GNUNET_assert(mdsize >= 0);
209  uris = GNUNET_FS_uri_to_string(uri);
210  slen = strlen(uris) + 1;
211  if (NULL == ulabel)
212  ulen = 1;
213  else
214  ulen = strlen(ulabel) + 1;
215  size = mdsize + sizeof(struct UBlock) + slen + ulen;
216  if (size > MAX_UBLOCK_SIZE)
217  {
218  size = MAX_UBLOCK_SIZE;
219  mdsize = size - sizeof(struct UBlock) - (slen + ulen);
220  }
221  ub_plain = GNUNET_malloc(size);
222  kbe = (char *)&ub_plain[1];
223  if (NULL != ulabel)
224  GNUNET_memcpy(kbe, ulabel, ulen);
225  kbe += ulen;
226  GNUNET_memcpy(kbe, uris, slen);
227  kbe += slen;
228  GNUNET_free(uris);
229  sptr = kbe;
230  if (NULL != meta)
231  mdsize =
232  GNUNET_CONTAINER_meta_data_serialize(meta, &sptr, mdsize,
234  if (-1 == mdsize)
235  {
236  GNUNET_break(0);
237  GNUNET_free(ub_plain);
238  cont(cont_cls, _("Internal error."));
239  return NULL;
240  }
241  size = sizeof(struct UBlock) + slen + mdsize + ulen;
242 
244  "Publishing under identifier `%s'\n",
245  label);
246  /* get public key of the namespace */
248  &pub);
249  derive_ublock_encryption_key(&skey, &iv,
250  label, &pub);
251 
252  /* encrypt ublock */
253  ub_enc = GNUNET_malloc(size);
254  GNUNET_CRYPTO_symmetric_encrypt(&ub_plain[1],
255  ulen + slen + mdsize,
256  &skey, &iv,
257  &ub_enc[1]);
258  GNUNET_free(ub_plain);
259  ub_enc->purpose.size = htonl(ulen + slen + mdsize +
260  sizeof(struct UBlock)
261  - sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
263 
264  /* derive signing-key from 'label' and public key of the namespace */
265  nsd = GNUNET_CRYPTO_ecdsa_private_key_derive(ns, label, "fs-ublock");
267  &ub_enc->verification_key);
270  &ub_enc->purpose,
271  &ub_enc->signature));
273  sizeof(ub_enc->verification_key),
274  &query);
275  GNUNET_free(nsd);
276 
278  uc->cont = cont;
279  uc->cont_cls = cont_cls;
280  if (NULL != dsh)
281  {
282  uc->qre =
284  0,
285  &query,
286  ulen + slen + mdsize + sizeof(struct UBlock),
287  ub_enc,
289  bo->content_priority,
290  bo->anonymity_level,
291  bo->replication_level,
292  bo->expiration_time,
293  -2, 1,
294  &ublock_put_cont, uc);
295  }
296  else
297  {
299  uc);
300  }
301  GNUNET_free(ub_enc);
302  return uc;
303 }
struct GNUNET_TIME_Absolute expiration_time
At what time should the block expire? Data blocks (DBLOCKS and IBLOCKS) may still be used even if the...
ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size(const struct GNUNET_CONTAINER_MetaData *md)
Get the size of the full meta-data in serialized form.
GNUNET_FS_UBlockContinuation cont
Function to call when done.
ssize_t GNUNET_CONTAINER_meta_data_serialize(const struct GNUNET_CONTAINER_MetaData *md, char **target, size_t max, enum GNUNET_CONTAINER_MetaDataSerializationOptions opt)
Serialize meta-data to target.
If not enough space is available, it is acceptable to only serialize some of the metadata.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h, uint32_t rid, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the datastore.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void ublock_put_cont(void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Continuation of GNUNET_FS_publish_ublock_().
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Private ECC key encoded for transmission.
struct GNUNET_DATASTORE_QueueEntry * qre
Handle for active datastore operation.
#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK
UBlock Signature, done using DSS, not ECC.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2024
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP, >1: with cover traffic).
int GNUNET_CRYPTO_ecdsa_sign(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
Definition: crypto_ecc.c:931
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature using pseudonym and search keyword / identifier.
Definition: block_fs.h:54
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
an ECC signature using ECDSA
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
Type of a block representing any type of search result (universal).
A 512-bit hashcode.
static unsigned int size
Size of the "table".
Definition: peer.c:66
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:241
struct GNUNET_SCHEDULER_Task * task
Task to run continuation asynchronously.
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
Context for 'ublock_put_cont'.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority, non-expired blocks will be kept.
static void run_cont(void *cls)
Run the continuation.
#define MAX_UBLOCK_SIZE
Maximum legal size for a ublock.
Definition: block_fs.h:41
struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_private_key_derive(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *label, const char *context)
Derive a private key from a given private key and a label.
Definition: crypto_ecc.c:1296
static void derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const char *label, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive the key for symmetric encryption/decryption from the public key and the label.
void * cont_cls
Closure of 'cont'.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
What is being signed and why?
Definition: block_fs.h:59
struct GNUNET_CRYPTO_EcdsaPublicKey verification_key
Public key used to sign this block.
Definition: block_fs.h:64
universal block for keyword and namespace search results
Definition: block_fs.h:50
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_publish_ublock_cancel_()

void GNUNET_FS_publish_ublock_cancel_ ( struct GNUNET_FS_PublishUblockContext uc)

Abort UBlock publishing operation.

Parameters
ucoperation to abort.

Definition at line 312 of file fs_publish_ublock.c.

References GNUNET_DATASTORE_cancel(), GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_FS_PublishUblockContext::qre, and GNUNET_FS_PublishUblockContext::task.

Referenced by GNUNET_FS_publish_ksk_cancel(), and GNUNET_FS_publish_sks_cancel().

313 {
314  if (NULL != uc->qre)
316  if (NULL != uc->task)
318  GNUNET_free(uc);
319 }
struct GNUNET_DATASTORE_QueueEntry * qre
Handle for active datastore operation.
struct GNUNET_SCHEDULER_Task * task
Task to run continuation asynchronously.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function: