2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testing/helper.c
23 * @brief helper functions for testing
24 * @author Christian Grothoff
28 #include "gnunet_testing_lib.h"
34 * Obtain the peer identity of the peer with the given configuration
35 * handle. This function reads the private key of the peer, obtains
36 * the public key and hashes it.
38 * @param cfg configuration of the peer
39 * @param pid where to store the peer identity
40 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
43 GNUNET_TESTING_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
44 struct GNUNET_PeerIdentity *pid)
47 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
48 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
51 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
54 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
56 ("Peer is lacking HOSTKEY configuration setting.\n"));
59 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
60 GNUNET_free (keyfile);
61 if (my_private_key == NULL)
63 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
64 _("Could not access hostkey.\n"));
67 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
68 GNUNET_CRYPTO_rsa_key_free (my_private_key);
69 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),