GNUnet 0.25.2-11-g84e94e98c
 
Loading...
Searching...
No Matches
delegate_misc.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016 GNUnet e.V.
4
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.
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 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19*/
20
21
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_abd_service.h"
31#include "gnunet_signatures.h"
32#include "abd.h"
33#include <inttypes.h>
34#include "delegate_misc.h"
35
36char *
38 const struct GNUNET_ABD_Delegate *cred)
39{
40 char *cred_str;
41 char *subject_pkey;
42 char *issuer_pkey;
43 char *signature;
44
46 subject_key);
48 ;
49 GNUNET_STRINGS_base64_encode ((char *) &cred->signature,
50 sizeof (struct
52 &signature);
53 if (0 == cred->subject_attribute_len)
54 {
55 GNUNET_asprintf (&cred_str,
56 "%s.%s -> %s | %s | %" SCNu64,
58 cred->issuer_attribute,
60 signature,
61 cred->expiration.abs_value_us);
62 }
63 else
64 {
65 GNUNET_asprintf (&cred_str,
66 "%s.%s -> %s.%s | %s | %" SCNu64,
68 cred->issuer_attribute,
70 cred->subject_attribute,
71 signature,
72 cred->expiration.abs_value_us);
73 }
76 GNUNET_free (signature);
77
78 return cred_str;
79}
80
81
82#define KEY_LEN_ENC (260 / 5)
83
86{
87 struct GNUNET_ABD_Delegate *dele;
88 char subject_pkey[KEY_LEN_ENC + 7];
89 char issuer_pkey[KEY_LEN_ENC + 7];
90 char iss_attr[253 + 1];
91 // Needs to be initialized, in case of Type 1 credential (A.a <- B)
92 char sub_attr[253 + 1] = "";
93 char signature[256]; // TODO max payload size
94 int attr_len;
95
97 struct GNUNET_TIME_Absolute etime_abs;
98
99 // If it's A.a <- B.b...
100 if (6 != sscanf (s,
101 "%58s.%253s -> %58s.%253s | %s | %" SCNu64,
103 iss_attr,
105 sub_attr,
106 signature,
107 &etime_abs.abs_value_us))
108 {
109 // Try if it's A.a <- B
110 if (5 != sscanf (s,
111 "%58s.%253s -> %58s | %s | %" SCNu64,
113 iss_attr,
115 signature,
116 &etime_abs.abs_value_us))
117 {
119 "Unable to parse DEL record string `%s'\n",
120 s);
121 return NULL;
122 }
123 }
124
125 // +1 for \0
126 if (strcmp (sub_attr, "") == 0)
127 {
128 attr_len = strlen (iss_attr) + 1;
129 }
130 else
131 {
132 attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
133 }
134 dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
135
136 {
137 char tmp_str[attr_len];
138 GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr));
139 if (strcmp (sub_attr, "") != 0)
140 {
141 tmp_str[strlen (iss_attr)] = '\0';
142 GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1,
143 sub_attr,
144 strlen (sub_attr));
145 }
146 tmp_str[attr_len - 1] = '\0';
147 if (GNUNET_SYSERR ==
149 &dele->subject_key))
150 {
151 GNUNET_free (dele);
152 return NULL;
153 }
154 if (GNUNET_SYSERR ==
156 &dele->issuer_key))
157 {
158 GNUNET_free (dele);
159 return NULL;
160 }
163 strlen (signature),
164 (void **) &sig));
165 dele->signature = *sig;
166 dele->expiration = etime_abs;
167 GNUNET_free (sig);
168
169 GNUNET_memcpy (&dele[1], tmp_str, attr_len);
170 }
171
172 dele->issuer_attribute = (char *) &dele[1];
173 dele->issuer_attribute_len = strlen (iss_attr);
174 if (strcmp (sub_attr, "") == 0)
175 {
176 dele->subject_attribute = NULL;
177 dele->subject_attribute_len = 0;
178 }
179 else
180 {
181 dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
182 dele->subject_attribute_len = strlen (sub_attr);
183 }
184
185 return dele;
186}
187
188
199struct GNUNET_ABD_Delegate *
201 const struct GNUNET_CRYPTO_BlindablePrivateKey *issuer,
203 const char *iss_attr,
204 const char *sub_attr,
206{
207 struct DelegateEntry *del;
208 struct GNUNET_ABD_Delegate *dele;
209 size_t size;
210 int attr_len;
211
212 if (NULL == sub_attr)
213 {
214 // +1 for \0
215 attr_len = strlen (iss_attr) + 1;
216 }
217 else
218 {
219 // +2 for both strings need to be terminated with \0
220 attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
221 }
222 size = sizeof (struct DelegateEntry) + attr_len;
223
224 {
225 char tmp_str[attr_len];
226 GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr));
227 if (NULL != sub_attr)
228 {
229 tmp_str[strlen (iss_attr)] = '\0';
230 GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1,
231 sub_attr,
232 strlen (sub_attr));
233 }
234 tmp_str[attr_len - 1] = '\0';
235
237 del->purpose.size =
238 htonl (size - sizeof (struct GNUNET_CRYPTO_BlindableKeySignature));
239 del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE);
240 GNUNET_CRYPTO_blindable_key_get_public (issuer, &del->issuer_key);
241 del->subject_key = *subject;
242 del->expiration = GNUNET_htonll (expiration->abs_value_us);
243 del->issuer_attribute_len = htonl (strlen (iss_attr) + 1);
244 if (NULL == sub_attr)
245 {
246 del->subject_attribute_len = htonl (0);
247 }
248 else
249 {
250 del->subject_attribute_len = htonl (strlen (sub_attr) + 1);
251 }
252
253 GNUNET_memcpy (&del[1], tmp_str, attr_len);
254 GNUNET_CRYPTO_blinded_key_sign_ (issuer, &del->purpose, &del->signature);
255
256 dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
257 dele->signature = del->signature;
258 dele->expiration = *expiration;
260
261 dele->subject_key = *subject;
262
263 // Copy the combined string at the part in the memory where the struct ends
264 GNUNET_memcpy (&dele[1], tmp_str, attr_len);
265 }
266
267 dele->issuer_attribute = (char *) &dele[1];
268 dele->issuer_attribute_len = strlen (iss_attr);
269 if (NULL == sub_attr)
270 {
271 dele->subject_attribute = NULL;
272 dele->subject_attribute_len = 0;
273 }
274 else
275 {
276 dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
277 dele->subject_attribute_len = strlen (sub_attr);
278 }
279
281 return dele;
282}
IPC messages between ABD API and ABD service.
char * GNUNET_ABD_delegate_to_string(const struct GNUNET_ABD_Delegate *cred)
#define KEY_LEN_ENC
struct GNUNET_ABD_Delegate * GNUNET_ABD_delegate_from_string(const char *s)
Delegate helper functions.
struct GNUNET_CRYPTO_BlindablePublicKey issuer_pkey
Issuer key.
Definition gnunet-abd.c:107
struct GNUNET_CRYPTO_BlindablePublicKey subject_pkey
Subject key.
Definition gnunet-abd.c:102
static char * subject
Subject pubkey string.
Definition gnunet-abd.c:87
static gnutls_certificate_credentials_t cred
The credential.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static int del
Desired action is to remove a record.
API to the Credential service.
#define GNUNET_SIGNATURE_PURPOSE_DELEGATE
Signature for a GNUnet credential (Reclaim)
struct GNUNET_ABD_Delegate * GNUNET_ABD_delegate_issue(const struct GNUNET_CRYPTO_BlindablePrivateKey *issuer, struct GNUNET_CRYPTO_BlindablePublicKey *subject, const char *iss_attr, const char *sub_attr, struct GNUNET_TIME_Absolute *expiration)
Issue an attribute to a subject.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blindable_key_get_public(const struct GNUNET_CRYPTO_BlindablePrivateKey *privkey, struct GNUNET_CRYPTO_BlindablePublicKey *key)
Retrieves the public key representation of a private key.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blinded_key_sign_(const struct GNUNET_CRYPTO_BlindablePrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_BlindableKeySignature *sig)
Sign a given block.
char * GNUNET_CRYPTO_blindable_public_key_to_string(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Creates a (Base32) string representation of the public key.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blindable_public_key_from_string(const char *str, struct GNUNET_CRYPTO_BlindablePublicKey *key)
Parses a (Base32) string representation of the public key.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition strings.c:1720
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition strings.c:1618
static unsigned int size
Size of the "table".
Definition peer.c:68
struct GNUNET_CRYPTO_BlindablePublicKey issuer_key
The issuer of the credential.
const char * subject_attribute
The subject attribute.
const char * issuer_attribute
The issuer attribute.
uint32_t issuer_attribute_len
Length of the issuer attribute.
uint32_t subject_attribute_len
Length of the subject attribute.
struct GNUNET_CRYPTO_BlindableKeySignature signature
Signature of this credential.
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
struct GNUNET_CRYPTO_BlindablePublicKey subject_key
Public key of the subject this credential was issued to.
An identity signature as per LSD0001.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.