GNUnet 0.21.1
delegate_misc.h File Reference

Delegate helper functions. More...

Include dependency graph for delegate_misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * GNUNET_ABD_delegate_to_string (const struct GNUNET_ABD_Delegate *cred)
 
struct GNUNET_ABD_DelegateGNUNET_ABD_delegate_from_string (const char *str)
 

Detailed Description

Delegate helper functions.

Definition in file delegate_misc.h.

Function Documentation

◆ GNUNET_ABD_delegate_to_string()

char * GNUNET_ABD_delegate_to_string ( const struct GNUNET_ABD_Delegate cred)

Definition at line 37 of file delegate_misc.c.

39{
40 char *cred_str;
41 char *subject_pkey;
42 char *issuer_pkey;
43 char *signature;
44
48 sizeof (struct GNUNET_CRYPTO_Signature),
49 &signature);
50 if (0 == cred->subject_attribute_len)
51 {
52 GNUNET_asprintf (&cred_str,
53 "%s.%s -> %s | %s | %" SCNu64,
55 cred->issuer_attribute,
57 signature,
59 }
60 else
61 {
62 GNUNET_asprintf (&cred_str,
63 "%s.%s -> %s.%s | %s | %" SCNu64,
65 cred->issuer_attribute,
68 signature,
70 }
73 GNUNET_free (signature);
74
75 return cred_str;
76}
struct GNUNET_CRYPTO_PublicKey issuer_pkey
Issuer key.
Definition: gnunet-abd.c:106
struct GNUNET_CRYPTO_PublicKey subject_pkey
Subject key.
Definition: gnunet-abd.c:101
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:551
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1622
const char * subject_attribute
The subject attribute.
const char * issuer_attribute
The issuer attribute.
uint32_t subject_attribute_len
Length of the subject attribute.
struct GNUNET_CRYPTO_Signature signature
Signature of this credential.
struct GNUNET_CRYPTO_PublicKey issuer_key
The issuer of the credential.
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
struct GNUNET_CRYPTO_PublicKey subject_key
Public key of the subject this credential was issued to.
An identity signature as per LSD0001.
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, GNUNET_asprintf(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_free, GNUNET_STRINGS_base64_encode(), GNUNET_ABD_Delegate::issuer_attribute, GNUNET_ABD_Delegate::issuer_key, issuer_pkey, GNUNET_ABD_Delegate::signature, GNUNET_ABD_Delegate::subject_attribute, GNUNET_ABD_Delegate::subject_attribute_len, GNUNET_ABD_Delegate::subject_key, and subject_pkey.

Referenced by abd_value_to_string(), handle_collect_result(), and sign_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegate_from_string()

struct GNUNET_ABD_Delegate * GNUNET_ABD_delegate_from_string ( const char *  str)

Definition at line 80 of file delegate_misc.c.

81{
82 struct GNUNET_ABD_Delegate *dele;
83 size_t enclen = (sizeof (struct GNUNET_CRYPTO_PublicKey)) * 8;
84 if (enclen % 5 > 0)
85 enclen += 5 - enclen % 5;
86 enclen /= 5; /* 260/5 = 52 */
87 char subject_pkey[enclen + 1];
88 char issuer_pkey[enclen + 1];
89 char iss_attr[253 + 1];
90 // Needs to be initialized, in case of Type 1 credential (A.a <- B)
91 char sub_attr[253 + 1] = "";
92 char signature[256]; // TODO max payload size
93
94 struct GNUNET_CRYPTO_Signature *sig;
95 struct GNUNET_TIME_Absolute etime_abs;
96
97 // If it's A.a <- B.b...
98 if (6 != sscanf (s,
99 "%58s.%253s -> %58s.%253s | %s | %" SCNu64,
101 iss_attr,
103 sub_attr,
104 signature,
105 &etime_abs.abs_value_us))
106 {
107 // Try if it's A.a <- B
108 if (5 != sscanf (s,
109 "%58s.%253s -> %58s | %s | %" SCNu64,
111 iss_attr,
113 signature,
114 &etime_abs.abs_value_us))
115 {
117 "Unable to parse DEL record string `%s'\n",
118 s);
119 return NULL;
120 }
121 }
122
123 // +1 for \0
124 int attr_len;
125 if (strcmp (sub_attr, "") == 0)
126 {
127 attr_len = strlen (iss_attr) + 1;
128 }
129 else
130 {
131 attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
132 }
133 dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
134
135 char tmp_str[attr_len];
136 GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr));
137 if (strcmp (sub_attr, "") != 0)
138 {
139 tmp_str[strlen (iss_attr)] = '\0';
140 GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1,
141 sub_attr,
142 strlen (sub_attr));
143 }
144 tmp_str[attr_len - 1] = '\0';
145
146 if (GNUNET_SYSERR ==
148 &dele->subject_key))
149 {
150 GNUNET_free (dele);
151 return NULL;
152 }
153 if (GNUNET_SYSERR ==
155 &dele->issuer_key))
156 {
157 GNUNET_free (dele);
158 return NULL;
159 }
160 GNUNET_assert (sizeof (struct GNUNET_CRYPTO_Signature) ==
162 strlen (signature),
163 (void **) &sig));
164 dele->signature = *sig;
165 dele->expiration = etime_abs;
166 GNUNET_free (sig);
167
168 GNUNET_memcpy (&dele[1], tmp_str, attr_len);
169
170 dele->issuer_attribute = (char *) &dele[1];
171 dele->issuer_attribute_len = strlen (iss_attr);
172 if (strcmp (sub_attr, "") == 0)
173 {
174 dele->subject_attribute = NULL;
175 dele->subject_attribute_len = 0;
176 }
177 else
178 {
179 dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
180 dele->subject_attribute_len = strlen (sub_attr);
181 }
182
183 return dele;
184}
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:571
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_malloc(size)
Wrapper around malloc.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1724
uint32_t issuer_attribute_len
Length of the issuer attribute.
An identity key as per LSD0001.
Time for absolute times used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, GNUNET_assert, GNUNET_CRYPTO_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, GNUNET_ABD_Delegate::issuer_attribute, GNUNET_ABD_Delegate::issuer_attribute_len, GNUNET_ABD_Delegate::issuer_key, issuer_pkey, GNUNET_ABD_Delegate::signature, GNUNET_ABD_Delegate::subject_attribute, GNUNET_ABD_Delegate::subject_attribute_len, GNUNET_ABD_Delegate::subject_key, and subject_pkey.

Referenced by abd_string_to_value(), run(), and store_cb().

Here is the call graph for this function:
Here is the caller graph for this function: