GNUnet 0.28.0-dev.3-7-g31e20e2e6
 
Loading...
Searching...
No Matches
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_AeadSecretKey *skey, struct GNUNET_CRYPTO_AeadNonce *iv, const char *label, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Derive the key for symmetric encryption/decryption from the public key and the label.
 
void GNUNET_FS_ublock_decrypt_ (const void *input, size_t input_len, const struct GNUNET_CRYPTO_EddsaPublicKey *ns, const char *label, void *output)
 Decrypt the given UBlock, storing the result in output.
 
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_().
 
static void run_cont (void *cls)
 Run the continuation.
 
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_EddsaPrivateKey *ns, const struct GNUNET_FS_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.
 
void GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc)
 Abort UBlock publishing operation.
 

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_AeadSecretKey skey,
struct GNUNET_CRYPTO_AeadNonce iv,
const char *  label,
const struct GNUNET_CRYPTO_EddsaPublicKey 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.

51{
52 struct GNUNET_HashCode key;
53
54 /* derive key from 'label' and public key of the namespace */
57 &key, sizeof(key),
58 "UBLOCK-ENC", strlen ("UBLOCK-ENC"),
59 label, strlen (label),
62}
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
void GNUNET_FS_hash_to_symmetric_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_AeadSecretKey *skey, struct GNUNET_CRYPTO_AeadNonce *nonce)
Definition fs_api.c:3342
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
#define GNUNET_CRYPTO_kdf_arg_auto(d)
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A 512-bit hashcode.

References GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_FS_hash_to_symmetric_key(), GNUNET_YES, key, and pub.

Referenced by GNUNET_FS_publish_ublock_(), and GNUNET_FS_ublock_decrypt_().

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_EddsaPublicKey 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 66 of file fs_publish_ublock.c.

71{
75
77 label, ns);
78 mac = (struct GNUNET_CRYPTO_AeadMac*) (((char*) input) + input_len - sizeof *
79 mac);
80 GNUNET_CRYPTO_aead_decrypt (input_len - sizeof (*mac),
81 input,
82 0,
83 NULL,
84 &skey,
85 &iv,
86 mac,
87 output);
88}
static void derive_ublock_encryption_key(struct GNUNET_CRYPTO_AeadSecretKey *skey, struct GNUNET_CRYPTO_AeadNonce *iv, const char *label, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Derive the key for symmetric encryption/decryption from the public key and the label.
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt(size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
Decrypt the given data using XChaCha20-Poly1305.
type for session keys
unsigned char mac[16]
Initialization vector.
type for session keys

References derive_ublock_encryption_key(), GNUNET_CRYPTO_aead_decrypt(), GNUNET_CRYPTO_AeadMac::mac, and ns.

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

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 131 of file fs_publish_ublock.c.

135{
137
138 uc->qre = NULL;
139 uc->cont (uc->cont_cls, msg);
140 GNUNET_free (uc);
141}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_free(ptr)
Wrapper around free.
Context for 'ublock_put_cont'.

References GNUNET_free, msg, and uc.

Referenced by GNUNET_FS_publish_ublock_().

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 150 of file fs_publish_ublock.c.

151{
153
154 uc->task = NULL;
155 uc->cont (uc->cont_cls, NULL);
156 GNUNET_free (uc);
157}

References GNUNET_free, and uc.

Referenced by GNUNET_FS_publish_ublock_().

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_EddsaPrivateKey ns,
const struct GNUNET_FS_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 161 of file fs_publish_ublock.c.

171{
173 struct GNUNET_HashCode query;
174 struct GNUNET_CRYPTO_AeadNonce iv;
175 struct GNUNET_CRYPTO_AeadSecretKey skey;
178 char *uris;
179 size_t size;
180 char *kbe;
181 char *sptr;
182 ssize_t mdsize;
183 size_t slen;
184 size_t ulen;
185 struct UBlock *ub_plain;
186 struct UBlock *ub_enc;
187
188 /* compute ublock to publish */
189 if (NULL == meta)
190 mdsize = 0;
191 else
193 GNUNET_assert (mdsize >= 0);
195 slen = strlen (uris) + 1;
196 if (NULL == ulabel)
197 ulen = 1;
198 else
199 ulen = strlen (ulabel) + 1;
200 size = mdsize + sizeof(struct UBlock) + slen + ulen;
201 if (size > MAX_UBLOCK_SIZE)
202 {
204 mdsize = size - sizeof(struct UBlock) - (slen + ulen);
205 }
206 ub_plain = GNUNET_malloc (size);
207 kbe = (char *) &ub_plain[1];
208 if (NULL != ulabel)
209 GNUNET_memcpy (kbe, ulabel, ulen);
210 kbe += ulen;
211 GNUNET_memcpy (kbe, uris, slen);
212 kbe += slen;
213 GNUNET_free (uris);
214 sptr = kbe;
215 if (NULL != meta)
216 mdsize =
217 GNUNET_FS_meta_data_serialize (meta, &sptr, mdsize,
219 if (-1 == mdsize)
220 {
221 GNUNET_break (0);
222 GNUNET_free (ub_plain);
223 cont (cont_cls, _ ("Internal error."));
224 return NULL;
225 }
226 size = sizeof(struct UBlock) + slen + mdsize + ulen + sizeof (struct
228
230 "Publishing under identifier `%s'\n",
231 label);
232 /* get public key of the namespace */
234 &pub);
236 label, &pub);
237
238 /* encrypt ublock */
239 {
241 ub_enc = GNUNET_malloc (size);
242 mac = (struct GNUNET_CRYPTO_AeadMac*) (((char*) &ub_enc[1]) + size - sizeof
243 *mac);
244 GNUNET_CRYPTO_aead_encrypt (ulen + slen + mdsize,
245 (unsigned char*) &ub_plain[1],
246 0,
247 NULL,
248 &skey,
249 &iv,
250 &ub_enc[1],
251 mac);
252 }
253 GNUNET_free (ub_plain);
254 ub_enc->purpose.size = htonl (size
255 - sizeof(struct GNUNET_CRYPTO_EddsaSignature));
256 ub_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK);
257
258 /* derive signing-key from 'label' and public key of the namespace */
259 GNUNET_CRYPTO_eddsa_private_key_derive (ns, label, "fs-ublock", &nsd);
261 &ub_enc->verification_key);
264 label,
265 "fs-ublock",
266 &ub_enc->purpose,
267 &ub_enc->signature));
268 GNUNET_CRYPTO_hash (&ub_enc->verification_key,
269 sizeof(ub_enc->verification_key),
270 &query);
271
273 uc->cont = cont;
274 uc->cont_cls = cont_cls;
275 if (NULL != dsh)
276 {
277 uc->qre =
279 0,
280 &query,
281 size,
282 ub_enc,
288 -2, 1,
290 }
291 else
292 {
294 uc);
295 }
296 GNUNET_free (ub_enc);
297 return uc;
298}
static void run_cont(void *cls)
Run the continuation.
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_().
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
static struct GNUNET_FS_BlockOptions bo
Options we set for published blocks.
static struct GNUNET_DATASTORE_Handle * dsh
Datastore handle.
@ GNUNET_BLOCK_TYPE_FS_UBLOCK
Type of a block representing any type of search result (universal).
#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK
UBlock Signature, done using DSS, not ECC (GNUnet-FS)
#define MAX_UBLOCK_SIZE
Maximum legal size for a ublock.
Definition block_fs.h:45
void GNUNET_CRYPTO_eddsa_private_key_derive(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPrivateScalar *result)
Derive a private scalar from a given private key and a label.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition crypto_ecc.c:201
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt(size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
Encrypt the given data using XChaCha20-Poly1305.
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.
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition fs_uri.c:2034
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_derived(const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
This is a signature function for EdDSA which takes a private key and derives it using the label and c...
void GNUNET_CRYPTO_eddsa_key_get_public_from_scalar(const struct GNUNET_CRYPTO_EddsaPrivateScalar *s, struct GNUNET_CRYPTO_EddsaPublicKey *pkey)
Extract the public key of the given private scalar.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
ssize_t GNUNET_FS_meta_data_get_serialized_size(const struct GNUNET_FS_MetaData *md)
Get the size of the full meta-data in serialized form.
Definition meta_data.c:858
ssize_t GNUNET_FS_meta_data_serialize(const struct GNUNET_FS_MetaData *md, char **target, size_t max, enum GNUNET_FS_MetaDataSerializationOptions opt)
Serialize meta-data to target.
Definition meta_data.c:637
@ GNUNET_FS_META_DATA_SERIALIZE_PART
If not enough space is available, it is acceptable to only serialize some of the metadata.
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:1310
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
Private ECC scalar encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using EdDSA.
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP,...
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority,...
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
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...
universal block for keyword and namespace search results
Definition block_fs.h:54

References _, GNUNET_FS_BlockOptions::anonymity_level, bo, GNUNET_FS_BlockOptions::content_priority, derive_ublock_encryption_key(), dsh, GNUNET_FS_BlockOptions::expiration_time, GNUNET_assert, GNUNET_BLOCK_TYPE_FS_UBLOCK, GNUNET_break, GNUNET_CRYPTO_aead_encrypt(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_key_get_public_from_scalar(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_CRYPTO_eddsa_sign_derived(), GNUNET_CRYPTO_hash(), GNUNET_DATASTORE_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_FS_meta_data_get_serialized_size(), GNUNET_FS_meta_data_serialize(), GNUNET_FS_META_DATA_SERIALIZE_PART, GNUNET_FS_uri_to_string(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, GNUNET_CRYPTO_AeadMac::mac, MAX_UBLOCK_SIZE, meta, ns, pub, UBlock::purpose, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_FS_BlockOptions::replication_level, run_cont(), UBlock::signature, GNUNET_CRYPTO_SignaturePurpose::size, size, ublock_put_cont(), uc, uri, and UBlock::verification_key.

Referenced by GNUNET_FS_publish_sks(), and publish_ksk_cont().

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 307 of file fs_publish_ublock.c.

308{
309 if (NULL != uc->qre)
311 if (NULL != uc->task)
313 GNUNET_free (uc);
314}
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986

References GNUNET_DATASTORE_cancel(), GNUNET_free, GNUNET_SCHEDULER_cancel(), and uc.

Referenced by GNUNET_FS_publish_ksk_cancel(), and GNUNET_FS_publish_sks_cancel().

Here is the call graph for this function:
Here is the caller graph for this function: