GNUnet 0.22.2
delegate_misc.c File Reference

Misc API for delegate. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_abd_service.h"
#include "gnunet_signatures.h"
#include "abd.h"
#include <inttypes.h>
#include "delegate_misc.h"
Include dependency graph for delegate_misc.c:

Go to the source code of this file.

Macros

#define KEY_LEN_ENC   (260 / 5)
 

Functions

char * GNUNET_ABD_delegate_to_string (const struct GNUNET_ABD_Delegate *cred)
 
struct GNUNET_ABD_DelegateGNUNET_ABD_delegate_from_string (const char *s)
 
struct GNUNET_ABD_DelegateGNUNET_ABD_delegate_issue (const struct GNUNET_CRYPTO_PrivateKey *issuer, struct GNUNET_CRYPTO_PublicKey *subject, const char *iss_attr, const char *sub_attr, struct GNUNET_TIME_Absolute *expiration)
 Issue an attribute to a subject. More...
 

Detailed Description

Misc API for delegate.

Author
Martin Schanzenbach

Definition in file delegate_misc.c.

Macro Definition Documentation

◆ KEY_LEN_ENC

#define KEY_LEN_ENC   (260 / 5)

Definition at line 79 of file delegate_misc.c.

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
47 GNUNET_STRINGS_base64_encode ((char *) &cred->signature,
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,
58 cred->expiration.abs_value_us);
59 }
60 else
61 {
62 GNUNET_asprintf (&cred_str,
63 "%s.%s -> %s.%s | %s | %" SCNu64,
65 cred->issuer_attribute,
67 cred->subject_attribute,
68 signature,
69 cred->expiration.abs_value_us);
70 }
73 GNUNET_free (signature);
74
75 return cred_str;
76}
struct GNUNET_CRYPTO_PublicKey issuer_pkey
Issuer key.
Definition: gnunet-abd.c:107
struct GNUNET_CRYPTO_PublicKey subject_pkey
Subject key.
Definition: gnunet-abd.c:102
static gnutls_certificate_credentials_t cred
The credential.
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:379
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:1599
An identity signature as per LSD0001.

References cred, GNUNET_asprintf(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_free, GNUNET_STRINGS_base64_encode(), issuer_pkey, 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 *  s)

Definition at line 82 of file delegate_misc.c.

83{
84 struct GNUNET_ABD_Delegate *dele;
85 char subject_pkey[KEY_LEN_ENC + 7];
86 char issuer_pkey[KEY_LEN_ENC + 7];
87 char iss_attr[253 + 1];
88 // Needs to be initialized, in case of Type 1 credential (A.a <- B)
89 char sub_attr[253 + 1] = "";
90 char signature[256]; // TODO max payload size
91 int attr_len;
92
93 struct GNUNET_CRYPTO_Signature *sig;
94 struct GNUNET_TIME_Absolute etime_abs;
95
96 // If it's A.a <- B.b...
97 if (6 != sscanf (s,
98 "%58s.%253s -> %58s.%253s | %s | %" SCNu64,
100 iss_attr,
102 sub_attr,
103 signature,
104 &etime_abs.abs_value_us))
105 {
106 // Try if it's A.a <- B
107 if (5 != sscanf (s,
108 "%58s.%253s -> %58s | %s | %" SCNu64,
110 iss_attr,
112 signature,
113 &etime_abs.abs_value_us))
114 {
116 "Unable to parse DEL record string `%s'\n",
117 s);
118 return NULL;
119 }
120 }
121
122 // +1 for \0
123 if (strcmp (sub_attr, "") == 0)
124 {
125 attr_len = strlen (iss_attr) + 1;
126 }
127 else
128 {
129 attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
130 }
131 dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
132
133 {
134 char tmp_str[attr_len];
135 GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr));
136 if (strcmp (sub_attr, "") != 0)
137 {
138 tmp_str[strlen (iss_attr)] = '\0';
139 GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1,
140 sub_attr,
141 strlen (sub_attr));
142 }
143 tmp_str[attr_len - 1] = '\0';
144 if (GNUNET_SYSERR ==
146 &dele->subject_key))
147 {
148 GNUNET_free (dele);
149 return NULL;
150 }
151 if (GNUNET_SYSERR ==
153 &dele->issuer_key))
154 {
155 GNUNET_free (dele);
156 return NULL;
157 }
158 GNUNET_assert (sizeof (struct GNUNET_CRYPTO_Signature) ==
160 strlen (signature),
161 (void **) &sig));
162 dele->signature = *sig;
163 dele->expiration = etime_abs;
164 GNUNET_free (sig);
165
166 GNUNET_memcpy (&dele[1], tmp_str, attr_len);
167 }
168
169 dele->issuer_attribute = (char *) &dele[1];
170 dele->issuer_attribute_len = strlen (iss_attr);
171 if (strcmp (sub_attr, "") == 0)
172 {
173 dele->subject_attribute = NULL;
174 dele->subject_attribute_len = 0;
175 }
176 else
177 {
178 dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
179 dele->subject_attribute_len = strlen (sub_attr);
180 }
181
182 return dele;
183}
#define KEY_LEN_ENC
Definition: delegate_misc.c:79
#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:399
@ 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:1701
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_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.
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, KEY_LEN_ENC, 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: