aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-23 13:30:13 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-23 13:30:13 +0000
commitcaeb00729a53df887361d6ebaa51524dfad97732 (patch)
treea2a4c51b60f80d6bb10460a757bcf76e27c3baaa
parent958ba73f8246d42a1a92501eb6b16d3e44b471a5 (diff)
downloadgnunet-caeb00729a53df887361d6ebaa51524dfad97732.tar.gz
gnunet-caeb00729a53df887361d6ebaa51524dfad97732.zip
-start to integrate identity service with gnunet-gns command-line tool
-rw-r--r--doc/man/gnunet-gns.116
-rw-r--r--src/gns/Makefile.am3
-rw-r--r--src/gns/gns.conf.in6
-rw-r--r--src/gns/gnunet-gns.c198
4 files changed, 177 insertions, 46 deletions
diff --git a/doc/man/gnunet-gns.1 b/doc/man/gnunet-gns.1
index e5e2240b9..2e45ee065 100644
--- a/doc/man/gnunet-gns.1
+++ b/doc/man/gnunet-gns.1
@@ -1,4 +1,4 @@
1.TH GNUNET\-GNS 1 "Aug 8, 2013" "GNUnet" 1.TH GNUNET\-GNS 1 "Aug 23, 2013" "GNUnet"
2 2
3.SH NAME 3.SH NAME
4gnunet\-gns \- Access to GNUnet Name Service 4gnunet\-gns \- Access to GNUnet Name Service
@@ -22,9 +22,9 @@ This is a quiet mode where only important information is displayed.
22For example a lookup for an IP address will only yield the IP address, no 22For example a lookup for an IP address will only yield the IP address, no
23descriptive text. 23descriptive text.
24.B 24.B
25.IP "\-t RRTYPE, \-\-type=RRTYPE" 25.IP "\-t TYPE, \-\-type=TYPE"
26Resource Record Type (RRTYPE) to look for. 26Resource Record Type (TYPE) to look for.
27Supported RRTYPE's are: A, AAAA, CNAME, NS, PKEY, PSEU, TLSA, SRV, SOA, MX, LEHO, VPN, REV, PTR, TXT 27Supported TYPE's are: A, AAAA, CNAME, NS, PKEY, PSEU, TLSA, SRV, SOA, MX, LEHO, VPN, REV, PTR, TXT
28 28
29Defaults to "A". 29Defaults to "A".
30.B 30.B
@@ -38,6 +38,12 @@ Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR.
38Name to lookup. 38Name to lookup.
39Resolve the specified name using the GNUnet Name System. 39Resolve the specified name using the GNUnet Name System.
40.B 40.B
41.IP "\-p PKEY, \-\-public-key=PKEY"
42Public key of the zone to perform the lookup in. This option should be used if the lookup is to be performed against a zone not controlled by this peer (alternatively, you could pass a ".zkey" for the name).
43.B
44.IP "\-z NAME, \-\-zone=NAME"
45Name of the ego of the zone to lookup the record in. The public key associated with the ego will be used for the zone.
46.B
41.IP "\-v, \-\-version" 47.IP "\-v, \-\-version"
42Print GNUnet version number. 48Print GNUnet version number.
43.B 49.B
@@ -48,4 +54,4 @@ Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic
48 54
49 55
50.SH "SEE ALSO" 56.SH "SEE ALSO"
51\fBgnunet\-namestore\fP(1) 57\fBgnunet\-namestore\fP(1), \fBgnunet\-identity\fP(1)
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index c2e4264b5..7f1ceab21 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -74,8 +74,9 @@ gnunet_gns_SOURCES = \
74 gnunet-gns.c 74 gnunet-gns.c
75gnunet_gns_LDADD = \ 75gnunet_gns_LDADD = \
76 $(top_builddir)/src/gns/libgnunetgns.la \ 76 $(top_builddir)/src/gns/libgnunetgns.la \
77 $(top_builddir)/src/util/libgnunetutil.la \
78 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 77 $(top_builddir)/src/namestore/libgnunetnamestore.la \
78 $(top_builddir)/src/identity/libgnunetidentity.la \
79 $(top_builddir)/src/util/libgnunetutil.la \
79 $(GN_LIBINTL) 80 $(GN_LIBINTL)
80gnunet_gns_DEPENDENCIES = \ 81gnunet_gns_DEPENDENCIES = \
81 libgnunetgns.la 82 libgnunetgns.la
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index f336e6a41..2c1fa9ccc 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -8,12 +8,6 @@ UNIXPATH = /tmp/gnunet-service-gns.sock
8 8
9ZONE_DIR = $SERVICEHOME/gns/ 9ZONE_DIR = $SERVICEHOME/gns/
10 10
11# Where to store the key for the Master zone
12ZONEKEY = $SERVICEHOME/gns/zonekey.zkey
13
14# Where to store the key for the Private zone
15PRIVATE_ZONEKEY = $SERVICEHOME/gns/zonekey_priv.zkey
16
17# Where to store the key for the Shorten zone 11# Where to store the key for the Shorten zone
18SHORTEN_ZONEKEY = $SERVICEHOME/gns/zonekey_short.zkey 12SHORTEN_ZONEKEY = $SERVICEHOME/gns/zonekey_short.zkey
19 13
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index c1944c1e2..881b88810 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -21,15 +21,20 @@
21 * @file gnunet-gns.c 21 * @file gnunet-gns.c
22 * @brief command line tool to access distributed GNS 22 * @brief command line tool to access distributed GNS
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 *
25 */ 24 */
26#include "platform.h" 25#include "platform.h"
27#include <gnunet_util_lib.h> 26#include <gnunet_util_lib.h>
28#include <gnunet_dnsparser_lib.h> 27#include <gnunet_dnsparser_lib.h>
28#include <gnunet_identity_service.h>
29#include <gnunet_namestore_service.h> 29#include <gnunet_namestore_service.h>
30#include <gnunet_gns_service.h> 30#include <gnunet_gns_service.h>
31 31
32/** 32/**
33 * Configuration we are using.
34 */
35static const struct GNUNET_CONFIGURATION_Handle *cfg;
36
37/**
33 * Handle to GNS service. 38 * Handle to GNS service.
34 */ 39 */
35static struct GNUNET_GNS_Handle *gns; 40static struct GNUNET_GNS_Handle *gns;
@@ -45,6 +50,16 @@ static char *lookup_name;
45static char *lookup_type; 50static char *lookup_type;
46 51
47/** 52/**
53 * Identity of the zone to use for the lookup (-z option)
54 */
55static char *zone_ego_name;
56
57/**
58 * Public key of the zone to use for the lookup (-p option)
59 */
60static char *public_key;
61
62/**
48 * raw output 63 * raw output
49 */ 64 */
50static int raw; 65static int raw;
@@ -59,6 +74,11 @@ static int rtype;
59 */ 74 */
60static struct GNUNET_GNS_LookupRequest *lookup_request; 75static struct GNUNET_GNS_LookupRequest *lookup_request;
61 76
77/**
78 * Handle to the identity service.
79 */
80static struct GNUNET_IDENTITY_Handle *identity;
81
62 82
63/** 83/**
64 * Task run on shutdown. Cleans up everything. 84 * Task run on shutdown. Cleans up everything.
@@ -70,6 +90,11 @@ static void
70do_shutdown (void *cls, 90do_shutdown (void *cls,
71 const struct GNUNET_SCHEDULER_TaskContext *tc) 91 const struct GNUNET_SCHEDULER_TaskContext *tc)
72{ 92{
93 if (NULL != identity)
94 {
95 GNUNET_IDENTITY_disconnect (identity);
96 identity = NULL;
97 }
73 if (NULL != lookup_request) 98 if (NULL != lookup_request)
74 { 99 {
75 GNUNET_GNS_lookup_cancel (lookup_request); 100 GNUNET_GNS_lookup_cancel (lookup_request);
@@ -128,43 +153,17 @@ process_lookup_result (void *cls, uint32_t rd_count,
128 153
129 154
130/** 155/**
131 * Main function that will be run. 156 * Perform the actual resolution, starting with the zone
157 * identified by the given public key.
132 * 158 *
133 * @param cls closure 159 * @param pkey public key to use for the zone
134 * @param args remaining command-line arguments
135 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
136 * @param cfg configuration
137 */ 160 */
138static void 161static void
139run (void *cls, char *const *args, const char *cfgfile, 162lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey)
140 const struct GNUNET_CONFIGURATION_Handle *cfg)
141{ 163{
142 char *keyfile; 164 char *keyfile;
143 struct GNUNET_CRYPTO_EccPrivateKey *key;
144 struct GNUNET_CRYPTO_EccPublicKey pkey;
145 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key; 165 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
146 166
147 gns = GNUNET_GNS_connect (cfg);
148 if (NULL == gns)
149 {
150 fprintf (stderr,
151 _("Failed to connect to GNS\n"));
152 return;
153 }
154 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
155 "ZONEKEY", &keyfile))
156 {
157 fprintf (stderr,
158 "Need zone to perform lookup in!\n");
159 GNUNET_SCHEDULER_shutdown ();
160 return;
161 }
162 /* FIXME: use identity service and/or allow user to specify public key! */
163 key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
164 GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
165 GNUNET_free (key);
166 GNUNET_free (keyfile);
167
168 if (GNUNET_OK != 167 if (GNUNET_OK !=
169 GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 168 GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
170 "SHORTEN_ZONEKEY", &keyfile)) 169 "SHORTEN_ZONEKEY", &keyfile))
@@ -187,7 +186,7 @@ run (void *cls, char *const *args, const char *cfgfile,
187 { 186 {
188 lookup_request = GNUNET_GNS_lookup (gns, 187 lookup_request = GNUNET_GNS_lookup (gns,
189 lookup_name, 188 lookup_name,
190 &pkey, 189 pkey,
191 rtype, 190 rtype,
192 GNUNET_NO, /* Use DHT */ 191 GNUNET_NO, /* Use DHT */
193 shorten_key, 192 shorten_key,
@@ -201,10 +200,135 @@ run (void *cls, char *const *args, const char *cfgfile,
201 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 200 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
202 return; 201 return;
203 } 202 }
204 if (NULL != shorten_key) 203 GNUNET_free_non_null (shorten_key);
205 GNUNET_free (shorten_key); 204}
205
206
207/**
208 * Method called to inform about the egos of this peer.
209 *
210 * When used with #GNUNET_IDENTITY_connect, this function is
211 * initially called for all egos and then again whenever a
212 * ego's name changes or if it is deleted. At the end of
213 * the initial pass over all egos, the function is once called
214 * with 'NULL' for @a ego. That does NOT mean that the callback won't
215 * be invoked in the future or that there was an error.
216 *
217 * If the @a name matches the `zone_ego_name`, we found the zone
218 * for our computation and will begin resolving against that zone.
219 * If we have iterated over all egos and not found the name, we
220 * terminate the program with an error message.
221 *
222 * @param cls closure (NULL, unused)
223 * @param ego ego handle
224 * @param ego_ctx context for application to store data for this ego
225 * (during the lifetime of this process, initially NULL)
226 * @param name name assigned by the user for this ego,
227 * NULL if the user just deleted the ego and it
228 * must thus no longer be used
229 */
230static void
231identity_cb (void *cls,
232 struct GNUNET_IDENTITY_Ego *ego,
233 void **ctx,
234 const char *name)
235{
236 struct GNUNET_CRYPTO_EccPublicKey pkey;
237
238 if ( (NULL != zone_ego_name) &&
239 (NULL != name) &&
240 (0 == strcmp (name,
241 zone_ego_name)) )
242 {
243 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
244 lookup_with_public_key (&pkey);
245 GNUNET_free (zone_ego_name);
246 zone_ego_name = NULL;
247 GNUNET_IDENTITY_disconnect (identity);
248 identity = NULL;
249 return;
250 }
251 if ( (NULL == ego) &&
252 (NULL != identity) &&
253 (NULL != zone_ego_name) )
254 {
255 fprintf (stderr,
256 _("Ego `%s' not found\n"),
257 zone_ego_name);
258 GNUNET_free (zone_ego_name);
259 zone_ego_name = NULL;
260 GNUNET_IDENTITY_disconnect (identity);
261 identity = NULL;
262 GNUNET_SCHEDULER_shutdown ();
263 return;
264 }
265}
266
267
268/**
269 * Main function that will be run.
270 *
271 * @param cls closure
272 * @param args remaining command-line arguments
273 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
274 * @param c configuration
275 */
276static void
277run (void *cls, char *const *args, const char *cfgfile,
278 const struct GNUNET_CONFIGURATION_Handle *c)
279{
280 struct GNUNET_CRYPTO_EccPublicKey pkey;
281
282 cfg = c;
283 gns = GNUNET_GNS_connect (cfg);
284 if (NULL == gns)
285 {
286 fprintf (stderr,
287 _("Failed to connect to GNS\n"));
288 return;
289 }
206 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 290 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
207 &do_shutdown, NULL); 291 &do_shutdown, NULL);
292 if (NULL != public_key)
293 {
294 if (GNUNET_OK !=
295 GNUNET_CRYPTO_ecc_public_key_from_string (public_key,
296 strlen (public_key),
297 &pkey))
298 {
299 fprintf (stderr,
300 _("Public key `%s' is not well-formed\n"),
301 public_key);
302 GNUNET_SCHEDULER_shutdown ();
303 return;
304 }
305 lookup_with_public_key (&pkey);
306 return;
307 }
308 if (NULL != zone_ego_name)
309 {
310 identity = GNUNET_IDENTITY_connect (cfg,
311 &identity_cb,
312 NULL);
313 return;
314 }
315 if ( (NULL != lookup_name) &&
316 (strlen (lookup_name) > 4) &&
317 (0 == strcmp (".zkey",
318 &lookup_name[strlen (lookup_name) - 4])) )
319 {
320 /* no zone required, use 'anonymous' zone */
321 GNUNET_CRYPTO_ecc_key_get_public (GNUNET_CRYPTO_ecc_key_get_anonymous (),
322 &pkey);
323 lookup_with_public_key (&pkey);
324 }
325 else
326 {
327 fprintf (stderr,
328 _("I need a zone (`-p' or `-z' option) to resolve this name\n"));
329 GNUNET_SCHEDULER_shutdown ();
330 return;
331 }
208} 332}
209 333
210 334
@@ -228,6 +352,12 @@ main (int argc, char *const *argv)
228 {'r', "raw", NULL, 352 {'r', "raw", NULL,
229 gettext_noop ("No unneeded output"), 0, 353 gettext_noop ("No unneeded output"), 0,
230 &GNUNET_GETOPT_set_one, &raw}, 354 &GNUNET_GETOPT_set_one, &raw},
355 {'p', "public-key", "PKEY",
356 gettext_noop ("Specify the public key of the zone to lookup the record in"), 1,
357 &GNUNET_GETOPT_set_string, &public_key},
358 {'z', "zone", "NAME",
359 gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1,
360 &GNUNET_GETOPT_set_string, &zone_ego_name},
231 GNUNET_GETOPT_OPTION_END 361 GNUNET_GETOPT_OPTION_END
232 }; 362 };
233 int ret; 363 int ret;