*/
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
#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);
{
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 ==
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);
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);
/**
* 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);
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,
_