From dcb57a9e51e8fe7412948ec0c47d383ed390ed61 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 4 Mar 2013 14:09:27 +0000 Subject: add argument to GNUNET_CRYPTO_ecc_decode_key to allow testing to disable key validation --- src/gns/gns.conf.in | 7 +++++++ src/include/gnunet_crypto_lib.h | 6 +++++- src/testing/testing.c | 3 ++- src/util/crypto_ecc.c | 15 ++++++++++----- 4 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in index a6075f346..f2aa1c2c6 100644 --- a/src/gns/gns.conf.in +++ b/src/gns/gns.conf.in @@ -22,6 +22,13 @@ HIJACK_DNS = NO # Automatically import PKEYs we learn into the shorten zone? AUTO_IMPORT_PKEY = YES +# Do we require users that want to access GNS to run this process +# (usually not a good idea) +UNIX_MATCH_UID = NO + +# Do we require users that want to access GNS to be in the 'gnunet' group? +UNIX_MATCH_GID = YES + # When we automatically import PKEYs into shorten zone, require confirmation # before they become active? (Not useful right now as the GUI to confirm # doesn't exist) diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 1bfa988c2..5b6d238c5 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1244,11 +1244,15 @@ GNUNET_CRYPTO_ecc_encode_key (const struct GNUNET_CRYPTO_EccPrivateKey *key); * * @param buf the buffer where the private key data is stored * @param len the length of the data in 'buffer' + * @param validate GNUNET_YES to validate that the key is well-formed, + * GNUNET_NO if the key comes from a totally trusted source + * and validation is considered too expensive * @return NULL on error */ struct GNUNET_CRYPTO_EccPrivateKey * GNUNET_CRYPTO_ecc_decode_key (const char *buf, - size_t len); + size_t len, + int validate); /** diff --git a/src/testing/testing.c b/src/testing/testing.c index 16f902890..826c5753f 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -544,7 +544,8 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, private_key = GNUNET_CRYPTO_ecc_decode_key (system->hostkeys_data + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), - GNUNET_TESTING_HOSTKEYFILESIZE); + GNUNET_TESTING_HOSTKEYFILESIZE, + GNUNET_NO); if (NULL == private_key) { LOG (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 0c9f6e134..d89989bd4 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -325,11 +325,15 @@ GNUNET_CRYPTO_ecc_encode_key (const struct GNUNET_CRYPTO_EccPrivateKey *key) * * @param buf the buffer where the private key data is stored * @param len the length of the data in 'buffer' + * @param validate GNUNET_YES to validate that the key is well-formed, + * GNUNET_NO if the key comes from a totally trusted source + * and validation is considered too expensive * @return NULL on error */ struct GNUNET_CRYPTO_EccPrivateKey * GNUNET_CRYPTO_ecc_decode_key (const char *buf, - size_t len) + size_t len, + int validate) { struct GNUNET_CRYPTO_EccPrivateKey *ret; uint16_t be; @@ -350,8 +354,9 @@ GNUNET_CRYPTO_ecc_decode_key (const char *buf, { LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_scan", rc); return NULL; - } - if (0 != (rc = gcry_pk_testkey (sexp))) + } + if ( (GNUNET_YES == validate) && + (0 != (rc = gcry_pk_testkey (sexp))) ) { LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); return NULL; @@ -451,7 +456,7 @@ try_read_key (const char *filename) char enc[fs]; GNUNET_break (fs == GNUNET_DISK_file_read (fd, enc, fs)); - if (NULL == (ret = GNUNET_CRYPTO_ecc_decode_key ((char *) enc, fs))) + if (NULL == (ret = GNUNET_CRYPTO_ecc_decode_key ((char *) enc, fs, GNUNET_YES))) { LOG (GNUNET_ERROR_TYPE_ERROR, _("File `%s' does not contain a valid private key (failed decode, %llu bytes). Deleting it.\n"), @@ -646,7 +651,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename) len = ntohs (enc->size); ret = NULL; if ((len > fs) || - (NULL == (ret = GNUNET_CRYPTO_ecc_decode_key ((char *) enc, len)))) + (NULL == (ret = GNUNET_CRYPTO_ecc_decode_key ((char *) enc, len, GNUNET_YES)))) { LOG (GNUNET_ERROR_TYPE_ERROR, _("File `%s' does not contain a valid private key. Deleting it.\n"), -- cgit v1.2.3