From: Nathan S. Evans Date: Wed, 2 Mar 2011 11:39:01 +0000 (+0000) Subject: Remove useless hostkey dilly-dallying in testing. X-Git-Tag: initial-import-from-subversion-38251~19039 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2838de5efb2c74e0eff4d306c767d6beb668be41;p=oweals%2Fgnunet.git Remove useless hostkey dilly-dallying in testing. --- diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index d9cc27ae0..883664534 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -689,6 +689,16 @@ GNUNET_CRYPTO_kdf (void *result, size_t out_len, */ struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_key_create (void); +/** + * Decode the private key from the data-format back + * to the "normal", internal format. + * + * @param buf the buffer where the private key data is stored + * @param len the length of the data in 'buffer' + */ +struct GNUNET_CRYPTO_RsaPrivateKey * +GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len); + /** * Create a new private key by reading it from a file. If the * files does not exist, create a new key and write it to the diff --git a/src/testing/testing.c b/src/testing/testing.c index 4a321c6e6..7f5ef2a01 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -435,6 +435,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); #endif + /* Fall through */ + case SP_HOSTKEY_CREATED: if (d->hostkey_callback != NULL) { d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); @@ -444,8 +446,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { d->phase = SP_TOPOLOGY_SETUP; } - /* Fall through */ - case SP_HOSTKEY_CREATED: /* wait for topology finished */ if ((GNUNET_YES == d->dead) || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == @@ -903,6 +903,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, char *hostkeyfile; char *temp_file_name; struct GNUNET_DISK_FileHandle *fn; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; + struct GNUNET_CRYPTO_RsaPrivateKey *private_key; ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); @@ -1065,7 +1067,18 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No need to copy configuration file since we are running locally.\n"); #endif - ret->phase = SP_COPIED; + if (hostkey != NULL) /* Get the peer identity from the hostkey */ + { + private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE); + GNUNET_assert(private_key != NULL); + GNUNET_CRYPTO_rsa_key_get_public (private_key, + &public_key); + GNUNET_CRYPTO_hash(&public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey); + ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id)); + ret->phase = SP_HOSTKEY_CREATED; + } + else + ret->phase = SP_COPIED; GNUNET_SCHEDULER_add_continuation (&start_fsm, ret, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index c7b2c16ee..67fd4a7ba 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -380,16 +380,25 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) /** * Decode the private key from the file-format back * to the "normal", internal format. + * + * @param buf the buffer where the private key data is stored + * @param len the length of the data in 'buffer' */ -static struct GNUNET_CRYPTO_RsaPrivateKey * -rsa_decode_key (const struct RsaPrivateKeyBinaryEncoded *encoding) +struct GNUNET_CRYPTO_RsaPrivateKey * +GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) { struct GNUNET_CRYPTO_RsaPrivateKey *ret; + const struct RsaPrivateKeyBinaryEncoded *encoding = (const struct RsaPrivateKeyBinaryEncoded *)buf; gcry_sexp_t res; gcry_mpi_t n, e, d, p, q, u; int rc; size_t size; int pos; + uint16_t enc_len; + + enc_len = ntohs(encoding->len); + if (len != enc_len) + return NULL; pos = 0; size = ntohs (encoding->sizen); @@ -718,7 +727,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs)); len = ntohs (enc->len); ret = NULL; - if ((len != fs) || (NULL == (ret = rsa_decode_key (enc)))) + if ((len != fs) || (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *)enc, len)))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _