aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-08-30 19:03:53 +0000
committerChristian Grothoff <christian@grothoff.org>2009-08-30 19:03:53 +0000
commit0ed78fc783399971276412dc48130ec5e7256512 (patch)
treefe31f5c135546c119b05d1660b764901dd0cab62 /src
parent5cf21b88fb81906c3da589495da11291d5c12d35 (diff)
downloadgnunet-0ed78fc783399971276412dc48130ec5e7256512.tar.gz
gnunet-0ed78fc783399971276412dc48130ec5e7256512.zip
sblocks
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs.h46
-rw-r--r--src/fs/fs_publish.c267
-rw-r--r--src/fs/fs_uri.c6
3 files changed, 229 insertions, 90 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index f0d9718a2..f13619041 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -493,6 +493,12 @@ struct GNUNET_FS_DownloadContext
493 493
494struct GNUNET_FS_Namespace 494struct GNUNET_FS_Namespace
495{ 495{
496
497 /**
498 * Private key for the namespace.
499 */
500 struct GNUNET_CRYPTO_RsaPrivateKey *key;
501
496 /** 502 /**
497 * Reference counter. 503 * Reference counter.
498 */ 504 */
@@ -527,6 +533,46 @@ struct GNUNET_FS_KBlock
527 533
528}; 534};
529 535
536/**
537 * @brief namespace content block (advertising data under an identifier in a namespace)
538 */
539struct GNUNET_FS_SBlock
540{
541
542 /**
543 * GNUNET_RSA_Signature using RSA-key of the namespace
544 */
545 struct GNUNET_CRYPTO_RsaSignature signature;
546
547 /**
548 * What is being signed and why?
549 */
550 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
551
552 /**
553 * Hash of the hash of the human-readable identifier used for
554 * this entry (the hash of the human-readable identifier is
555 * used as the key for decryption; the xor of this identifier
556 * and the hash of the "keyspace" is the datastore-query hash).
557 */
558 GNUNET_HashCode identifier;
559
560 /**
561 * Public key of the namespace.
562 */
563 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
564
565 /* 0-terminated update-identifier here */
566
567 /* 0-terminated URI here */
568
569 /* variable-size Meta-Data follows here */
570
571};
572
573
574
575
530#endif 576#endif
531 577
532/* end of fs.h */ 578/* end of fs.h */
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index b9bf1dc9c..55541fc33 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -26,7 +26,6 @@
26 * @author Christian Grothoff 26 * @author Christian Grothoff
27 * 27 *
28 * TODO: 28 * TODO:
29 * - SBlocks
30 * - indexing support 29 * - indexing support
31 * - code-sharing with unindex (can wait) 30 * - code-sharing with unindex (can wait)
32 * - persistence support (can wait) 31 * - persistence support (can wait)
@@ -42,9 +41,18 @@
42 41
43#define DEBUG_PUBLISH GNUNET_YES 42#define DEBUG_PUBLISH GNUNET_YES
44 43
44/**
45 * Maximum allowed size for a KBlock.
46 */
45#define MAX_KBLOCK_SIZE 60000 47#define MAX_KBLOCK_SIZE 60000
46 48
47/** 49/**
50 * Maximum allowed size for an SBlock.
51 */
52#define MAX_SBLOCK_SIZE 60000
53
54
55/**
48 * Main function that performs the upload. 56 * Main function that performs the upload.
49 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload 57 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
50 * @param tc task context 58 * @param tc task context
@@ -1200,7 +1208,10 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1200 size = sizeof (struct GNUNET_FS_KBlock) + pkc->slen + pkc->mdsize; 1208 size = sizeof (struct GNUNET_FS_KBlock) + pkc->slen + pkc->mdsize;
1201 1209
1202 pkc->cpy = GNUNET_malloc (size); 1210 pkc->cpy = GNUNET_malloc (size);
1203 pkc->cpy->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + pkc->mdsize + pkc->slen); 1211 pkc->cpy->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1212 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1213 pkc->mdsize +
1214 pkc->slen);
1204 pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK); 1215 pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1205 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); 1216 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1206 GNUNET_SCHEDULER_add_continuation (h->sched, 1217 GNUNET_SCHEDULER_add_continuation (h->sched,
@@ -1212,6 +1223,65 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1212 1223
1213 1224
1214/** 1225/**
1226 * Context for the SKS publication.
1227 */
1228struct PublishSksContext
1229{
1230
1231 /**
1232 * Global FS context.
1233 */
1234 struct GNUNET_FS_Uri *uri;
1235
1236 /**
1237 * Handle to the datastore.
1238 */
1239 struct GNUNET_DATASTORE_Handle *dsh;
1240
1241 /**
1242 * Function to call once we're done.
1243 */
1244 GNUNET_FS_PublishContinuation cont;
1245
1246 /**
1247 * Closure for cont.
1248 */
1249 void *cont_cls;
1250
1251};
1252
1253
1254/**
1255 * Function called by the datastore API with
1256 * the result from the PUT (SBlock) request.
1257 *
1258 * @param cls closure of type "struct PublishSksContext*"
1259 * @param success GNUNET_OK on success
1260 * @param msg error message (or NULL)
1261 */
1262static void
1263sb_put_cont (void *cls,
1264 int success,
1265 const char *msg)
1266{
1267 struct PublishSksContext *psc = cls;
1268
1269 if (NULL != psc->dsh)
1270 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
1271 if (GNUNET_OK != success)
1272 psc->cont (psc->cont_cls,
1273 NULL,
1274 msg);
1275 else
1276 psc->cont (psc->cont_cls,
1277 psc->uri,
1278 NULL);
1279 GNUNET_FS_uri_destroy (psc->uri);
1280 GNUNET_free (psc);
1281}
1282
1283
1284/**
1215 * Publish an SBlock on GNUnet. 1285 * Publish an SBlock on GNUnet.
1216 * 1286 *
1217 * @param h handle to the file sharing subsystem 1287 * @param h handle to the file sharing subsystem
@@ -1240,100 +1310,123 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1240 enum GNUNET_FS_PublishOptions options, 1310 enum GNUNET_FS_PublishOptions options,
1241 GNUNET_FS_PublishContinuation cont, 1311 GNUNET_FS_PublishContinuation cont,
1242 void *cont_cls) 1312 void *cont_cls)
1243{ 1313{
1244#if 0 1314 struct PublishSksContext *psc;
1245 struct GNUNET_ECRS_URI *uri; 1315 struct GNUNET_CRYPTO_AesSessionKey sk;
1246 struct GNUNET_ClientServerConnection *sock; 1316 struct GNUNET_CRYPTO_AesInitializationVector iv;
1247 GNUNET_DatastoreValue *value; 1317 struct GNUNET_FS_Uri *sks_uri;
1248 unsigned int size; 1318 char *uris;
1249 unsigned int mdsize; 1319 size_t size;
1250 struct GNUNET_RSA_PrivateKey *hk; 1320 size_t slen;
1251 GNUNET_EC_SBlock *sb; 1321 size_t nidlen;
1252 char *dstURI; 1322 size_t idlen;
1253 char *destPos; 1323 ssize_t mdsize;
1254 GNUNET_HashCode hc; /* hash of thisId = key */ 1324 struct GNUNET_FS_SBlock *sb;
1255 GNUNET_HashCode hc2; /* hash of hc = identifier */ 1325 struct GNUNET_FS_SBlock *sb_enc;
1256 int ret; 1326 char *dest;
1257 unsigned int nidlen; 1327 GNUNET_HashCode key; /* hash of thisId = key */
1258 1328 GNUNET_HashCode id; /* hash of hc = identifier */
1259 hk = read_namespace_key (cfg, pid); 1329
1260 if (hk == NULL) 1330 uris = GNUNET_FS_uri_to_string (uri);
1261 return NULL; 1331 slen = strlen (uris) + 1;
1262 1332 idlen = strlen (identifier);
1263 /* THEN: construct GNUNET_EC_SBlock */ 1333 if (update == NULL)
1264 dstURI = GNUNET_ECRS_uri_to_string (dstU); 1334 update = "";
1265 mdsize = GNUNET_meta_data_get_serialized_size (md, GNUNET_SERIALIZE_PART); 1335 nidlen = strlen (update) + 1;
1266 if (nextId == NULL) 1336 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta,
1267 nextId = ""; 1337 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1268 nidlen = strlen (nextId) + 1; 1338
1269 size = mdsize + sizeof (GNUNET_EC_SBlock) + strlen (dstURI) + 1 + nidlen; 1339 size = sizeof (struct GNUNET_FS_SBlock) + slen + nidlen + mdsize;
1270 if (size > MAX_SBLOCK_SIZE) 1340 if (size > MAX_SBLOCK_SIZE)
1271 { 1341 {
1272 size = MAX_SBLOCK_SIZE; 1342 size = MAX_SBLOCK_SIZE;
1273 mdsize = 1343 mdsize = size - (sizeof (struct GNUNET_FS_SBlock) + slen + nidlen);
1274 size - (sizeof (GNUNET_EC_SBlock) + strlen (dstURI) + 1 + nidlen);
1275 } 1344 }
1276 value = GNUNET_malloc (sizeof (GNUNET_DatastoreValue) + size); 1345 sb = GNUNET_malloc (sizeof (struct GNUNET_FS_SBlock) + size);
1277 sb = (GNUNET_EC_SBlock *) & value[1]; 1346 dest = (char *) &sb[1];
1278 sb->type = htonl (GNUNET_ECRS_BLOCKTYPE_SIGNED); 1347 memcpy (dest, update, nidlen);
1279 destPos = (char *) &sb[1]; 1348 dest += nidlen;
1280 memcpy (destPos, nextId, nidlen); 1349 memcpy (dest, uris, slen);
1281 destPos += nidlen; 1350 dest += slen;
1282 memcpy (destPos, dstURI, strlen (dstURI) + 1); 1351 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
1283 destPos += strlen (dstURI) + 1; 1352 dest,
1284 mdsize = GNUNET_meta_data_serialize (ectx, 1353 mdsize,
1285 md, 1354 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1286 destPos,
1287 mdsize, GNUNET_SERIALIZE_PART);
1288 if (mdsize == -1) 1355 if (mdsize == -1)
1289 { 1356 {
1290 GNUNET_GE_BREAK (ectx, 0); 1357 GNUNET_break (0);
1291 GNUNET_free (dstURI); 1358 GNUNET_free (uris);
1292 GNUNET_RSA_free_key (hk); 1359 GNUNET_free (sb);
1293 GNUNET_free (value); 1360 cont (cont_cls,
1294 return NULL; 1361 NULL,
1362 _("Internal error."));
1363 return;
1295 } 1364 }
1296 size = sizeof (GNUNET_EC_SBlock) + mdsize + strlen (dstURI) + 1 + nidlen; 1365 size = sizeof (struct GNUNET_FS_SBlock) + mdsize + slen + nidlen;
1297 value->size = htonl (sizeof (GNUNET_DatastoreValue) + size); 1366 sb_enc = GNUNET_malloc (sizeof (struct GNUNET_FS_SBlock) + size);
1298 value->type = htonl (GNUNET_ECRS_BLOCKTYPE_SIGNED); 1367 GNUNET_CRYPTO_hash (identifier, idlen, &key);
1299 value->priority = htonl (priority); 1368 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &id);
1300 value->anonymity_level = htonl (anonymityLevel); 1369 sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1301 value->expiration_time = GNUNET_htonll (expiration); 1370 sks_uri->type = sks;
1302 GNUNET_hash (thisId, strlen (thisId), &hc); 1371 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace);
1303 GNUNET_hash (&hc, sizeof (GNUNET_HashCode), &hc2); 1372 GNUNET_CRYPTO_hash (&sb_enc->subspace,
1304 uri = GNUNET_malloc (sizeof (URI)); 1373 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1305 uri->type = sks; 1374 &sks_uri->data.sks.namespace);
1306 GNUNET_RSA_get_public_key (hk, &sb->subspace); 1375 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
1307 GNUNET_hash (&sb->subspace, 1376 GNUNET_CRYPTO_hash_xor (&id,
1308 sizeof (GNUNET_RSA_PublicKey), &uri->data.sks.namespace); 1377 &sks_uri->data.sks.namespace,
1309 GNUNET_GE_BREAK (ectx, 0 == memcmp (&uri->data.sks.namespace, 1378 &sb_enc->identifier);
1310 pid, sizeof (GNUNET_HashCode))); 1379 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
1311 uri->data.sks.identifier = GNUNET_strdup (thisId); 1380 GNUNET_CRYPTO_aes_encrypt (&sb[1],
1312 GNUNET_hash_xor (&hc2, &uri->data.sks.namespace, &sb->identifier); 1381 size - sizeof (struct GNUNET_FS_SBlock),
1313 GNUNET_ECRS_encryptInPlace (&hc, &sb[1], size - sizeof (GNUNET_EC_SBlock)); 1382 &sk,
1314 GNUNET_GE_ASSERT (ectx, 1383 &iv,
1315 GNUNET_OK == GNUNET_RSA_sign (hk, 1384 &sb_enc[1]);
1316 size 1385 GNUNET_free (sb);
1317 - 1386 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
1318 sizeof 1387 sb_enc->purpose.size = htonl(slen + mdsize + nidlen
1319 (GNUNET_RSA_Signature) - 1388 + sizeof(struct GNUNET_FS_SBlock)
1320 sizeof 1389 - sizeof(struct GNUNET_CRYPTO_RsaSignature));
1321 (GNUNET_RSA_PublicKey) - 1390 GNUNET_assert (GNUNET_OK ==
1322 sizeof (unsigned int), 1391 GNUNET_CRYPTO_rsa_sign (namespace->key,
1323 &sb->identifier, 1392 &sb_enc->purpose,
1324 &sb->signature)); 1393 &sb_enc->signature));
1325 GNUNET_RSA_free_key (hk); 1394 psc = GNUNET_malloc (sizeof(struct PublishSksContext));
1326 sock = GNUNET_client_connection_create (ectx, cfg); 1395 psc->uri = sks_uri;
1327 ret = GNUNET_FS_insert (sock, value); 1396 psc->cont = cont;
1328 if (ret != GNUNET_OK) 1397 psc->cont_cls = cont_cls;
1398 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1329 { 1399 {
1330 GNUNET_free (uri); 1400 GNUNET_free (sb_enc);
1331 uri = NULL; 1401 sb_put_cont (psc,
1402 GNUNET_OK,
1403 NULL);
1404 return;
1405 }
1406 psc->dsh = GNUNET_DATASTORE_connect (h->cfg, h->sched);
1407 if (NULL == psc->dsh)
1408 {
1409 GNUNET_free (sb_enc);
1410 sb_put_cont (psc,
1411 GNUNET_NO,
1412 _("Failed to connect to datastore."));
1413 return;
1332 } 1414 }
1333 GNUNET_client_connection_destroy (sock); 1415
1334 GNUNET_free (value); 1416 GNUNET_DATASTORE_put (psc->dsh,
1335 GNUNET_free (dstURI); 1417 0,
1336#endif 1418 &sb->identifier,
1419 size,
1420 sb_enc,
1421 GNUNET_DATASTORE_BLOCKTYPE_SBLOCK,
1422 priority,
1423 anonymity,
1424 expirationTime,
1425 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1426 &sb_put_cont,
1427 psc);
1428 GNUNET_free (sb_enc);
1337} 1429}
1338 1430
1431
1339/* end of fs_publish.c */ 1432/* end of fs_publish.c */
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 8e69a8425..47bad3454 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -628,11 +628,11 @@ uri_loc_parse (const char *s, char **emsg)
628 goto ERR; 628 goto ERR;
629 } 629 }
630 ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); 630 ass.purpose.size = htonl(sizeof(struct LocUriAssembly));
631 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_NAMESPACE_PLACEMENT); 631 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
632 et.value = exptime; 632 et.value = exptime;
633 ass.exptime = GNUNET_TIME_absolute_hton (et); 633 ass.exptime = GNUNET_TIME_absolute_hton (et);
634 if (GNUNET_OK != 634 if (GNUNET_OK !=
635 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_NAMESPACE_PLACEMENT, 635 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
636 &ass.purpose, 636 &ass.purpose,
637 &sig, 637 &sig,
638 &ass.peer)) 638 &ass.peer))
@@ -847,7 +847,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
847 GNUNET_free (keyfile); 847 GNUNET_free (keyfile);
848 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 848 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
849 ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); 849 ass.purpose.size = htonl(sizeof(struct LocUriAssembly));
850 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_NAMESPACE_PLACEMENT); 850 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
851 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time); 851 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time);
852 ass.fi = baseUri->data.chk; 852 ass.fi = baseUri->data.chk;
853 ass.peer = my_public_key; 853 ass.peer = my_public_key;