diff options
-rw-r--r-- | doc/man/gnunet-ecc.1 | 8 | ||||
-rw-r--r-- | src/datastore/datastore_api.c | 115 | ||||
-rw-r--r-- | src/fs/fs_misc.c | 8 | ||||
-rw-r--r-- | src/fs/fs_publish_ublock.c | 1 | ||||
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 20 | ||||
-rw-r--r-- | src/include/gnunet_getopt_lib.h | 54 | ||||
-rw-r--r-- | src/include/gnunet_json_lib.h | 10 | ||||
-rw-r--r-- | src/json/json_generator.c | 13 | ||||
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 2 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 10 | ||||
-rw-r--r-- | src/util/crypto_ecc.c | 45 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 2 | ||||
-rw-r--r-- | src/util/gnunet-ecc.c | 22 | ||||
-rw-r--r-- | src/util/resolver_api.c | 1 |
14 files changed, 195 insertions, 116 deletions
diff --git a/doc/man/gnunet-ecc.1 b/doc/man/gnunet-ecc.1 index a91a2ac2f7..910687f1f3 100644 --- a/doc/man/gnunet-ecc.1 +++ b/doc/man/gnunet-ecc.1 @@ -19,11 +19,11 @@ Create COUNT public-private key pairs and write them to FILENAME. Used for crea .IP "\-p, \-\-print-public-key" Print the corresponding public key to stdout. This is the value used for PKEY records in GNS. .B -.IP "\-p, \-\-print-hex" -Print the corresponding public key to stdout in HEX format. Useful for comparing to Ed25519 keys in X.509 tools. +.IP "\-P, \-\-print-private-key" +Print the corresponding private key to stdout. This is the value used for PKEY records in GNS. .B -.IP "\-P, \-\-print-peer-identity" -Print the corresponding peer identity (hash of the public key) to stdout. This hash is used for the name of peers. +.IP "\-x, \-\-print-hex" +Print the corresponding public key to stdout in HEX format. Useful for comparing to Ed25519 keys in X.509 tools. .B .IP "\-c FILENAME, \-\-config=FILENAME" Use the configuration file FILENAME. diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 31f7a997f7..2ad864987f 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -651,6 +651,46 @@ process_queue (struct GNUNET_DATASTORE_Handle *h) } +/** + * Get the entry at the head of the message queue. + * + * @param h handle to the datastore + * @param response_type the expected response type + * @return the queue entry + */ +static struct GNUNET_DATASTORE_QueueEntry * +get_queue_head (struct GNUNET_DATASTORE_Handle *h, + uint16_t response_type) +{ + struct GNUNET_DATASTORE_QueueEntry *qe; + + if (h->skip_next_messages > 0) + { + h->skip_next_messages--; + process_queue (h); + return NULL; + } + qe = h->queue_head; + if (NULL == qe) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + if (NULL != qe->env) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + if (response_type != qe->response_type) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + return qe; +} /** @@ -702,30 +742,10 @@ handle_status (void *cls, const char *emsg; int32_t status = ntohl (sm->status); - if (h->skip_next_messages > 0) - { - h->skip_next_messages--; - process_queue (h); - return; - } - if (NULL == (qe = h->queue_head)) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_STATUS != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); + if (NULL == qe) return; - } rc = qe->qc.sc; free_queue_entry (qe); if (ntohs (sm->header.size) > sizeof (struct StatusMessage)) @@ -785,30 +805,10 @@ handle_data (void *cls, struct GNUNET_DATASTORE_QueueEntry *qe; struct ResultContext rc; - if (h->skip_next_messages > 0) - { - process_queue (h); - return; - } - qe = h->queue_head; + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_DATA); if (NULL == qe) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_DATA != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); return; - } #if INSANE_STATISTICS GNUNET_STATISTICS_update (h->stats, gettext_noop ("# Results received"), @@ -854,31 +854,10 @@ handle_data_end (void *cls, struct GNUNET_DATASTORE_QueueEntry *qe; struct ResultContext rc; - if (h->skip_next_messages > 0) - { - h->skip_next_messages--; - process_queue (h); - return; - } - qe = h->queue_head; + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_DATA); if (NULL == qe) - { - GNUNET_break (0); - do_disconnect (h); return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_DATA != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); - return; - } rc = qe->qc.rc; free_queue_entry (qe); LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index bcb8620cfa..b26de431cc 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2010, 2011 GNUnet e.V. + Copyright (C) 2010, 2011, 2017 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -43,6 +43,8 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData {"application/gnunet-directory", ".gnd"}, {"application/java", ".class"}, {"application/msword", ".doc"}, + {"application/nar", ".nar"}, + {"application/narinfo", ".narinfo"}, {"application/ogg", ".ogg"}, {"application/pdf", ".pdf"}, {"application/pgp-keys", ".key"}, @@ -53,8 +55,8 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData {"application/xml", ".xml"}, {"application/x-debian-package", ".deb"}, {"application/x-dvi", ".dvi"}, - {"applixation/x-flac", ".flac"}, - {"applixation/x-gzip", ".gz"}, + {"application/x-flac", ".flac"}, + {"application/x-gzip", ".gz"}, {"application/x-java-archive", ".jar"}, {"application/x-java-vm", ".class"}, {"application/x-python-code", ".pyc"}, diff --git a/src/fs/fs_publish_ublock.c b/src/fs/fs_publish_ublock.c index e21443ccbf..189a6909a2 100644 --- a/src/fs/fs_publish_ublock.c +++ b/src/fs/fs_publish_ublock.c @@ -301,6 +301,7 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, uc->task = GNUNET_SCHEDULER_add_now (&run_cont, uc); } + GNUNET_free (ub_enc); return uc; } diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 07cade0e30..e886a561cd 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1110,6 +1110,16 @@ GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublic /** + * Convert a private key to a string. + * + * @param priv key to convert + * @return string representing @a pub + */ +char * +GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv); + + +/** * Convert a public key to a string. * * @param pub key to convert @@ -2016,13 +2026,14 @@ GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, * @param pkey the public key of the signer * @param[out] buf set to a buffer with the blinded message to be signed * @param[out] buf_size number of bytes stored in @a buf - * @return GNUNET_YES if successful, GNUNET_NO if RSA key is malicious + * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious */ int GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, - char **buf, size_t *buf_size); + char **buf, + size_t *buf_size); /** @@ -2035,7 +2046,8 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, - const void *msg, size_t msg_len); + const void *msg, + size_t msg_len); /** @@ -2105,7 +2117,7 @@ GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig); * @return unblinded signature on success, NULL if RSA key is bad or malicious. */ struct GNUNET_CRYPTO_RsaSignature * -GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_RsaSignature *sig, +GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey); diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index f707bb0919..e38925f147 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h @@ -230,11 +230,11 @@ GNUNET_GETOPT_option_filename (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_base32_fixed_size (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - void *val, - size_t val_size); + const char *name, + const char *argumentHelp, + const char *description, + void *val, + size_t val_size); /** @@ -264,9 +264,9 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag (char shortName, - const char *name, - const char *description, - int *val); + const char *name, + const char *description, + int *val); /** @@ -280,10 +280,10 @@ GNUNET_GETOPT_option_flag (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - unsigned int *val); + const char *name, + const char *argumentHelp, + const char *description, + unsigned int *val); /** @@ -297,10 +297,10 @@ GNUNET_GETOPT_option_uint (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_ulong (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - unsigned long long *val); + const char *name, + const char *argumentHelp, + const char *description, + unsigned long long *val); /** @@ -315,10 +315,10 @@ GNUNET_GETOPT_option_ulong (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_TIME_Relative *val); + const char *name, + const char *argumentHelp, + const char *description, + struct GNUNET_TIME_Relative *val); /** @@ -333,10 +333,10 @@ GNUNET_GETOPT_option_relative_time (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_absolute_time (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_TIME_Absolute *val); + const char *name, + const char *argumentHelp, + const char *description, + struct GNUNET_TIME_Absolute *val); /** @@ -350,9 +350,9 @@ GNUNET_GETOPT_option_absolute_time (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_increment_uint (char shortName, - const char *name, - const char *description, - unsigned int *val); + const char *name, + const char *description, + unsigned int *val); /** diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index f2682bea7d..c12badcd9c 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h @@ -343,6 +343,16 @@ GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); /** + * Convert absolute timestamp to a json string. + * + * @param stamp the time stamp + * @return a json string with the timestamp in @a stamp + */ +json_t * +GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); + + +/** * Convert relative timestamp to a json string. * * @param stamp the time stamp diff --git a/src/json/json_generator.c b/src/json/json_generator.c index e660e10c53..98f7163bcc 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c @@ -73,6 +73,19 @@ GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) /** + * Convert absolute timestamp to a json string. + * + * @param stamp the time stamp + * @return a json string with the timestamp in @a stamp + */ +json_t * +GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp) +{ + return GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (stamp)); +} + + +/** * Convert relative timestamp to a json string. * * @param stamp the time stamp diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 9d077f874d..8281e9a166 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c @@ -509,6 +509,7 @@ transmit_task_cb (void *cls) "Starting set exchange with peer `%s'\n", GNUNET_i2s (&peer_entry->id)); peer_entry->transmit_task = NULL; + GNUNET_assert (NULL == peer_entry->so); peer_entry->so = GNUNET_SET_prepare (&peer_entry->id, &revocation_set_union_app_id, NULL, @@ -758,6 +759,7 @@ handle_revocation_union_request (void *cls, { peer_entry = new_peer_entry (other_peer); } + GNUNET_assert (NULL == peer_entry->so); peer_entry->so = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, (struct GNUNET_SET_Option[]) {{ 0 }}, diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index ec4d821649..6b354df986 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -541,6 +541,13 @@ client_disconnect_cb (void *cls, GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc); + for (struct AddressToStringContext *cur = a2s_head; + NULL != cur; + cur = cur->next) + { + if (cur->tc == tc) + cur->tc = NULL; + } GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); @@ -864,6 +871,8 @@ transmit_address_to_client (void *cls, GNUNET_assert ( (GNUNET_OK == res) || (GNUNET_SYSERR == res) ); + if (NULL == actx->tc) + return; if (NULL == buf) { env = GNUNET_MQ_msg (atsm, @@ -878,6 +887,7 @@ transmit_address_to_client (void *cls, GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); + GNUNET_free (actx); return; } if (GNUNET_SYSERR == res) diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index eaa49a9919..7845932ee7 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -354,6 +354,37 @@ GNUNET_CRYPTO_eddsa_public_key_to_string (const struct GNUNET_CRYPTO_EddsaPublic /** + * Convert a private key to a string. + * + * @param priv key to convert + * @return string representing @a pub + */ +char * +GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) +{ + char *privkeybuf; + size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8; + char *end; + + if (keylen % 5 > 0) + keylen += 5 - keylen % 5; + keylen /= 5; + privkeybuf = GNUNET_malloc (keylen + 1); + end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv, + sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), + privkeybuf, + keylen); + if (NULL == end) + { + GNUNET_free (privkeybuf); + return NULL; + } + *end = '\0'; + return privkeybuf; +} + + +/** * Convert a string representing a public key to a public key. * * @param enc encoded public key @@ -374,9 +405,10 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc, if (enclen != keylen) return GNUNET_SYSERR; - if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, - pub, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, enclen, + pub, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) return GNUNET_SYSERR; return GNUNET_OK; } @@ -403,9 +435,10 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc, if (enclen != keylen) return GNUNET_SYSERR; - if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, - pub, - sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, enclen, + pub, + sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) return GNUNET_SYSERR; return GNUNET_OK; } diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 7a108c21b1..a985d8e596 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -1046,7 +1046,7 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) * @return unblinded signature on success, NULL if RSA key is bad or malicious. */ struct GNUNET_CRYPTO_RsaSignature * -GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_RsaSignature *sig, +GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey) { diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index 42ecc2101d..66a4bd3e91 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c @@ -49,6 +49,11 @@ static unsigned int list_keys_count; static int print_public_key; /** + * Flag for printing private key. + */ +static int print_private_key; + +/** * Flag for printing public key in hex. */ static int print_public_key_hex; @@ -377,7 +382,7 @@ run (void *cls, char *const *args, const char *cfgfile, create_keys (args[0], args[1]); return; } - if (print_public_key || print_public_key_hex) + if (print_public_key || print_public_key_hex || print_private_key) { char *str; struct GNUNET_DISK_FileHandle *keyfile; @@ -388,19 +393,26 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_DISK_PERM_NONE); if (NULL == keyfile) return; - while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) + while (sizeof (pk) == + GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) { GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub); if (print_public_key_hex) { print_hex ("HEX:", &pub, sizeof (pub)); } - else + else if (print_public_key) { str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); FPRINTF (stdout, "%s\n", str); GNUNET_free (str); } + else if (print_private_key) + { + str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk); + FPRINTF (stdout, "%s\n", str); + GNUNET_free (str); + } } GNUNET_DISK_file_close (keyfile); } @@ -438,6 +450,10 @@ main (int argc, "print-public-key", gettext_noop ("print the public key in ASCII format"), &print_public_key), + GNUNET_GETOPT_option_flag ('P', + "print-private-key", + gettext_noop ("print the private key in ASCII format"), + &print_private_key), GNUNET_GETOPT_option_flag ('x', "print-hex", gettext_noop ("print the public key in HEX format"), diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 33a340729d..11b8134d6d 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c @@ -469,6 +469,7 @@ handle_response (void *cls, uint16_t size; char *nret; + GNUNET_assert (NULL != rh); size = ntohs (msg->size); if (size == sizeof (struct GNUNET_MessageHeader)) { |