-fixes
authorChristian Grothoff <christian@grothoff.org>
Tue, 19 Jun 2012 07:57:02 +0000 (07:57 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 19 Jun 2012 07:57:02 +0000 (07:57 +0000)
src/include/gnunet_crypto_lib.h
src/testing/gnunet-testing.c

index 879b1cae20deadecf0e1de5b8dd4ca8381c2367e..33842fc2734f28fba032adf0c9253dacbf68bfcc 100644 (file)
@@ -895,12 +895,12 @@ GNUNET_CRYPTO_rsa_public_key_from_string (const char *enc,
 /**
  * Encode the private key in a format suitable for
  * storing it into a file.
- * @returns encoding of the private key.
- *    The first 4 bytes give the size of the array, as usual.
+ * @return encoding of the private key
  */
 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *
 GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey);
 
+
 /**
  * Decode the private key from the data-format back
  * to the "normal", internal format.
@@ -911,6 +911,7 @@ GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
 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
index a84c512a72cf83c8519989a82f640f08a0a1aa8b..bce0c75221f835d3c22162bf643d46040f46c141 100644 (file)
@@ -27,8 +27,8 @@
 #include "gnunet_util_lib.h"
 #include "gnunet_testing_lib-new.h"
 
-#define HOSTKEYFILESIZE 914
 
+#define HOSTKEYFILESIZE 914
 
 /**
  * Final status code.
@@ -122,20 +122,28 @@ create_hostkeys (const unsigned int no)
   struct GNUNET_PeerIdentity id;
   struct GNUNET_DISK_FileHandle *fd;
   struct GNUNET_CRYPTO_RsaPrivateKey *pk;
+  struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkb;
 
   system = GNUNET_TESTING_system_create ("testing", NULL);
   pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
+  if (NULL == pk)
+  {
+    fprintf (stderr, _("Could not extract hostkey %u (offset too large?)\n"), create_no);
+    return 1;
+  }
   fd = GNUNET_DISK_file_open (create_hostkey,
                              GNUNET_DISK_OPEN_READWRITE |
                              GNUNET_DISK_OPEN_CREATE,
                              GNUNET_DISK_PERM_USER_READ |
                              GNUNET_DISK_PERM_USER_WRITE);
   GNUNET_assert (fd != NULL);
+  pkb = GNUNET_CRYPTO_rsa_encode_key (pk);
   GNUNET_assert (HOSTKEYFILESIZE ==
-                GNUNET_DISK_file_write (fd, pk, HOSTKEYFILESIZE));
+                GNUNET_DISK_file_write (fd, pkb, ntohs (pkb->len)));
   GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
                   "Wrote hostkey to file: `%s'\n", create_hostkey);
+  GNUNET_free (pkb);
   GNUNET_CRYPTO_rsa_key_free (pk);
   return 0;
 }