GNUnet  0.11.x
oidc_helper.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2010-2015 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 
26 #include "platform.h"
27 #include <inttypes.h>
28 #include <jansson.h>
29 #include "gnunet_util_lib.h"
30 #include "gnunet_reclaim_lib.h"
31 #include "gnunet_reclaim_service.h"
32 #include "gnunet_signatures.h"
33 #include "oidc_helper.h"
34 // #include "benchmark.h"
35 #include <gcrypt.h>
36 
38 
43 {
48 
53 
58 
63 
68 };
69 
71 
75 static char OIDC_profile_claims[14][32] = {
76  "name", "family_name", "given_name", "middle_name", "nickname",
77  "preferred_username", "profile", "picture", "website", "gender", "birthdate",
78  "zoneinfo", "locale", "updated_at"
79 };
80 
84 static char OIDC_email_claims[2][16] = {
85  "email", "email_verified"
86 };
87 
91 static char OIDC_phone_claims[2][32] = {
92  "phone_number", "phone_number_verified"
93 };
94 
98 static char OIDC_address_claims[5][32] = {
99  "street_address", "locality", "region", "postal_code", "country"
100 };
101 
102 static enum GNUNET_GenericReturnValue
104 {
105  int i;
106  for (i = 0; i < 5; i++)
107  {
108  if (0 == strcmp (claim, OIDC_address_claims[i]))
109  {
110  return GNUNET_YES;
111  }
112  }
113  return GNUNET_NO;
114 }
115 
116 
117 static char *
119 {
120  json_t *root;
121  char *json_str;
122 
123  root = json_object ();
124  json_object_set_new (root, JWT_ALG, json_string (JWT_ALG_VALUE));
125  json_object_set_new (root, JWT_TYP, json_string (JWT_TYP_VALUE));
126 
127  json_str = json_dumps (root, JSON_INDENT (0) | JSON_COMPACT);
128  json_decref (root);
129  return json_str;
130 }
131 
132 
133 static void
134 replace_char (char *str, char find, char replace)
135 {
136  char *current_pos = strchr (str, find);
137 
138  while (current_pos)
139  {
140  *current_pos = replace;
141  current_pos = strchr (current_pos, find);
142  }
143 }
144 
145 
146 // RFC4648
147 static void
148 fix_base64 (char *str)
149 {
150  // Replace + with -
151  replace_char (str, '+', '-');
152 
153  // Replace / with _
154  replace_char (str, '/', '_');
155 }
156 
157 
158 static json_t*
160  const struct GNUNET_RECLAIM_AttributeList *attrs,
161  const struct
162  GNUNET_RECLAIM_PresentationList *presentations)
163 {
166  char *subject;
167  char *source_name;
168  char *attr_val_str;
169  char *pres_val_str;
170  json_t *body;
171  json_t *aggr_names;
172  json_t *aggr_sources;
173  json_t *aggr_sources_jwt;
174  json_t *addr_claim = NULL;
175  int num_presentations = 0;
176  for (le = attrs->list_head; NULL != le; le = le->next)
177  {
179  num_presentations++;
180  }
181 
182  subject =
184  sizeof(struct
186  body = json_object ();
187  aggr_names = json_object ();
188  aggr_sources = json_object ();
189 
190  // iss REQUIRED case sensitive server uri with https
191  // The issuer is the local reclaim instance (e.g.
192  // https://reclaim.id/api/openid)
193  json_object_set_new (body, "iss", json_string (SERVER_ADDRESS));
194  // sub REQUIRED public key identity, not exceed 255 ASCII length
195  json_object_set_new (body, "sub", json_string (subject));
196  pres_val_str = NULL;
197  source_name = NULL;
198  int i = 0;
199  for (ple = presentations->list_head; NULL != ple; ple = ple->next)
200  {
201  // New presentation
202  GNUNET_asprintf (&source_name,
203  "src%d",
204  i);
205  aggr_sources_jwt = json_object ();
206  pres_val_str =
208  ple->presentation->data,
209  ple->presentation->data_size);
210  json_object_set_new (aggr_sources_jwt,
212  ple->presentation->type),
213  json_string (pres_val_str) );
214  json_object_set_new (aggr_sources, source_name, aggr_sources_jwt);
215  GNUNET_free (pres_val_str);
216  GNUNET_free (source_name);
217  source_name = NULL;
218  i++;
219  }
220 
221  for (le = attrs->list_head; NULL != le; le = le->next)
222  {
223 
225  {
226 
227  attr_val_str =
229  le->attribute->data,
230  le->attribute->data_size);
237  {
238  if (NULL == addr_claim)
239  {
240  addr_claim = json_object ();
241  }
242  json_object_set_new (addr_claim, le->attribute->name,
243  json_string (attr_val_str));
244 
245  }
246  else
247  {
248  json_object_set_new (body, le->attribute->name,
249  json_string (attr_val_str));
250  }
251  GNUNET_free (attr_val_str);
252  }
253  else
254  {
255  // Check if presentation is there
256  int j = 0;
257  for (ple = presentations->list_head; NULL != ple; ple = ple->next)
258  {
259  if (GNUNET_YES ==
261  &le->attribute->credential))
262  break;
263  j++;
264  }
265  if (NULL == ple)
266  {
268  "Presentation for `%s' missing...\n",
269  le->attribute->name);
270  continue;
271  }
272  // Presentation exists, hence take the respective source str
273  GNUNET_asprintf (&source_name,
274  "src%d",
275  j);
276  json_object_set_new (aggr_names, le->attribute->data,
277  json_string (source_name));
278  GNUNET_free (source_name);
279  }
280  }
281  if (NULL != addr_claim)
282  json_object_set_new (body, "address", addr_claim);
283  if (0 != i)
284  {
285  json_object_set_new (body, "_claim_names", aggr_names);
286  json_object_set_new (body, "_claim_sources", aggr_sources);
287  }
288 
289  return body;
290 }
291 
292 
301 char *
303  const struct GNUNET_RECLAIM_AttributeList *attrs,
304  const struct
305  GNUNET_RECLAIM_PresentationList *presentations)
306 {
307  char *body_str;
308  json_t*body = generate_userinfo_json (sub_key,
309  attrs,
310  presentations);
311  body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT);
312  json_decref (body);
313  return body_str;
314 }
315 
316 
328 char *
330  const struct GNUNET_IDENTITY_PublicKey *sub_key,
331  const struct GNUNET_RECLAIM_AttributeList *attrs,
332  const struct
333  GNUNET_RECLAIM_PresentationList *presentations,
334  const struct GNUNET_TIME_Relative *expiration_time,
335  const char *nonce,
336  const char *secret_key)
337 {
338  struct GNUNET_HashCode signature;
339  struct GNUNET_TIME_Absolute exp_time;
340  struct GNUNET_TIME_Absolute time_now;
341  char *audience;
342  char *subject;
343  char *header;
344  char *body_str;
345  char *result;
346  char *header_base64;
347  char *body_base64;
348  char *signature_target;
349  char *signature_base64;
350  json_t *body;
351 
352  body = generate_userinfo_json (sub_key,
353  attrs,
354  presentations);
355  // iat REQUIRED time now
356  time_now = GNUNET_TIME_absolute_get ();
357  // exp REQUIRED time expired from config
358  exp_time = GNUNET_TIME_absolute_add (time_now, *expiration_time);
359  // auth_time only if max_age
360  // nonce only if nonce
361  // OPTIONAL acr,amr,azp
362  subject =
364  sizeof(struct
366  audience =
368  sizeof(struct
370  header = create_jwt_header ();
371 
372  // aud REQUIRED public key client_id must be there
373  json_object_set_new (body, "aud", json_string (audience));
374  // iat
375  json_object_set_new (body,
376  "iat",
377  json_integer (time_now.abs_value_us / (1000 * 1000)));
378  // exp
379  json_object_set_new (body,
380  "exp",
381  json_integer (exp_time.abs_value_us / (1000 * 1000)));
382  // nbf
383  json_object_set_new (body,
384  "nbf",
385  json_integer (time_now.abs_value_us / (1000 * 1000)));
386  // nonce
387  if (NULL != nonce)
388  json_object_set_new (body, "nonce", json_string (nonce));
389 
390  body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT);
391  json_decref (body);
392  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"ID-Token: %s\n", body_str);
393 
394  GNUNET_STRINGS_base64url_encode (header, strlen (header), &header_base64);
395  fix_base64 (header_base64);
396 
397  GNUNET_STRINGS_base64url_encode (body_str, strlen (body_str), &body_base64);
398  fix_base64 (body_base64);
399 
400  GNUNET_free (subject);
401  GNUNET_free (audience);
402 
407  GNUNET_asprintf (&signature_target, "%s.%s", header_base64, body_base64);
408  GNUNET_CRYPTO_hmac_raw (secret_key,
409  strlen (secret_key),
410  signature_target,
411  strlen (signature_target),
412  &signature);
413  GNUNET_STRINGS_base64url_encode ((const char *) &signature,
414  sizeof(struct GNUNET_HashCode),
415  &signature_base64);
416  fix_base64 (signature_base64);
417 
418  GNUNET_asprintf (&result,
419  "%s.%s.%s",
420  header_base64,
421  body_base64,
422  signature_base64);
423 
424  GNUNET_free (signature_target);
425  GNUNET_free (header);
426  GNUNET_free (body_str);
427  GNUNET_free (signature_base64);
428  GNUNET_free (body_base64);
429  GNUNET_free (header_base64);
430  return result;
431 }
432 
433 
446 char *
448  const struct GNUNET_RECLAIM_Ticket *ticket,
449  const struct GNUNET_RECLAIM_AttributeList *attrs,
450  const struct
451  GNUNET_RECLAIM_PresentationList *presentations,
452  const char *nonce_str,
453  const char *code_challenge)
454 {
455  struct OIDC_Parameters params;
456  char *code_payload;
457  char *payload;
458  char *tmp;
459  char *code_str;
460  char *buf_ptr = NULL;
461  size_t payload_len;
462  size_t code_payload_len;
463  size_t attr_list_len = 0;
464  size_t pres_list_len = 0;
465  size_t code_challenge_len = 0;
466  uint32_t nonce_len = 0;
468 
470  // Assign ticket
471  memset (&params, 0, sizeof(params));
472  params.ticket = *ticket;
473  // Assign nonce
474  payload_len = sizeof(struct OIDC_Parameters);
475  if ((NULL != nonce_str) && (strcmp ("", nonce_str) != 0))
476  {
477  nonce_len = strlen (nonce_str);
478  payload_len += nonce_len;
479  }
480  params.nonce_len = htonl (nonce_len);
481  // Assign code challenge
482  if (NULL != code_challenge)
483  code_challenge_len = strlen (code_challenge);
484  payload_len += code_challenge_len;
485  params.code_challenge_len = htonl (code_challenge_len);
486  // Assign attributes
487  if (NULL != attrs)
488  {
489  // Get length
490  attr_list_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
491  params.attr_list_len = htonl (attr_list_len);
493  "Length of serialized attributes: %lu\n",
494  attr_list_len);
495  // Get serialized attributes
496  payload_len += attr_list_len;
497  }
498  if (NULL != presentations)
499  {
500  // Get length
501  pres_list_len =
503  params.pres_list_len = htonl (pres_list_len);
505  "Length of serialized presentations: %lu\n",
506  pres_list_len);
507  // Get serialized attributes
508  payload_len += pres_list_len;
509  }
510 
511  // Get plaintext length
512  payload = GNUNET_malloc (payload_len);
513  memcpy (payload, &params, sizeof(params));
514  tmp = payload + sizeof(params);
515  if (0 < code_challenge_len)
516  {
517  memcpy (tmp, code_challenge, code_challenge_len);
518  tmp += code_challenge_len;
519  }
520  if (0 < nonce_len)
521  {
522  memcpy (tmp, nonce_str, nonce_len);
523  tmp += nonce_len;
524  }
525  if (0 < attr_list_len)
527  if (0 < pres_list_len)
528  GNUNET_RECLAIM_presentation_list_serialize (presentations, tmp);
529 
532  // Get length
533  code_payload_len = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
534  + payload_len + sizeof(struct
535  GNUNET_IDENTITY_Signature);
537  "Length of data to encode: %lu\n",
538  code_payload_len);
539 
540  // Initialize code payload
541  code_payload = GNUNET_malloc (code_payload_len);
542  GNUNET_assert (NULL != code_payload);
543  purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *) code_payload;
544  purpose->size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
545  + payload_len);
547  // Store pubkey
548  buf_ptr = (char *) &purpose[1];
549  memcpy (buf_ptr, payload, payload_len);
550  GNUNET_free (payload);
551  buf_ptr += payload_len;
552  // Sign and store signature
553  if (GNUNET_SYSERR ==
554  GNUNET_IDENTITY_sign_ (issuer,
555  purpose,
556  (struct GNUNET_IDENTITY_Signature *)
557  buf_ptr))
558  {
559  GNUNET_break (0);
560  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to sign code\n");
561  GNUNET_free (code_payload);
562  return NULL;
563  }
564  GNUNET_STRINGS_base64url_encode (code_payload, code_payload_len, &code_str);
565  GNUNET_free (code_payload);
566  return code_str;
567 }
568 
569 
585 int
587  const char *code,
588  const char *code_verifier,
590  struct GNUNET_RECLAIM_AttributeList **attrs,
591  struct GNUNET_RECLAIM_PresentationList **presentations,
592  char **nonce_str)
593 {
594  char *code_payload;
595  char *ptr;
596  char *plaintext;
597  char *attrs_ser;
598  char *presentations_ser;
599  char *expected_code_challenge;
600  char *code_challenge;
601  char *code_verifier_hash;
603  struct GNUNET_IDENTITY_Signature *signature;
604  uint32_t code_challenge_len;
605  uint32_t attrs_ser_len;
606  uint32_t pres_ser_len;
607  size_t plaintext_len;
608  size_t code_payload_len;
609  uint32_t nonce_len = 0;
610  struct OIDC_Parameters *params;
611 
612  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to decode `%s'\n", code);
613  code_payload = NULL;
614  code_payload_len =
615  GNUNET_STRINGS_base64url_decode (code, strlen (code),
616  (void **) &code_payload);
617  if (code_payload_len < sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
618  + sizeof(struct OIDC_Parameters)
619  + sizeof(struct GNUNET_IDENTITY_Signature))
620  {
621  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Authorization code malformed\n");
622  GNUNET_free (code_payload);
623  return GNUNET_SYSERR;
624  }
625 
626  purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *) code_payload;
627  plaintext_len = code_payload_len;
628  plaintext_len -= sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose);
629  ptr = (char *) &purpose[1];
630  plaintext_len -= sizeof(struct GNUNET_IDENTITY_Signature);
631  plaintext = ptr;
632  ptr += plaintext_len;
633  signature = (struct GNUNET_IDENTITY_Signature *) ptr;
634  params = (struct OIDC_Parameters *) plaintext;
635 
636  // cmp code_challenge code_verifier
637  code_challenge_len = ntohl (params->code_challenge_len);
638  code_challenge = ((char *) &params[1]);
639  if (0 != code_challenge_len) /* Only check if this code requires a CV */
640  {
641  if (NULL == code_verifier)
642  {
644  "Expected code verifier!\n");
645  GNUNET_free (code_payload);
646  return GNUNET_SYSERR;
647  }
648  code_verifier_hash = GNUNET_malloc (256 / 8);
649  // hash code verifier
650  gcry_md_hash_buffer (GCRY_MD_SHA256,
651  code_verifier_hash,
652  code_verifier,
653  strlen (code_verifier));
654  // encode code verifier
655  GNUNET_STRINGS_base64url_encode (code_verifier_hash, 256 / 8,
656  &expected_code_challenge);
657  GNUNET_free (code_verifier_hash);
658  if (0 !=
659  strncmp (expected_code_challenge, code_challenge, code_challenge_len))
660  {
662  "Invalid code verifier! Expected: %s, Got: %.*s\n",
663  expected_code_challenge,
664  code_challenge_len,
665  code_challenge);
666  GNUNET_free (code_payload);
667  GNUNET_free (expected_code_challenge);
668  return GNUNET_SYSERR;
669  }
670  GNUNET_free (expected_code_challenge);
671  }
672  nonce_len = ntohl (params->nonce_len);
673  if (0 != nonce_len)
674  {
675  *nonce_str = GNUNET_strndup (code_challenge + code_challenge_len,
676  nonce_len);
677  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got nonce: %s\n", *nonce_str);
678  }
679 
680  // Ticket
681  memcpy (ticket, &params->ticket, sizeof(params->ticket));
682  // Signature
683  // GNUNET_CRYPTO_ecdsa_key_get_public (ecdsa_priv, &ecdsa_pub);
684  if (0 != GNUNET_memcmp (audience, &ticket->audience))
685  {
686  GNUNET_free (code_payload);
687  if (NULL != *nonce_str)
688  GNUNET_free (*nonce_str);
690  "Audience in ticket does not match client!\n");
691  return GNUNET_SYSERR;
692  }
693  if (GNUNET_OK !=
696  purpose,
697  signature,
698  &(ticket->identity)))
699  {
700  GNUNET_free (code_payload);
701  if (NULL != *nonce_str)
702  GNUNET_free (*nonce_str);
703  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Signature of AuthZ code invalid!\n");
704  return GNUNET_SYSERR;
705  }
706  // Attributes
707  attrs_ser = ((char *) &params[1]) + code_challenge_len + nonce_len;
708  attrs_ser_len = ntohl (params->attr_list_len);
709  *attrs = GNUNET_RECLAIM_attribute_list_deserialize (attrs_ser, attrs_ser_len);
710  presentations_ser = ((char*) attrs_ser) + attrs_ser_len;
711  pres_ser_len = ntohl (params->pres_list_len);
712  *presentations =
714  pres_ser_len);
715 
716  GNUNET_free (code_payload);
717  return GNUNET_OK;
718 }
719 
720 
730 void
731 OIDC_build_token_response (const char *access_token,
732  const char *id_token,
733  const struct GNUNET_TIME_Relative *expiration_time,
734  char **token_response)
735 {
736  json_t *root_json;
737 
738  root_json = json_object ();
739 
740  GNUNET_assert (NULL != access_token);
741  GNUNET_assert (NULL != id_token);
742  GNUNET_assert (NULL != expiration_time);
743  json_object_set_new (root_json, "access_token", json_string (access_token));
744  json_object_set_new (root_json, "token_type", json_string ("Bearer"));
745  json_object_set_new (root_json,
746  "expires_in",
747  json_integer (expiration_time->rel_value_us
748  / (1000 * 1000)));
749  json_object_set_new (root_json, "id_token", json_string (id_token));
750  *token_response = json_dumps (root_json, JSON_INDENT (0) | JSON_COMPACT);
751  json_decref (root_json);
752 }
753 
754 
758 char *
760 {
761  char *access_token;
762 
764  sizeof(*ticket),
765  &access_token);
766  return access_token;
767 }
768 
769 
773 int
774 OIDC_access_token_parse (const char *token,
775  struct GNUNET_RECLAIM_Ticket **ticket)
776 {
777  if (sizeof (struct GNUNET_RECLAIM_Ticket) !=
779  strlen (token),
780  (void**) ticket))
781  return GNUNET_SYSERR;
782  return GNUNET_OK;
783 }
784 
785 
796  const char*attr)
797 {
798  char *scope_variables;
799  char *scope_variable;
800  char delimiter[] = " ";
801  int i;
802 
803  scope_variables = GNUNET_strdup (scopes);
804  scope_variable = strtok (scope_variables, delimiter);
805  while (NULL != scope_variable)
806  {
807  if (0 == strcmp ("profile", scope_variable))
808  {
809  for (i = 0; i < 14; i++)
810  {
811  if (0 == strcmp (attr, OIDC_profile_claims[i]))
812  {
813  GNUNET_free (scope_variables);
814  return GNUNET_YES;
815  }
816  }
817  }
818  else if (0 == strcmp ("address", scope_variable))
819  {
820  for (i = 0; i < 5; i++)
821  {
822  if (0 == strcmp (attr, OIDC_address_claims[i]))
823  {
824  GNUNET_free (scope_variables);
825  return GNUNET_YES;
826  }
827  }
828  }
829  else if (0 == strcmp ("email", scope_variable))
830  {
831  for (i = 0; i < 2; i++)
832  {
833  if (0 == strcmp (attr, OIDC_email_claims[i]))
834  {
835  GNUNET_free (scope_variables);
836  return GNUNET_YES;
837  }
838  }
839  }
840  else if (0 == strcmp ("phone", scope_variable))
841  {
842  for (i = 0; i < 2; i++)
843  {
844  if (0 == strcmp (attr, OIDC_phone_claims[i]))
845  {
846  GNUNET_free (scope_variables);
847  return GNUNET_YES;
848  }
849  }
850 
851  }
852  else if (0 == strcmp (attr, scope_variable))
853  {
855  GNUNET_free (scope_variables);
856  return GNUNET_YES;
857  }
858  scope_variable = strtok (NULL, delimiter);
859  }
860  GNUNET_free (scope_variables);
861  return GNUNET_NO;
862 
863 }
int GNUNET_IDENTITY_signature_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_IDENTITY_Signature *sig, const struct GNUNET_IDENTITY_PublicKey *pub)
Verify a given signature.
The authorization ticket.
static enum GNUNET_GenericReturnValue is_claim_in_address_scope(const char *claim)
Definition: oidc_helper.c:103
uint64_t rel_value_us
The actual value.
uint32_t type
Type/Format of Claim.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
#define JWT_ALG_VALUE
Definition: oidc_helper.h:33
struct GNUNET_RECLAIM_Attribute * claim
Claim to store.
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn&#39; this be the standard hmac function and the abov...
Definition: crypto_hash.c:420
const char * name
The name of the attribute.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_RECLAIM_AttributeList * GNUNET_RECLAIM_attribute_list_deserialize(const char *data, size_t data_size)
Deserialize an attribute list.
struct GNUNET_RECLAIM_PresentationListEntry * next
DLL.
uint32_t attr_list_len
The length of the attributes list.
Definition: oidc_helper.c:62
uint32_t pres_list_len
The length of the presentation list.
Definition: oidc_helper.c:67
static char * create_jwt_header(void)
Definition: oidc_helper.c:118
A private key for an identity as per LSD0001.
struct GNUNET_RECLAIM_PresentationListEntry * list_head
List head.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
helper library for OIDC related functions
A list of GNUNET_RECLAIM_Attribute structures.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:395
#define SERVER_ADDRESS
Definition: oidc_helper.h:39
struct GNUNET_RECLAIM_Identifier credential
Referenced ID of credential (may be GNUNET_RECLAIM_ID_ZERO if self-creded)
void OIDC_build_token_response(const char *access_token, const char *id_token, const struct GNUNET_TIME_Relative *expiration_time, char **token_response)
Build a token response for a token request TODO: Maybe we should add the scope here?
Definition: oidc_helper.c:731
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
enum GNUNET_GenericReturnValue OIDC_check_scopes_for_claim_request(const char *scopes, const char *attr)
Checks if a claim is implicitly requested through standard scope(s) or explicitly through non-standar...
Definition: oidc_helper.c:795
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1932
struct GNUNET_RECLAIM_Attribute * attribute
The attribute claim.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
static char OIDC_email_claims[2][16]
Standard claims represented by the "email" scope in OIDC.
Definition: oidc_helper.c:84
#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN
Signature for a GNUid Ticket.
struct GNUNET_IDENTITY_PublicKey identity
The ticket issuer (= the user)
static void replace_char(char *str, char find, char replace)
Definition: oidc_helper.c:134
uint32_t code_challenge_len
The length of the PKCE code_challenge.
Definition: oidc_helper.c:57
An identity signature as per LSD0001.
const char * GNUNET_RECLAIM_presentation_number_to_typename(uint32_t type)
Convert a presentation type number to the corresponding credential type string.
char * OIDC_access_token_new(const struct GNUNET_RECLAIM_Ticket *ticket)
Generate a new access token.
Definition: oidc_helper.c:759
#define JWT_TYP
Definition: oidc_helper.h:35
static int result
Global testing status.
size_t GNUNET_RECLAIM_presentation_list_serialize_get_size(const struct GNUNET_RECLAIM_PresentationList *presentations)
Get required size for serialization buffer.
struct GNUNET_RECLAIM_Identifier credential_id
The credential id of which this is a presentation.
const void * data
Binary value stored as presentation value.
size_t data_size
Number of bytes in data.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
static GNUNET_NETWORK_STRUCT_END char OIDC_profile_claims[14][32]
Standard claims represented by the "profile" scope in OIDC.
Definition: oidc_helper.c:75
A 512-bit hashcode.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1978
char * OIDC_generate_id_token(const struct GNUNET_IDENTITY_PublicKey *aud_key, const struct GNUNET_IDENTITY_PublicKey *sub_key, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations, const struct GNUNET_TIME_Relative *expiration_time, const char *nonce, const char *secret_key)
Create a JWT from attributes.
Definition: oidc_helper.c:329
static void fix_base64(char *str)
Definition: oidc_helper.c:148
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1876
char * OIDC_build_authz_code(const struct GNUNET_IDENTITY_PrivateKey *issuer, const struct GNUNET_RECLAIM_Ticket *ticket, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations, const char *nonce_str, const char *code_challenge)
Builds an OIDC authorization code including a reclaim ticket and nonce.
Definition: oidc_helper.c:447
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int OIDC_parse_authz_code(const struct GNUNET_IDENTITY_PublicKey *audience, const char *code, const char *code_verifier, struct GNUNET_RECLAIM_Ticket *ticket, struct GNUNET_RECLAIM_AttributeList **attrs, struct GNUNET_RECLAIM_PresentationList **presentations, char **nonce_str)
Parse reclaim ticket and nonce from authorization code.
Definition: oidc_helper.c:586
size_t data_size
Number of bytes in data.
size_t GNUNET_RECLAIM_attribute_list_serialize(const struct GNUNET_RECLAIM_AttributeList *attrs, char *result)
Serialize an attribute list.
struct GNUNET_RECLAIM_AttributeListEntry * next
DLL.
static unsigned long long payload
How much data are we currently storing in the database?
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
static char OIDC_phone_claims[2][32]
Standard claims represented by the "phone" scope in OIDC.
Definition: oidc_helper.c:91
char * GNUNET_RECLAIM_presentation_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;claim&#39; of a presentation to a string.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
struct GNUNET_RECLAIM_Presentation * presentation
The credential.
static json_t * generate_userinfo_json(const struct GNUNET_IDENTITY_PublicKey *sub_key, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations)
Definition: oidc_helper.c:159
static char * subject
Subject pubkey string.
Definition: gnunet-abd.c:86
An identity key as per LSD0001.
A list of GNUNET_RECLAIM_Presentation structures.
#define GNUNET_PACKED
gcc-ism to get packed structs.
int GNUNET_IDENTITY_sign_(const struct GNUNET_IDENTITY_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_IDENTITY_Signature *sig)
Sign a given block.
static char OIDC_address_claims[5][32]
Standard claims represented by the "address" scope in OIDC.
Definition: oidc_helper.c:98
#define GNUNET_RECLAIM_id_is_equal(a, b)
struct GNUNET_IDENTITY_PublicKey audience
The ticket audience (= relying party)
#define GNUNET_log(kind,...)
const void * data
Binary value stored as attribute value.
char * GNUNET_RECLAIM_attribute_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;claim&#39; of an attribute to a string.
size_t GNUNET_RECLAIM_attribute_list_serialize_get_size(const struct GNUNET_RECLAIM_AttributeList *attrs)
Get required size for serialization buffer.
uint32_t type
Type of Claim.
#define JWT_ALG
Definition: oidc_helper.h:30
int OIDC_access_token_parse(const char *token, struct GNUNET_RECLAIM_Ticket **ticket)
Parse an access token.
Definition: oidc_helper.c:774
Time for absolute times used by GNUnet, in microseconds.
uint32_t nonce_len
The nonce length.
Definition: oidc_helper.c:52
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:937
#define JWT_TYP_VALUE
Definition: oidc_helper.h:37
struct GNUNET_RECLAIM_Ticket ticket
The reclaim ticket.
Definition: oidc_helper.c:47
size_t GNUNET_RECLAIM_presentation_list_serialize(const struct GNUNET_RECLAIM_PresentationList *presentations, char *result)
Serialize a presentation list.
char * OIDC_generate_userinfo(const struct GNUNET_IDENTITY_PublicKey *sub_key, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations)
Generate userinfo JSON as string.
Definition: oidc_helper.c:302
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:2050
struct GNUNET_RECLAIM_AttributeListEntry * list_head
List head.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_RECLAIM_PresentationList * GNUNET_RECLAIM_presentation_list_deserialize(const char *data, size_t data_size)
Deserialize a presentation list.
Time for relative time used by GNUnet, in microseconds.
The signature used to generate the authorization code.
Definition: oidc_helper.c:42
#define GNUNET_RECLAIM_id_is_zero(a)