2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @author Martin Schanzenbach
22 * @file src/identity-provider/gnunet-service-identity-provider.c
23 * @brief Identity Token Service
28 #include "gnunet_util_lib.h"
30 #include "gnunet_signatures.h"
38 * Weather to print the token
40 static int print_token;
46 const struct GNUNET_CONFIGURATION_Handle *c)
51 const char *header_b64;
52 const char *payload_b64;
53 const char *signature_b32;
54 const char *keystring;
57 json_t *keystring_json;
59 struct GNUNET_CRYPTO_EcdsaPublicKey key;
60 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
61 struct GNUNET_CRYPTO_EcdsaSignature sig;
65 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
66 _("Option `-t' is required\n"));
69 header_b64 = strtok (token, ".");
70 payload_b64 = strtok (NULL, ".");
71 signature_b32 = strtok (NULL, ".");
72 if ( (NULL == header_b64) ||
73 (NULL == payload_b64) ||
74 (NULL == signature_b32) )
76 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
77 _("Token `%s' is malformed\n"),
85 GNUNET_STRINGS_base64_decode (payload_b64,
89 GNUNET_STRINGS_base64_decode (header_b64,
94 GNUNET_asprintf(&data,
98 char *val = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + strlen (data));
99 purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose*)val;
100 purpose->size = htonl(sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + strlen (data));
101 purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN);
102 GNUNET_memcpy (&purpose[1], data, strlen(data));
108 printf ("Token:\nHeader:\t\t%s\nPayload:\t%s\n",
111 GNUNET_free (header);
113 payload_json = json_loads (payload, 0, &error);
114 GNUNET_free (payload);
116 if ((NULL == payload_json) || (! json_is_object (payload_json)) )
121 keystring_json = json_object_get (payload_json, "iss");
122 if (! json_is_string (keystring_json))
127 keystring = json_string_value (keystring_json);
129 GNUNET_CRYPTO_ecdsa_public_key_from_string (keystring,
136 GNUNET_STRINGS_string_to_data (signature_b32,
137 strlen (signature_b32),
139 sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
142 printf ("Signature:\t%s\n",
146 GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN,
150 printf("Signature not OK!\n");
152 printf("Signature OK!\n");
159 main(int argc, char *const argv[])
161 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
163 gettext_noop ("GNUid token"), 1,
164 &GNUNET_GETOPT_set_string, &token},
166 gettext_noop ("Print token contents"), 0,
167 &GNUNET_GETOPT_set_one, &print_token},
169 GNUNET_GETOPT_OPTION_END
171 return GNUNET_PROGRAM_run (argc, argv, "ct",