2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file reclaim/plugin_gnsrecord_reclaim.c
23 * @brief gnsrecord plugin to provide the API for identity records
24 * @author Martin Schanzenbach
27 #include "gnunet_util_lib.h"
28 #include "gnunet_gnsrecord_lib.h"
29 #include "gnunet_gnsrecord_plugin.h"
33 * Convert the 'value' of a record to a string.
35 * @param cls closure, unused
36 * @param type type of the record
37 * @param data value in binary encoding
38 * @param data_size number of bytes in @a data
39 * @return NULL on error, otherwise human-readable representation of the value
42 value_to_string (void *cls,
47 const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
48 const struct GNUNET_CRYPTO_EcdsaPublicKey *audience_pubkey;
56 case GNUNET_GNSRECORD_TYPE_ID_ATTR:
57 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
58 case GNUNET_GNSRECORD_TYPE_ID_TOKEN: //DEPRECATED
59 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT:
60 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
61 return GNUNET_strndup (data, data_size);
62 case GNUNET_GNSRECORD_TYPE_ABE_KEY:
63 case GNUNET_GNSRECORD_TYPE_ABE_MASTER:
64 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
65 case GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA: //DEPRECATED
67 audience_pubkey = data+sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey);
68 scopes = (char*) audience_pubkey+(sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
69 ecdhe_str = GNUNET_STRINGS_data_to_string_alloc (ecdhe_privkey,
70 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
71 aud_str = GNUNET_STRINGS_data_to_string_alloc (audience_pubkey,
72 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
73 GNUNET_asprintf (&result,
75 ecdhe_str, aud_str, scopes);
76 GNUNET_free (aud_str);
77 GNUNET_free (ecdhe_str);
87 * Convert human-readable version of a 'value' of a record to the binary
90 * @param cls closure, unused
91 * @param type type of the record
92 * @param s human-readable string
93 * @param data set to value in binary encoding (will be allocated)
94 * @param data_size set to number of bytes in @a data
95 * @return #GNUNET_OK on success
98 string_to_value (void *cls,
111 return GNUNET_SYSERR;
114 case GNUNET_GNSRECORD_TYPE_ID_ATTR:
115 return GNUNET_STRINGS_string_to_data (s,
119 case GNUNET_GNSRECORD_TYPE_ID_TOKEN:
120 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT:
121 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
122 *data = GNUNET_strdup (s);
123 *data_size = strlen (s);
125 case GNUNET_GNSRECORD_TYPE_ABE_KEY:
126 case GNUNET_GNSRECORD_TYPE_ABE_MASTER:
127 return GNUNET_STRINGS_string_to_data (s,
131 case GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA:
132 tmp_tok = GNUNET_strdup (s);
133 ecdhe_str = strtok (tmp_tok, ";");
134 if (NULL == ecdhe_str)
136 GNUNET_free (tmp_tok);
137 return GNUNET_SYSERR;
139 aud_keystr = strtok (NULL, ";");
140 if (NULL == aud_keystr)
142 GNUNET_free (tmp_tok);
143 return GNUNET_SYSERR;
145 str = strtok (NULL, ";");
148 GNUNET_free (tmp_tok);
149 return GNUNET_SYSERR;
151 *data_size = strlen (str) + 1
152 +sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)
153 +sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
154 *data = GNUNET_malloc (*data_size);
157 GNUNET_STRINGS_string_to_data (ecdhe_str,
160 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
161 write_ptr += sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey);
162 GNUNET_STRINGS_string_to_data (aud_keystr,
165 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
166 write_ptr += sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
167 GNUNET_memcpy (write_ptr, str, strlen (str) + 1); //with 0-Terminator
168 GNUNET_free (tmp_tok);
172 return GNUNET_SYSERR;
178 * Mapping of record type numbers to human-readable
185 { "ID_ATTR", GNUNET_GNSRECORD_TYPE_ID_ATTR },
186 { "ID_TOKEN", GNUNET_GNSRECORD_TYPE_ID_TOKEN },
187 { "ABE_KEY", GNUNET_GNSRECORD_TYPE_ABE_KEY },
188 { "ABE_MASTER", GNUNET_GNSRECORD_TYPE_ABE_MASTER },
189 { "ID_TOKEN_METADATA", GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA },
190 { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT },
191 { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT },
197 * Convert a type name (i.e. "AAAA") to the corresponding number.
199 * @param cls closure, unused
200 * @param dns_typename name to convert
201 * @return corresponding number, UINT32_MAX on error
204 typename_to_number (void *cls,
205 const char *dns_typename)
210 while ( (NULL != name_map[i].name) &&
211 (0 != strcasecmp (dns_typename, name_map[i].name)) )
213 return name_map[i].number;
218 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
220 * @param cls closure, unused
221 * @param type number of a type to convert
222 * @return corresponding typestring, NULL on error
225 number_to_typename (void *cls,
231 while ( (NULL != name_map[i].name) &&
232 (type != name_map[i].number) )
234 return name_map[i].name;
239 * Entry point for the plugin.
242 * @return the exported block API
245 libgnunet_plugin_gnsrecord_reclaim_init (void *cls)
247 struct GNUNET_GNSRECORD_PluginFunctions *api;
249 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
250 api->value_to_string = &value_to_string;
251 api->string_to_value = &string_to_value;
252 api->typename_to_number = &typename_to_number;
253 api->number_to_typename = &number_to_typename;
259 * Exit point from the plugin.
261 * @param cls the return value from #libgnunet_plugin_block_test_init
265 libgnunet_plugin_gnsrecord_reclaim_done (void *cls)
267 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
273 /* end of plugin_gnsrecord_dns.c */