aboutsummaryrefslogtreecommitdiff
path: root/src/identity-provider
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-26 11:55:54 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-26 11:55:54 +0000
commit871d289fbe7629caa39aeb7e9bb30d7d48864d62 (patch)
tree59c39e574fc2a716e10301ff53cd0878c42ca13f /src/identity-provider
parent6a80e00bda6d07527d0a6adf5812801a57bdf2f0 (diff)
downloadgnunet-871d289fbe7629caa39aeb7e9bb30d7d48864d62.tar.gz
gnunet-871d289fbe7629caa39aeb7e9bb30d7d48864d62.zip
fix double free, bad use of strtok
Diffstat (limited to 'src/identity-provider')
-rw-r--r--src/identity-provider/gnunet-identity-token.c87
1 files changed, 64 insertions, 23 deletions
diff --git a/src/identity-provider/gnunet-identity-token.c b/src/identity-provider/gnunet-identity-token.c
index 3e7d5bd9b..1f480aae0 100644
--- a/src/identity-provider/gnunet-identity-token.c
+++ b/src/identity-provider/gnunet-identity-token.c
@@ -1,3 +1,29 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
4
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.
9
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.
14
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.
19 */
20/**
21 * @author Martin Schanzenbach
22 * @file src/identity-provider/gnunet-service-identity-provider.c
23 * @brief Identity Token Service
24 *
25 */
26
1#include "platform.h" 27#include "platform.h"
2#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
3#include <jansson.h> 29#include <jansson.h>
@@ -19,25 +45,42 @@ run (void *cls,
19 const char *cfgfile, 45 const char *cfgfile,
20 const struct GNUNET_CONFIGURATION_Handle *c) 46 const struct GNUNET_CONFIGURATION_Handle *c)
21{ 47{
22 char* payload; 48 char *payload;
23 char* header; 49 char *header;
24 //Get token parts 50 //Get token parts
25 char* header_b64 = strtok (token, "."); 51 const char *header_b64;
26 char* payload_b64 = strtok(NULL, "."); 52 const char *payload_b64;
27 char* signature_b32 = strtok(NULL, "."); 53 const char *signature_b32;
28 const char* keystring; 54 const char *keystring;
29 char* data; 55 char *data;
30 json_t *payload_json; 56 json_t *payload_json;
31 json_t *keystring_json; 57 json_t *keystring_json;
32 json_error_t error; 58 json_error_t error;
33 struct GNUNET_CRYPTO_EcdsaPublicKey key; 59 struct GNUNET_CRYPTO_EcdsaPublicKey key;
34 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; 60 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
35 struct GNUNET_CRYPTO_EcdsaSignature sig; 61 struct GNUNET_CRYPTO_EcdsaSignature sig;
36 62
37 GNUNET_assert (NULL != header_b64); 63 if (NULL == token)
38 GNUNET_assert (NULL != payload_b64); 64 {
39 GNUNET_assert (NULL != signature_b32); 65 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
40 66 _("Option `-t' is required\n"));
67 return;
68 }
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) )
75 {
76 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
77 _("Token `%s' is malformed\n"),
78 token);
79 GNUNET_free (token);
80 token = NULL;
81 return;
82 }
83
41 //Decode payload 84 //Decode payload
42 GNUNET_STRINGS_base64_decode (payload_b64, 85 GNUNET_STRINGS_base64_decode (payload_b64,
43 strlen (payload_b64), 86 strlen (payload_b64),
@@ -46,9 +89,7 @@ run (void *cls,
46 GNUNET_STRINGS_base64_decode (header_b64, 89 GNUNET_STRINGS_base64_decode (header_b64,
47 strlen (header_b64), 90 strlen (header_b64),
48 &header); 91 &header);
49 if (NULL == token) 92
50 return;
51
52 93
53 GNUNET_asprintf(&data, 94 GNUNET_asprintf(&data,
54 "%s,%s", 95 "%s,%s",
@@ -60,14 +101,14 @@ run (void *cls,
60 purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN); 101 purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN);
61 GNUNET_memcpy (&purpose[1], data, strlen(data)); 102 GNUNET_memcpy (&purpose[1], data, strlen(data));
62 GNUNET_free (data); 103 GNUNET_free (data);
63 GNUNET_free (header_b64); 104 GNUNET_free (token);
64 GNUNET_free (header_b64); 105 token = NULL;
65 106
66 if (print_token) 107 if (print_token)
67 printf ("Token:\nHeader:\t\t%s\nPayload:\t%s\n", header, payload); 108 printf ("Token:\nHeader:\t\t%s\nPayload:\t%s\n", header, payload);
68 GNUNET_free (header); 109 GNUNET_free (header);
69 GNUNET_free (payload); 110 GNUNET_free (payload);
70 111
71 payload_json = json_loads (payload, 0, &error); 112 payload_json = json_loads (payload, 0, &error);
72 if ((NULL == payload_json) || !json_is_object (payload_json)) 113 if ((NULL == payload_json) || !json_is_object (payload_json))
73 { 114 {
@@ -92,10 +133,10 @@ run (void *cls,
92 strlen (signature_b32), 133 strlen (signature_b32),
93 &sig, 134 &sig,
94 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 135 sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
95 136
96 if (print_token) 137 if (print_token)
97 printf ("Signature:\t%s\n", keystring); 138 printf ("Signature:\t%s\n", keystring);
98 139
99 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN, 140 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN,
100 purpose, 141 purpose,
101 &sig, 142 &sig,
@@ -106,6 +147,8 @@ run (void *cls,
106 GNUNET_free (val); 147 GNUNET_free (val);
107 return; 148 return;
108} 149}
150
151
109int 152int
110main(int argc, char *const argv[]) 153main(int argc, char *const argv[])
111{ 154{
@@ -123,5 +166,3 @@ main(int argc, char *const argv[])
123 "ct", options, 166 "ct", options,
124 &run, NULL); 167 &run, NULL);
125} 168}
126
127