aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-15 11:29:41 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-15 11:29:41 +0000
commita841376422f9b5cca49bf551c01ffd62bb386033 (patch)
tree041421959fd23cf82bfb2d8122bce240c5de9cee
parent6923d93ccd83677b6a1ef8bf7d3c82e877122632 (diff)
downloadgnunet-gtk-a841376422f9b5cca49bf551c01ffd62bb386033.tar.gz
gnunet-gtk-a841376422f9b5cca49bf551c01ffd62bb386033.zip
-update gnunet-setup for new GNS crypto (#3001_
)
-rw-r--r--src/setup/gnunet-setup-gns.c203
1 files changed, 99 insertions, 104 deletions
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index beba823a..11820cf4 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -318,11 +318,6 @@ static struct MoveOperationContext *moc_head;
318static struct MoveOperationContext *moc_tail; 318static struct MoveOperationContext *moc_tail;
319 319
320/** 320/**
321 * Name of our zone as a string.
322 */
323static char *zone_as_string;
324
325/**
326 * Handle to the namestore. 321 * Handle to the namestore.
327 */ 322 */
328static struct GNUNET_NAMESTORE_Handle *namestore; 323static struct GNUNET_NAMESTORE_Handle *namestore;
@@ -353,11 +348,6 @@ static struct GNUNET_CRYPTO_EccPrivateKey *pkey;
353static struct GNUNET_CRYPTO_EccPublicKey pubkey; 348static struct GNUNET_CRYPTO_EccPublicKey pubkey;
354 349
355/** 350/**
356 * Short hash of the public key of the zone we are currently editing.
357 */
358static struct GNUNET_CRYPTO_ShortHashCode zone;
359
360/**
361 * Pseudonym of the current zone we are editing. 351 * Pseudonym of the current zone we are editing.
362 */ 352 */
363static char *current_pseudonym; 353static char *current_pseudonym;
@@ -408,7 +398,7 @@ create_qrcode (unsigned int scale)
408 pseu = gtk_entry_get_text (GTK_ENTRY(entry)); 398 pseu = gtk_entry_get_text (GTK_ENTRY(entry));
409 GNUNET_asprintf (&str, 399 GNUNET_asprintf (&str,
410 "gnunet://gns/%s/%s\n", 400 "gnunet://gns/%s/%s\n",
411 zone_as_string, 401 GNUNET_NAMESTORE_z2s (&pubkey),
412 pseu); 402 pseu);
413 if (0 != QRinput_append (qri, 403 if (0 != QRinput_append (qri,
414 QR_MODE_8, 404 QR_MODE_8,
@@ -767,26 +757,13 @@ free_edit_dialog_context (struct EditDialogContext *edc)
767 * Process a record that was stored in the namestore. 757 * Process a record that was stored in the namestore.
768 * 758 *
769 * @param cls closure 759 * @param cls closure
770 * @param zone_key public key of the zone
771 * @param freshness when does the corresponding block in the DHT expire (until
772 * when should we never do a DHT lookup for the same name again)?;
773 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
774 * or the expiration time of the block in the namestore (even if there are zero
775 * records matching the desired record type)
776 * @param name name that is being mapped (at most 255 characters long)
777 * @param rd_count number of entries in 'rd' array 760 * @param rd_count number of entries in 'rd' array
778 * @param rd array of records with data to store 761 * @param rd array of records with data to store
779 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
780 * because the user queried for a particular record type only)
781 */ 762 */
782static void 763static void
783merge_with_existing_records (void *cls, 764merge_with_existing_records (void *cls,
784 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
785 struct GNUNET_TIME_Absolute freshness,
786 const char *name,
787 unsigned int rd_count, 765 unsigned int rd_count,
788 const struct GNUNET_NAMESTORE_RecordData *rd, 766 const struct GNUNET_NAMESTORE_RecordData *rd)
789 const struct GNUNET_CRYPTO_EccSignature *signature)
790{ 767{
791 struct MoveOperationContext *moc = cls; 768 struct MoveOperationContext *moc = cls;
792 struct EditDialogContext *edc = moc->edc; 769 struct EditDialogContext *edc = moc->edc;
@@ -812,12 +789,12 @@ merge_with_existing_records (void *cls,
812 /* FIXME: sanity-check merge... */ 789 /* FIXME: sanity-check merge... */
813 oc = GNUNET_new (struct OperationContext); 790 oc = GNUNET_new (struct OperationContext);
814 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 791 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
815 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 792 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
816 moc->pk, 793 moc->pk,
817 edc->name, 794 edc->name,
818 rd_count + 1, 795 rd_count + 1,
819 rd_new, 796 rd_new,
820 &operation_done_cont, oc); 797 &operation_done_cont, oc);
821 GNUNET_CRYPTO_ecc_key_free (moc->pk); 798 GNUNET_CRYPTO_ecc_key_free (moc->pk);
822 GNUNET_free (moc->data); 799 GNUNET_free (moc->data);
823 GNUNET_free (moc); 800 GNUNET_free (moc);
@@ -826,6 +803,41 @@ merge_with_existing_records (void *cls,
826 803
827 804
828/** 805/**
806 * Process an encrypted that was stored in the namestore for
807 * merging.
808 *
809 * @param cls closure
810 * @param block block to decrypt
811 */
812static void
813decrypt_block_for_merge (void *cls,
814 const struct GNUNET_NAMESTORE_Block *block)
815{
816 struct MoveOperationContext *moc = cls;
817 struct GNUNET_CRYPTO_EccPublicKey pubkey;
818
819 GNUNET_CRYPTO_ecc_key_get_public (moc->pk,
820 &pubkey);
821 if (GNUNET_OK !=
822 GNUNET_NAMESTORE_block_decrypt (block,
823 &pubkey,
824 moc->edc->name,
825 &merge_with_existing_records,
826 moc))
827 {
828 show_error_message (_("Failed to decode existing record in target zone"),
829 _("Failed to add new record."));
830 GNUNET_CRYPTO_ecc_key_free (moc->pk);
831 GNUNET_free (moc->data);
832 free_edit_dialog_context (moc->edc);
833 GNUNET_free (moc);
834 return;
835 }
836}
837
838
839
840/**
829 * The edit dialog completed; update the namestore and the 841 * The edit dialog completed; update the namestore and the
830 * view based on the new values in 'edc'. 842 * view based on the new values in 'edc'.
831 * 843 *
@@ -893,11 +905,11 @@ edit_dialog_continuation (struct EditDialogContext *edc,
893 rd_new[edc->off] = rd_old[rd_count - 1]; 905 rd_new[edc->off] = rd_old[rd_count - 1];
894 oc = GNUNET_new (struct OperationContext); 906 oc = GNUNET_new (struct OperationContext);
895 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 907 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
896 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 908 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
897 pkey, edc->name, 909 pkey, edc->name,
898 rd_count + 1, 910 rd_count + 1,
899 rd_new, 911 rd_new,
900 &operation_done_cont, oc); 912 &operation_done_cont, oc);
901 } 913 }
902 else 914 else
903 { 915 {
@@ -919,11 +931,11 @@ edit_dialog_continuation (struct EditDialogContext *edc,
919 rd_new[edc->off] = rd; 931 rd_new[edc->off] = rd;
920 oc = GNUNET_new (struct OperationContext); 932 oc = GNUNET_new (struct OperationContext);
921 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 933 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
922 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 934 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
923 pkey, edc->name, 935 pkey, edc->name,
924 rd_count, 936 rd_count,
925 rd_new, 937 rd_new,
926 &operation_done_cont, oc); 938 &operation_done_cont, oc);
927 } 939 }
928 else 940 else
929 { 941 {
@@ -933,11 +945,11 @@ edit_dialog_continuation (struct EditDialogContext *edc,
933 rd_new[rd_count] = rd; 945 rd_new[rd_count] = rd;
934 oc = GNUNET_new (struct OperationContext); 946 oc = GNUNET_new (struct OperationContext);
935 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 947 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
936 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 948 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
937 pkey, edc->name, 949 pkey, edc->name,
938 rd_count + 1, 950 rd_count + 1,
939 rd_new, 951 rd_new,
940 &operation_done_cont, oc); 952 &operation_done_cont, oc);
941 } 953 }
942 } 954 }
943 else 955 else
@@ -945,8 +957,7 @@ edit_dialog_continuation (struct EditDialogContext *edc,
945 char *keyfile; 957 char *keyfile;
946 struct GNUNET_CRYPTO_EccPrivateKey *pk; 958 struct GNUNET_CRYPTO_EccPrivateKey *pk;
947 struct MoveOperationContext *moc; 959 struct MoveOperationContext *moc;
948 struct GNUNET_CRYPTO_ShortHashCode target_zone_hash; 960 struct GNUNET_HashCode query;
949 struct GNUNET_CRYPTO_EccPublicKey pubkey;
950 961
951 /* determine target zone */ 962 /* determine target zone */
952 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 963 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
@@ -971,22 +982,20 @@ edit_dialog_continuation (struct EditDialogContext *edc,
971 NULL); 982 NULL);
972 break; 983 break;
973 } 984 }
974 GNUNET_CRYPTO_ecc_key_get_public (pk, &pubkey); 985 GNUNET_NAMESTORE_query_from_private_key (pk,
975 GNUNET_CRYPTO_short_hash (&pubkey, 986 edc->name,
976 sizeof (struct GNUNET_CRYPTO_EccPublicKey), 987 &query);
977 &target_zone_hash);
978 moc = GNUNET_new (struct MoveOperationContext); 988 moc = GNUNET_new (struct MoveOperationContext);
979 moc->data = data; 989 moc->data = data;
980 moc->rd = rd; 990 moc->rd = rd;
981 moc->edc = edc; 991 moc->edc = edc;
982 moc->pk = pk; 992 moc->pk = pk;
983 GNUNET_CONTAINER_DLL_insert (moc_head, moc_tail, moc); 993 GNUNET_CONTAINER_DLL_insert (moc_head, moc_tail, moc);
984 moc->qe = GNUNET_NAMESTORE_lookup_record (namestore, 994
985 &target_zone_hash, 995 moc->qe = GNUNET_NAMESTORE_lookup_block (namestore,
986 edc->name, 996 &query,
987 0 /* all */, 997 &decrypt_block_for_merge,
988 &merge_with_existing_records, 998 moc);
989 moc);
990 /* zone changed, remove record from old zone, add to new zone! */ 999 /* zone changed, remove record from old zone, add to new zone! */
991 if (GNUNET_YES == edc->old_record_in_namestore) 1000 if (GNUNET_YES == edc->old_record_in_namestore)
992 { 1001 {
@@ -998,12 +1007,12 @@ edit_dialog_continuation (struct EditDialogContext *edc,
998 rd_new[edc->off] = rd_old[rd_count - 1]; 1007 rd_new[edc->off] = rd_old[rd_count - 1];
999 oc = GNUNET_new (struct OperationContext); 1008 oc = GNUNET_new (struct OperationContext);
1000 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 1009 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
1001 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 1010 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
1002 pkey, edc->name, 1011 pkey, edc->name,
1003 rd_count - 1, 1012 rd_count - 1,
1004 rd_new, 1013 rd_new,
1005 &operation_done_cont, oc); 1014 &operation_done_cont, oc);
1006 1015
1007 } 1016 }
1008 return; 1017 return;
1009 } 1018 }
@@ -1536,21 +1545,21 @@ GNUNET_setup_gns_main_treeview_key_press_event_cb (GtkWidget *widget,
1536 rd_new[off] = rd_old[ri->rd_count - 1]; 1545 rd_new[off] = rd_old[ri->rd_count - 1];
1537 oc = GNUNET_new (struct OperationContext); 1546 oc = GNUNET_new (struct OperationContext);
1538 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 1547 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
1539 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 1548 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
1540 pkey, name, 1549 pkey, name,
1541 ri->rd_count - 1, 1550 ri->rd_count - 1,
1542 rd_new, 1551 rd_new,
1543 &operation_done_cont, oc); 1552 &operation_done_cont, oc);
1544 g_free (n_value); 1553 g_free (n_value);
1545 } 1554 }
1546 else 1555 else
1547 { 1556 {
1548 oc = GNUNET_new (struct OperationContext); 1557 oc = GNUNET_new (struct OperationContext);
1549 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 1558 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
1550 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 1559 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
1551 pkey, name, 1560 pkey, name,
1552 0, NULL, 1561 0, NULL,
1553 &operation_done_cont, oc); 1562 &operation_done_cont, oc);
1554 } 1563 }
1555 g_free (name); 1564 g_free (name);
1556 1565
@@ -1627,11 +1636,12 @@ GNUNET_setup_gns_pseu_entry_changed_cb (GtkEditable *editable,
1627 } 1636 }
1628 oc = GNUNET_new (struct OperationContext); 1637 oc = GNUNET_new (struct OperationContext);
1629 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc); 1638 GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
1630 oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 1639 oc->qe = GNUNET_NAMESTORE_records_store (namestore,
1631 pkey, "+", 1640 pkey,
1632 total, 1641 GNUNET_GNS_MASTERZONE_STR,
1633 rd_new, 1642 total,
1634 &operation_done_cont, oc); 1643 rd_new,
1644 &operation_done_cont, oc);
1635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1636 "New Pseudonym is `%s' %u\n", 1646 "New Pseudonym is `%s' %u\n",
1637 (char *) pseu, rd_new[off].data_size); 1647 (char *) pseu, rd_new[off].data_size);
@@ -1661,10 +1671,12 @@ GNUNET_setup_gns_public_key_copy_button_clicked_cb (GtkButton *button,
1661{ 1671{
1662 GtkClipboard *cb; 1672 GtkClipboard *cb;
1663 1673
1664 if (NULL == zone_as_string) 1674 if (NULL == pkey)
1665 return; 1675 return;
1666 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); 1676 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1667 gtk_clipboard_set_text (cb, zone_as_string, -1); 1677 gtk_clipboard_set_text (cb,
1678 GNUNET_NAMESTORE_z2s (&pubkey),
1679 -1);
1668} 1680}
1669 1681
1670 1682
@@ -1700,25 +1712,17 @@ zone_sync_proc (void *cls)
1700 * widgets accordingly. 1712 * widgets accordingly.
1701 * 1713 *
1702 * @param NULL 1714 * @param NULL
1703 * @param zone_key public key of the zone 1715 * @param zone_key private key of the zone
1704 * @param freshness when does the corresponding block in the DHT expire (until
1705 * when should we never do a DHT lookup for the same name again)?;
1706 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
1707 * or the expiration time of the block in the namestore (even if there are zero
1708 * records matching the desired record type)
1709 * @param name name that is being mapped (at most 255 characters long) 1716 * @param name name that is being mapped (at most 255 characters long)
1710 * @param rd_count number of entries in 'rd' array 1717 * @param rd_count number of entries in 'rd' array
1711 * @param rd array of records with data to store 1718 * @param rd array of records with data to store
1712 * @param signature signature of the record block, NULL as we are monitoring
1713 */ 1719 */
1714static void 1720static void
1715zone_iteration_proc (void *cls, 1721zone_iteration_proc (void *cls,
1716 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 1722 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
1717 struct GNUNET_TIME_Absolute expire,
1718 const char *name, 1723 const char *name,
1719 unsigned int rd_count, 1724 unsigned int rd_count,
1720 const struct GNUNET_NAMESTORE_RecordData *rd, 1725 const struct GNUNET_NAMESTORE_RecordData *rd)
1721 const struct GNUNET_CRYPTO_EccSignature *signature)
1722{ 1726{
1723 GtkTreeRowReference *rr; 1727 GtkTreeRowReference *rr;
1724 GtkTreePath *path; 1728 GtkTreePath *path;
@@ -1731,7 +1735,6 @@ zone_iteration_proc (void *cls,
1731 gboolean time_is_relative; 1735 gboolean time_is_relative;
1732 gboolean public; 1736 gboolean public;
1733 guint64 exp_t; 1737 guint64 exp_t;
1734 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
1735 GtkEntry *pseu_entry; 1738 GtkEntry *pseu_entry;
1736 struct GNUNET_HashCode name_hash; 1739 struct GNUNET_HashCode name_hash;
1737 struct RecordInfo *ri; 1740 struct RecordInfo *ri;
@@ -1754,10 +1757,9 @@ zone_iteration_proc (void *cls,
1754 name); 1757 name);
1755 return; 1758 return;
1756 } 1759 }
1757 GNUNET_CRYPTO_short_hash_to_enc (&zone, &shenc);
1758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1759 "Zone `%s' iteration result `%s', %u records\n", 1761 "Zone iteration result `%s', %u records\n",
1760 &shenc, name, rd_count); 1762 name, rd_count);
1761 GNUNET_CRYPTO_hash (name, 1763 GNUNET_CRYPTO_hash (name,
1762 strlen (name), 1764 strlen (name),
1763 &name_hash); 1765 &name_hash);
@@ -1919,7 +1921,6 @@ load_zone (const char *zonename)
1919 char *keyfile; 1921 char *keyfile;
1920 struct GNUNET_CRYPTO_EccPrivateKey *pk; 1922 struct GNUNET_CRYPTO_EccPrivateKey *pk;
1921 char *emsg; 1923 char *emsg;
1922 struct GNUNET_CRYPTO_ShortHashAsciiEncoded shenc;
1923 char *label; 1924 char *label;
1924 GtkTreeIter toplevel; 1925 GtkTreeIter toplevel;
1925 1926
@@ -1958,14 +1959,8 @@ load_zone (const char *zonename)
1958 } 1959 }
1959 pkey = pk; 1960 pkey = pk;
1960 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey); 1961 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey);
1961 GNUNET_CRYPTO_short_hash (&pubkey,
1962 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1963 &zone);
1964 GNUNET_CRYPTO_short_hash_to_enc(&zone, &shenc);
1965
1966 zone_as_string = GNUNET_strdup ((char *) &shenc);
1967 label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"), 1962 label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"),
1968 zone_as_string); 1963 GNUNET_NAMESTORE_z2s (&pubkey));
1969 gtk_label_set_markup (GTK_LABEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_label")), 1964 gtk_label_set_markup (GTK_LABEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_label")),
1970 label); 1965 label);
1971 g_free (label); 1966 g_free (label);
@@ -1984,7 +1979,7 @@ load_zone (const char *zonename)
1984#if HAVE_QRENCODE_H 1979#if HAVE_QRENCODE_H
1985 setup_qrcode (); 1980 setup_qrcode ();
1986#endif 1981#endif
1987 zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, &zone, 1982 zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pk,
1988 &zone_iteration_proc, 1983 &zone_iteration_proc,
1989 &zone_sync_proc, 1984 &zone_sync_proc,
1990 NULL); 1985 NULL);