2 This file is part of GNUnet
3 Copyright (C) 2010-2015 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file reclaim/oidc_helper.c
23 * @brief helper library for OIDC related functions
24 * @author Martin Schanzenbach
29 #include "gnunet_util_lib.h"
30 #include "gnunet_reclaim_attribute_lib.h"
31 #include "gnunet_reclaim_service.h"
32 #include "gnunet_signatures.h"
33 #include "oidc_helper.h"
34 // #include "benchmark.h"
37 GNUNET_NETWORK_STRUCT_BEGIN
40 * The signature used to generate the authorization code
42 struct OIDC_Parameters
47 struct GNUNET_RECLAIM_Ticket ticket;
52 uint32_t nonce GNUNET_PACKED;
55 * The length of the PKCE code_challenge
57 uint32_t code_challenge_len GNUNET_PACKED;
60 * The length of the attributes list
62 uint32_t attr_list_len GNUNET_PACKED;
65 GNUNET_NETWORK_STRUCT_END
68 create_jwt_header (void)
73 root = json_object ();
74 json_object_set_new (root, JWT_ALG, json_string (JWT_ALG_VALUE));
75 json_object_set_new (root, JWT_TYP, json_string (JWT_TYP_VALUE));
77 json_str = json_dumps (root, JSON_INDENT (0) | JSON_COMPACT);
84 replace_char (char *str, char find, char replace)
86 char *current_pos = strchr (str, find);
90 *current_pos = replace;
91 current_pos = strchr (current_pos, find);
98 fix_base64 (char *str)
101 replace_char (str, '+', '-');
104 replace_char (str, '/', '_');
109 * Create a JWT from attributes
111 * @param aud_key the public of the audience
112 * @param sub_key the public key of the subject
113 * @param attrs the attribute list
114 * @param expiration_time the validity of the token
115 * @param secret_key the key used to sign the JWT
116 * @return a new base64-encoded JWT string.
119 OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
120 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
121 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
122 const struct GNUNET_TIME_Relative *expiration_time,
124 const char *secret_key)
126 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
127 struct GNUNET_HashCode signature;
128 struct GNUNET_TIME_Absolute exp_time;
129 struct GNUNET_TIME_Absolute time_now;
134 char *aggr_names_str;
135 char *aggr_sources_str;
136 char *aggr_sources_jwt_str;
141 char *signature_target;
142 char *signature_base64;
144 char *attest_val_str;
147 json_t *aggr_sources;
148 json_t *aggr_sources_jwt;
149 uint64_t attest_arr[GNUNET_RECLAIM_ATTRIBUTE_list_count_attest (attrs)];
151 // iat REQUIRED time now
152 time_now = GNUNET_TIME_absolute_get ();
153 // exp REQUIRED time expired from config
154 exp_time = GNUNET_TIME_absolute_add (time_now, *expiration_time);
155 // auth_time only if max_age
156 // nonce only if nonce
157 // OPTIONAL acr,amr,azp
159 GNUNET_STRINGS_data_to_string_alloc (sub_key,
161 GNUNET_CRYPTO_EcdsaPublicKey));
163 GNUNET_STRINGS_data_to_string_alloc (aud_key,
165 GNUNET_CRYPTO_EcdsaPublicKey));
166 header = create_jwt_header ();
167 body = json_object ();
168 aggr_names = json_object ();
169 aggr_sources = json_object ();
171 // iss REQUIRED case sensitive server uri with https
172 // The issuer is the local reclaim instance (e.g.
173 // https://reclaim.id/api/openid)
174 json_object_set_new (body, "iss", json_string (SERVER_ADDRESS));
175 // sub REQUIRED public key identity, not exceed 255 ASCII length
176 json_object_set_new (body, "sub", json_string (subject));
177 // aud REQUIRED public key client_id must be there
178 json_object_set_new (body, "aud", json_string (audience));
180 json_object_set_new (body,
182 json_integer (time_now.abs_value_us / (1000 * 1000)));
184 json_object_set_new (body,
186 json_integer (exp_time.abs_value_us / (1000 * 1000)));
188 json_object_set_new (body,
190 json_integer (time_now.abs_value_us / (1000 * 1000)));
193 json_object_set_new (body, "nonce", json_string (nonce));
195 attest_val_str = NULL;
196 aggr_names_str = NULL;
197 aggr_sources_str = NULL;
198 aggr_sources_jwt_str = NULL;
200 for (le = attrs->list_head; NULL != le; le = le->next)
203 if (le->claim != NULL)
207 GNUNET_RECLAIM_ATTRIBUTE_value_to_string (le->claim->type,
209 le->claim->data_size);
210 json_object_set_new (body, le->claim->name, json_string (attr_val_str));
211 GNUNET_free (attr_val_str);
213 else if (NULL != le->reference)
215 // Check if attest is there
219 if (attest_arr[j] == le->reference->id_attest)
225 // Attest not yet existent. Append to the end of the list
226 GNUNET_CONTAINER_DLL_remove (attrs->list_head, attrs->list_tail, le);
227 GNUNET_CONTAINER_DLL_insert_tail (attrs->list_head, attrs->list_tail,
233 // Attestation is existing, hence take the respective source str
234 GNUNET_asprintf (&source_name,
237 json_object_set_new (aggr_names, le->reference->name, json_string (
242 else if (NULL != le->attest)
244 // We assume that at max 99 different attestations
248 if (attest_arr[j] == le->attest->id)
255 attest_arr[i] = le->attest->id;
256 GNUNET_asprintf (&source_name,
259 aggr_sources_jwt = json_object ();
260 attest_val_str = GNUNET_RECLAIM_ATTESTATION_value_to_string (
261 le->attest->type, le->attest->data, le->attest->data_size);
262 json_object_set_new (aggr_sources_jwt, "JWT",json_string (
264 aggr_sources_jwt_str = json_dumps (aggr_sources_jwt, JSON_INDENT (0)
266 json_object_set_new (aggr_sources, source_name,json_string (
267 aggr_sources_jwt_str));
272 // Attestation already existent. Ignore
278 if (NULL != attest_val_str)
279 GNUNET_free (attest_val_str);
280 if (NULL != source_name)
281 GNUNET_free (source_name);
284 aggr_names_str = json_dumps (aggr_names, JSON_INDENT (0) | JSON_COMPACT);
285 aggr_sources_str = json_dumps (aggr_sources, JSON_INDENT (0)
287 json_object_set_new (body, "_claim_names", json_string (aggr_names_str));
288 json_object_set_new (body, "_claim_sources", json_string (
292 json_decref (aggr_names);
293 json_decref (aggr_sources);
294 json_decref (aggr_sources_jwt);
296 body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT);
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"ID-Token: %s\n", body_str);
300 GNUNET_STRINGS_base64_encode (header, strlen (header), &header_base64);
301 fix_base64 (header_base64);
303 GNUNET_STRINGS_base64_encode (body_str, strlen (body_str), &body_base64);
304 fix_base64 (body_base64);
306 GNUNET_free (subject);
307 GNUNET_free (audience);
310 * Creating the JWT signature. This might not be
311 * standards compliant, check.
313 GNUNET_asprintf (&signature_target, "%s.%s", header_base64, body_base64);
314 GNUNET_CRYPTO_hmac_raw (secret_key,
317 strlen (signature_target),
319 GNUNET_STRINGS_base64_encode ((const char *) &signature,
320 sizeof(struct GNUNET_HashCode),
322 fix_base64 (signature_base64);
324 GNUNET_asprintf (&result,
330 GNUNET_free (signature_target);
331 GNUNET_free (header);
332 GNUNET_free (body_str);
333 if (NULL != aggr_sources_str)
334 GNUNET_free (aggr_sources_str);
335 if (NULL != aggr_names_str)
336 GNUNET_free (aggr_names_str);
337 if (NULL != aggr_sources_jwt_str)
338 GNUNET_free (aggr_sources_jwt_str);
339 GNUNET_free (signature_base64);
340 GNUNET_free (body_base64);
341 GNUNET_free (header_base64);
346 /* Converts a hex character to its integer value */
350 return isdigit (ch) ? ch - '0' : tolower (ch) - 'a' + 10;
354 /* Converts an integer value to its hex character*/
358 static char hex[] = "0123456789abcdef";
360 return hex[code & 15];
364 /* Returns a url-encoded version of str */
365 /* IMPORTANT: be sure to free() the returned string after use */
367 url_encode (const char *str)
369 char *pstr = (char *) str;
370 char *buf = GNUNET_malloc (strlen (str) * 3 + 1);
375 if (isalnum (*pstr) || (*pstr == '-') || (*pstr == '_') || (*pstr == '.') ||
378 else if (*pstr == ' ')
383 *pbuf++ = to_hex (*pstr >> 4);
384 *pbuf++ = to_hex (*pstr & 15);
393 /* Returns a url-decoded version of str */
394 /* IMPORTANT: be sure to free() the returned string after use */
396 url_decode (const char *str)
398 char *pstr = (char *) str;
399 char *buf = GNUNET_malloc (strlen (str) + 1);
406 if (pstr[1] && pstr[2])
408 *pbuf++ = from_hex (pstr[1]) << 4 | from_hex (pstr[2]);
412 else if (*pstr == '+')
428 * Returns base64 encoded string urlencoded
430 * @param string the string to encode
431 * @return base64 encoded string
434 base64_and_urlencode (const char *data, size_t data_size)
439 GNUNET_STRINGS_base64_encode (data, data_size, &enc);
440 urlenc = url_encode (enc);
447 * Returns base64 encoded string urlencoded
449 * @param string the string to encode
450 * @return base64 encoded string
453 base64url_encode (const char *data, size_t data_size)
458 GNUNET_STRINGS_base64_encode (data, data_size, &enc);
459 // Replace with correct characters for base64url
461 while ('\0' != enc[pos])
479 derive_aes_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
480 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
481 struct GNUNET_HashCode *key_material)
483 static const char ctx_key[] = "reclaim-aes-ctx-key";
484 static const char ctx_iv[] = "reclaim-aes-ctx-iv";
486 GNUNET_CRYPTO_kdf (key,
487 sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey),
491 sizeof(struct GNUNET_HashCode),
493 GNUNET_CRYPTO_kdf (iv,
495 struct GNUNET_CRYPTO_SymmetricInitializationVector),
499 sizeof(struct GNUNET_HashCode),
505 calculate_key_priv (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
506 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
507 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
508 const struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_pub)
510 struct GNUNET_HashCode key_material;
512 GNUNET_CRYPTO_ecdsa_ecdh (ecdsa_priv, ecdh_pub, &key_material);
513 derive_aes_key (key, iv, &key_material);
518 calculate_key_pub (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
519 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
520 const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub,
521 const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv)
523 struct GNUNET_HashCode key_material;
525 GNUNET_CRYPTO_ecdh_ecdsa (ecdh_priv, ecdsa_pub, &key_material);
526 derive_aes_key (key, iv, &key_material);
531 decrypt_payload (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
532 const struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_pub,
537 struct GNUNET_CRYPTO_SymmetricSessionKey key;
538 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
540 calculate_key_priv (&key, &iv, ecdsa_priv, ecdh_pub);
541 GNUNET_break (GNUNET_CRYPTO_symmetric_decrypt (ct, ct_len, &key, &iv, buf));
546 encrypt_payload (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub,
547 const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv,
552 struct GNUNET_CRYPTO_SymmetricSessionKey key;
553 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
555 calculate_key_pub (&key, &iv, ecdsa_pub, ecdh_priv);
557 GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len, &key, &iv, buf));
562 * Builds an OIDC authorization code including
563 * a reclaim ticket and nonce
565 * @param issuer the issuer of the ticket, used to sign the ticket and nonce
566 * @param ticket the ticket to include in the code
567 * @param attrs list of attributes which are shared
568 * @param nonce the nonce to include in the code
569 * @param code_challenge PKCE code challenge
570 * @return a new authorization code (caller must free)
573 OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
574 const struct GNUNET_RECLAIM_Ticket *ticket,
575 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
576 const char *nonce_str,
577 const char *code_challenge)
579 struct OIDC_Parameters params;
584 char *buf_ptr = NULL;
586 size_t code_payload_len;
587 size_t attr_list_len = 0;
588 size_t code_challenge_len = 0;
591 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
592 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv;
593 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pub;
597 memset (¶ms, 0, sizeof(params));
598 params.ticket = *ticket;
601 payload_len = sizeof(struct OIDC_Parameters);
602 if ((NULL != nonce_str) && (strcmp ("", nonce_str) != 0))
604 if ((1 != sscanf (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX))
607 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid nonce %s\n", nonce_str);
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
611 "Got nonce: %u from %s\n",
615 nonce_tmp = htonl (nonce);
616 params.nonce = nonce_tmp;
617 // Assign code challenge
618 if (NULL != code_challenge)
619 code_challenge_len = strlen (code_challenge);
620 payload_len += code_challenge_len;
621 params.code_challenge_len = htonl (code_challenge_len);
626 attr_list_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
627 params.attr_list_len = htonl (attr_list_len);
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
629 "Length of serialized attributes: %lu\n",
631 // Get serialized attributes
632 payload_len += attr_list_len;
634 // Get plaintext length
635 payload = GNUNET_malloc (payload_len);
636 memcpy (payload, ¶ms, sizeof(params));
637 tmp = payload + sizeof(params);
638 if (0 < code_challenge_len)
640 memcpy (tmp, code_challenge, code_challenge_len);
641 tmp += code_challenge_len;
643 if (0 < attr_list_len)
644 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, tmp);
649 code_payload_len = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
650 + sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)
651 + payload_len + sizeof(struct
652 GNUNET_CRYPTO_EcdsaSignature);
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Length of data to encode: %lu\n",
658 ecdh_priv = GNUNET_CRYPTO_ecdhe_key_create ();
659 GNUNET_CRYPTO_ecdhe_key_get_public (ecdh_priv, &ecdh_pub);
660 // Initialize code payload
661 code_payload = GNUNET_malloc (code_payload_len);
662 GNUNET_assert (NULL != code_payload);
663 purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *) code_payload;
664 purpose->size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
665 + sizeof(ecdh_pub) + payload_len);
666 purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN);
668 buf_ptr = (char *) &purpose[1];
669 memcpy (buf_ptr, &ecdh_pub, sizeof(ecdh_pub));
670 buf_ptr += sizeof(ecdh_pub);
671 // Encrypt plaintext and store
672 encrypt_payload (&ticket->audience, ecdh_priv, payload, payload_len, buf_ptr);
673 GNUNET_free (ecdh_priv);
674 GNUNET_free (payload);
675 buf_ptr += payload_len;
676 // Sign and store signature
678 GNUNET_CRYPTO_ecdsa_sign (issuer,
680 (struct GNUNET_CRYPTO_EcdsaSignature *)
684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to sign code\n");
685 GNUNET_free (code_payload);
688 code_str = base64_and_urlencode (code_payload, code_payload_len);
689 GNUNET_free (code_payload);
695 * Parse reclaim ticket and nonce from
696 * authorization code.
697 * This also verifies the signature in the code.
699 * @param audience the expected audience of the code
700 * @param code the string representation of the code
701 * @param code_verfier PKCE code verifier
702 * @param ticket where to store the ticket
703 * @param attrs the attributes in the code
704 * @param nonce where to store the nonce
705 * @return GNUNET_OK if successful, else GNUNET_SYSERR
708 OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
710 const char *code_verifier,
711 struct GNUNET_RECLAIM_Ticket *ticket,
712 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList **attrs,
719 char *expected_code_challenge;
720 char *code_challenge;
721 char *code_verifier_hash;
722 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
723 struct GNUNET_CRYPTO_EcdsaSignature *signature;
724 struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_pub;
725 struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_pub;
726 uint32_t code_challenge_len;
727 uint32_t attrs_ser_len;
728 size_t plaintext_len;
729 size_t code_payload_len;
731 struct OIDC_Parameters *params;
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to decode `%s'\n", code);
736 GNUNET_STRINGS_base64_decode (code, strlen (code), (void **) &code_payload);
737 if (code_payload_len < sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
738 + sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)
739 + sizeof(struct OIDC_Parameters)
740 + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))
742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Authorization code malformed\n");
743 GNUNET_free_non_null (code_payload);
744 return GNUNET_SYSERR;
747 purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *) code_payload;
748 plaintext_len = code_payload_len;
749 plaintext_len -= sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose);
750 ptr = (char *) &purpose[1];
752 ecdh_pub = (struct GNUNET_CRYPTO_EcdhePublicKey *) ptr;
753 ptr += sizeof(struct GNUNET_CRYPTO_EcdhePublicKey);
754 plaintext_len -= sizeof(struct GNUNET_CRYPTO_EcdhePublicKey);
756 // Decrypt ciphertext
757 plaintext_len -= sizeof(struct GNUNET_CRYPTO_EcdsaSignature);
758 plaintext = GNUNET_malloc (plaintext_len);
759 decrypt_payload (ecdsa_priv, ecdh_pub, ptr, plaintext_len, plaintext);
761 ptr += plaintext_len;
762 signature = (struct GNUNET_CRYPTO_EcdsaSignature *) ptr;
763 params = (struct OIDC_Parameters *) plaintext;
765 // cmp code_challenge code_verifier
766 code_challenge_len = ntohl (params->code_challenge_len);
767 if (0 != code_challenge_len) /* Only check if this code requires a CV */
769 if (NULL == code_verifier)
771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
772 "Expected code verifier!\n");
773 GNUNET_free_non_null (code_payload);
774 return GNUNET_SYSERR;
776 code_verifier_hash = GNUNET_malloc (256 / 8);
777 // hash code verifier
778 gcry_md_hash_buffer (GCRY_MD_SHA256,
781 strlen (code_verifier));
782 // encode code verifier
783 expected_code_challenge = base64url_encode (code_verifier_hash, 256 / 8);
784 code_challenge = (char *) ¶ms[1];
785 GNUNET_free (code_verifier_hash);
786 if ((strlen (expected_code_challenge) != code_challenge_len) ||
788 strncmp (expected_code_challenge, code_challenge, code_challenge_len)))
790 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
791 "Invalid code verifier! Expected: %s, Got: %.*s\n",
792 expected_code_challenge,
795 GNUNET_free_non_null (code_payload);
796 GNUNET_free (expected_code_challenge);
797 return GNUNET_SYSERR;
799 GNUNET_free (expected_code_challenge);
802 memcpy (ticket, ¶ms->ticket, sizeof(params->ticket));
804 nonce = ntohl (params->nonce); // ntohl (*((uint32_t *) ptr));
805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got nonce: %u\n", nonce);
807 GNUNET_CRYPTO_ecdsa_key_get_public (ecdsa_priv, &ecdsa_pub);
808 if (0 != GNUNET_memcmp (&ecdsa_pub, &ticket->audience))
810 GNUNET_free (code_payload);
811 GNUNET_free (plaintext);
812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
813 "Audience in ticket does not match client!\n");
814 return GNUNET_SYSERR;
817 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN,
822 GNUNET_free (code_payload);
823 GNUNET_free (plaintext);
824 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Signature of AuthZ code invalid!\n");
825 return GNUNET_SYSERR;
828 attrs_ser = ((char *) ¶ms[1]) + code_challenge_len;
829 attrs_ser_len = ntohl (params->attr_list_len);
830 *attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attrs_ser, attrs_ser_len);
834 GNUNET_asprintf (nonce_str, "%u", nonce);
835 GNUNET_free (code_payload);
836 GNUNET_free (plaintext);
842 * Build a token response for a token request
843 * TODO: Maybe we should add the scope here?
845 * @param access_token the access token to include
846 * @param id_token the id_token to include
847 * @param expiration_time the expiration time of the token(s)
848 * @param token_response where to store the response
851 OIDC_build_token_response (const char *access_token,
852 const char *id_token,
853 const struct GNUNET_TIME_Relative *expiration_time,
854 char **token_response)
858 root_json = json_object ();
860 GNUNET_assert (NULL != access_token);
861 GNUNET_assert (NULL != id_token);
862 GNUNET_assert (NULL != expiration_time);
863 json_object_set_new (root_json, "access_token", json_string (access_token));
864 json_object_set_new (root_json, "token_type", json_string ("Bearer"));
865 json_object_set_new (root_json,
867 json_integer (expiration_time->rel_value_us
869 json_object_set_new (root_json, "id_token", json_string (id_token));
870 *token_response = json_dumps (root_json, JSON_INDENT (0) | JSON_COMPACT);
871 json_decref (root_json);
876 * Generate a new access token
879 OIDC_access_token_new ()
882 uint64_t random_number;
885 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
886 GNUNET_STRINGS_base64_encode (&random_number,