GNUnet  0.11.x
Functions
delegate_misc.h File Reference

Delegate helper functions. More...

#include "gnunet_abd_service.h"
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.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, GNUNET_asprintf(), GNUNET_CRYPTO_ecdsa_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().

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_EcdsaSignature),
49  &signature);
50  if (0 == cred->subject_attribute_len)
51  {
52  GNUNET_asprintf (&cred_str,
53  "%s.%s -> %s | %s | %" SCNu64,
54  issuer_pkey,
55  cred->issuer_attribute,
56  subject_pkey,
57  signature,
58  cred->expiration.abs_value_us);
59  }
60  else
61  {
62  GNUNET_asprintf (&cred_str,
63  "%s.%s -> %s.%s | %s | %" SCNu64,
64  issuer_pkey,
65  cred->issuer_attribute,
66  subject_pkey,
67  cred->subject_attribute,
68  signature,
69  cred->expiration.abs_value_us);
70  }
71  GNUNET_free (subject_pkey);
72  GNUNET_free (issuer_pkey);
73  GNUNET_free (signature);
74 
75  return cred_str;
76 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_pkey
Issuer key.
Definition: gnunet-abd.c:106
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
uint32_t subject_attribute_len
Length of the subject attribute.
an ECC signature using ECDSA
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
Definition: gnunet-abd.c:101
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1857
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:332
const char * subject_attribute
The subject attribute.
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
const char * issuer_attribute
The issuer attribute.
#define GNUNET_free(ptr)
Wrapper around free.
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 79 of file delegate_misc.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, GNUNET_assert, GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_STRINGS_base64_decode(), 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().

80 {
81  struct GNUNET_ABD_Delegate *dele;
82  size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
83  if (enclen % 5 > 0)
84  enclen += 5 - enclen % 5;
85  enclen /= 5; /* 260/5 = 52 */
86  char subject_pkey[enclen + 1];
87  char issuer_pkey[enclen + 1];
88  char iss_attr[253 + 1];
89  // Needs to be initialized, in case of Type 1 credential (A.a <- B)
90  char sub_attr[253 + 1] = "";
91  char signature[256]; // TODO max payload size
92 
93  struct GNUNET_CRYPTO_EcdsaSignature *sig;
94  struct GNUNET_TIME_Absolute etime_abs;
95 
96  // If it's A.a <- B.b...
97  if (6 != sscanf (s,
98  "%52s.%253s -> %52s.%253s | %s | %" SCNu64,
99  issuer_pkey,
100  iss_attr,
101  subject_pkey,
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  "%52s.%253s -> %52s | %s | %" SCNu64,
109  issuer_pkey,
110  iss_attr,
111  subject_pkey,
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  int attr_len;
124  if (strcmp (sub_attr, "") == 0)
125  {
126  attr_len = strlen (iss_attr) + 1;
127  }
128  else
129  {
130  attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
131  }
132  dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
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 
146  strlen (subject_pkey),
147  &dele->subject_key);
149  strlen (issuer_pkey),
150  &dele->issuer_key);
151  GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) ==
152  GNUNET_STRINGS_base64_decode (signature,
153  strlen (signature),
154  (void **) &sig));
155  dele->signature = *sig;
156  dele->expiration = etime_abs;
157  GNUNET_free (sig);
158 
159  GNUNET_memcpy (&dele[1], tmp_str, attr_len);
160 
161  dele->issuer_attribute = (char *) &dele[1];
162  dele->issuer_attribute_len = strlen (iss_attr);
163  if (strcmp (sub_attr, "") == 0)
164  {
165  dele->subject_attribute = NULL;
166  dele->subject_attribute_len = 0;
167  }
168  else
169  {
170  dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
171  dele->subject_attribute_len = strlen (sub_attr);
172  }
173 
174  return dele;
175 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_pkey
Issuer key.
Definition: gnunet-abd.c:106
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint32_t subject_attribute_len
Length of the subject attribute.
an ECC signature using ECDSA
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
Definition: gnunet-abd.c:101
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1921
uint32_t issuer_attribute_len
Length of the issuer attribute.
const char * subject_attribute
The subject attribute.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:466
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
Time for absolute times used by GNUnet, in microseconds.
const char * issuer_attribute
The issuer attribute.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: