GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
fs_publish_ublock.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2012, 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
28#include "platform.h"
29#include "gnunet_constants.h"
30#include "gnunet_signatures.h"
31#include "fs_publish_ublock.h"
32#include "fs_api.h"
33#include "fs_tree.h"
34
35
45static void
48 *iv,
49 const char *label,
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}
63
64
65void
66GNUNET_FS_ublock_decrypt_ (const void *input,
67 size_t input_len,
68 const struct GNUNET_CRYPTO_EddsaPublicKey *ns,
69 const char *label,
70 void *output)
71{
75
76 if (input_len < sizeof *mac)
77 return;
79 label, ns);
80 mac = (struct GNUNET_CRYPTO_AeadMac*) (((char*) input)
81 + input_len
82 - sizeof *mac);
83 GNUNET_CRYPTO_aead_decrypt (input_len - sizeof (*mac),
84 input,
85 0,
86 NULL,
87 &skey,
88 &iv,
89 mac,
90 output);
91}
92
93
119
120
133static void
135 int32_t success,
137 const char *msg)
138{
140
141 uc->qre = NULL;
142 uc->cont (uc->cont_cls, msg);
143 GNUNET_free (uc);
144}
145
146
152static void
153run_cont (void *cls)
154{
156
157 uc->task = NULL;
158 uc->cont (uc->cont_cls, NULL);
159 GNUNET_free (uc);
160}
161
162
166 const char *label,
167 const char *ulabel,
168 const struct GNUNET_CRYPTO_EddsaPrivateKey *ns,
169 const struct GNUNET_FS_MetaData *meta,
170 const struct GNUNET_FS_Uri *uri,
171 const struct GNUNET_FS_BlockOptions *bo,
174{
176 struct GNUNET_HashCode query;
177 struct GNUNET_CRYPTO_AeadNonce iv;
178 struct GNUNET_CRYPTO_AeadSecretKey skey;
181 char *uris;
182 size_t size;
183 char *kbe;
184 char *sptr;
185 ssize_t mdsize;
186 size_t slen;
187 size_t ulen;
188 struct UBlock *ub_plain;
189 struct UBlock *ub_enc;
190
191 /* compute ublock to publish */
192 if (NULL == meta)
193 mdsize = 0;
194 else
196 GNUNET_assert (mdsize >= 0);
198 slen = strlen (uris) + 1;
199 if (NULL == ulabel)
200 ulen = 1;
201 else
202 ulen = strlen (ulabel) + 1;
203 size = mdsize + sizeof(struct UBlock) + slen + ulen;
204 if (size > MAX_UBLOCK_SIZE)
205 {
207 mdsize = size - sizeof(struct UBlock) - (slen + ulen);
208 }
209 ub_plain = GNUNET_malloc (size);
210 kbe = (char *) &ub_plain[1];
211 if (NULL != ulabel)
212 GNUNET_memcpy (kbe, ulabel, ulen);
213 kbe += ulen;
214 GNUNET_memcpy (kbe, uris, slen);
215 kbe += slen;
216 GNUNET_free (uris);
217 sptr = kbe;
218 if (NULL != meta)
219 mdsize =
220 GNUNET_FS_meta_data_serialize (meta, &sptr, mdsize,
222 if (-1 == mdsize)
223 {
224 GNUNET_break (0);
225 GNUNET_free (ub_plain);
226 cont (cont_cls, _ ("Internal error."));
227 return NULL;
228 }
229 size = sizeof(struct UBlock) + slen + mdsize + ulen + sizeof (struct
231
233 "Publishing under identifier `%s'\n",
234 label);
235 /* get public key of the namespace */
237 &pub);
239 label, &pub);
240
241 /* encrypt ublock */
242 {
244 ub_enc = GNUNET_malloc (size);
245 mac = (struct GNUNET_CRYPTO_AeadMac*) (((char*) ub_enc) + size - sizeof *mac
246 );
247 GNUNET_CRYPTO_aead_encrypt (ulen + slen + mdsize,
248 (unsigned char*) &ub_plain[1],
249 0,
250 NULL,
251 &skey,
252 &iv,
253 &ub_enc[1],
254 mac);
255 }
256 GNUNET_free (ub_plain);
257 ub_enc->purpose.size = htonl (size
258 - sizeof(struct GNUNET_CRYPTO_EddsaSignature));
260
261 /* derive signing-key from 'label' and public key of the namespace */
262 GNUNET_CRYPTO_eddsa_private_key_derive (ns, label, "fs-ublock", &nsd);
264 &ub_enc->verification_key);
267 label,
268 "fs-ublock",
269 &ub_enc->purpose,
270 &ub_enc->signature));
272 sizeof(ub_enc->verification_key),
273 &query);
274
276 uc->cont = cont;
277 uc->cont_cls = cont_cls;
278 if (NULL != dsh)
279 {
280 uc->qre =
282 0,
283 &query,
284 size,
285 ub_enc,
291 -2, 1,
293 }
294 else
295 {
297 uc);
298 }
299 GNUNET_free (ub_enc);
300 return uc;
301}
302
303
309void
311{
312 if (NULL != uc->qre)
314 if (NULL != uc->task)
316 GNUNET_free (uc);
317}
318
319
320/* end of fs_publish_ublock.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MessageHeader * msg
Definition 005.c:2
shared definitions for the FS library
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 void run_cont(void *cls)
Run the continuation.
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.
void GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc)
Abort UBlock publishing operation.
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_().
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.
publish a UBLOCK in GNUnet
void(* GNUNET_FS_UBlockContinuation)(void *cls, const char *emsg)
Signature of a function called as the continuation of a UBlock publication.
Merkle-tree-ish-CHK file encoding for GNUnet.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
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_CRYPTO_EddsaPublicKey pub
static struct GNUNET_TIME_Absolute min_expiration
Minimum time that content should have to not be discarded instantly (time stamp of any content that w...
static struct GNUNET_DATASTORE_Handle * dsh
Datastore handle.
static struct GNUNET_FS_UnindexContext * uc
@ 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_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.
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.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
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.
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
GNUNET_FS_PublishOptions
Options for publishing.
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_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
#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_CRYPTO_kdf_arg_auto(d)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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.
#define GNUNET_free(ptr)
Wrapper around free.
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
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
type for session keys
unsigned char mac[16]
Initialization vector.
type for session keys
Private ECC key encoded for transmission.
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 purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Handle to the datastore service.
Entry in our priority queue.
Settings for publishing a block (which may of course also apply to an entire directory or file).
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...
Master context for most FS operations.
Definition fs_api.h:1083
Meta data to associate with a file, directory or namespace.
Definition meta_data.c:92
Context for 'ublock_put_cont'.
struct GNUNET_DATASTORE_QueueEntry * qre
Handle for active datastore operation.
void * cont_cls
Closure of 'cont'.
struct GNUNET_SCHEDULER_Task * task
Task to run continuation asynchronously.
GNUNET_FS_UBlockContinuation cont
Function to call when done.
A Universal Resource Identifier (URI), opaque.
Definition fs_api.h:167
A 512-bit hashcode.
Entry in list of pending tasks.
Definition scheduler.c:141
Time for absolute times used by GNUnet, in microseconds.
universal block for keyword and namespace search results
Definition block_fs.h:54
struct GNUNET_CRYPTO_EddsaSignature signature
Signature using pseudonym and search keyword / identifier.
Definition block_fs.h:58
struct GNUNET_CRYPTO_SignaturePurpose purpose
What is being signed and why?
Definition block_fs.h:63
struct GNUNET_CRYPTO_EddsaPublicKey verification_key
Public key used to sign this block.
Definition block_fs.h:68