#include <inttypes.h>#include <jansson.h>#include <jose/jose.h>#include "gnunet_gns_service.h"#include "gnunet_gnsrecord_lib.h"#include "gnunet_util_lib.h"#include "gnunet_reclaim_lib.h"#include "gnunet_reclaim_service.h"#include "gnunet_signatures.h"#include "oidc_helper.h"#include <gcrypt.h>Go to the source code of this file.
| Data Structures | |
| struct | OIDC_Parameters | 
| The signature used to generate the authorization code.  More... | |
| Functions | |
| static enum GNUNET_GenericReturnValue | is_claim_in_address_scope (const char *claim) | 
| static char * | create_jwt_hmac_header (void) | 
| static void | replace_char (char *str, char find, char replace) | 
| static void | fix_base64 (char *str) | 
| static json_t * | generate_userinfo_json (const struct GNUNET_CRYPTO_BlindablePublicKey *sub_key, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations) | 
| char * | OIDC_generate_userinfo (const struct GNUNET_CRYPTO_BlindablePublicKey *sub_key, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations) | 
| Generate userinfo JSON as string. | |
| static char * | generate_id_token_body (const char *rp_uri, const struct GNUNET_CRYPTO_BlindablePublicKey *sub_key, const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_RECLAIM_PresentationList *presentations, const struct GNUNET_TIME_Relative *expiration_time, const char *nonce) | 
| char * | OIDC_generate_id_token_rsa (const char *rp_uri, const struct GNUNET_CRYPTO_BlindablePublicKey *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 json_t *secret_rsa_key) | 
| Create a JWT using RSA256 algorithm from attributes. | |
| char * | OIDC_generate_id_token_hmac (const char *rp_uri, const struct GNUNET_CRYPTO_BlindablePublicKey *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 using HMAC (HS256) from attributes. | |
| char * | OIDC_build_authz_code (const struct GNUNET_CRYPTO_BlindablePrivateKey *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. | |
| static enum GNUNET_GenericReturnValue | check_code_challenge (const char *code_challenge, uint32_t code_challenge_len, const char *code_verifier) | 
| int | OIDC_parse_authz_code (const char *rp_uri, const struct GNUNET_CRYPTO_BlindablePublicKey *cid, 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, enum OIDC_VerificationOptions opts, char **emsg) | 
| Parse reclaim ticket and nonce from authorization code. | |
| 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? | |
| char * | OIDC_access_token_new (const struct GNUNET_RECLAIM_Ticket *ticket, const char *rp_uri) | 
| Generate a new access token. | |
| int | OIDC_access_token_parse (const char *token, struct GNUNET_RECLAIM_Ticket **ticket, char **rp_uri) | 
| Parse an access token. | |
| 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-standard scope. | |
| Variables | |
| static GNUNET_NETWORK_STRUCT_END char | OIDC_profile_claims [14][32] | 
| Standard claims represented by the "profile" scope in OIDC. | |
| static char | OIDC_email_claims [2][16] | 
| Standard claims represented by the "email" scope in OIDC. | |
| static char | OIDC_phone_claims [2][32] | 
| Standard claims represented by the "phone" scope in OIDC. | |
| static char | OIDC_address_claims [5][32] | 
| Standard claims represented by the "address" scope in OIDC. | |
| 
 | static | 
Definition at line 106 of file oidc_helper.c.
References claim, GNUNET_NO, GNUNET_YES, and OIDC_address_claims.
Referenced by generate_userinfo_json().
| 
 | static | 
Definition at line 121 of file oidc_helper.c.
References JWT_ALG, JWT_ALG_VALUE_HMAC, JWT_TYP, and JWT_TYP_VALUE.
Referenced by OIDC_generate_id_token_hmac().
| 
 | static | 
Definition at line 137 of file oidc_helper.c.
Referenced by fix_base64().
| 
 | static | 
Definition at line 151 of file oidc_helper.c.
References replace_char(), and str.
Referenced by OIDC_generate_id_token_hmac().
| 
 | static | 
There is this weird quirk that the individual address claim(s) must be inside a JSON object of the "address" claim.
There is this weird quirk that the individual address claim(s) must be inside a JSON object of the "address" claim.
This is/can only be set once!
Definition at line 162 of file oidc_helper.c.
References GNUNET_RECLAIM_AttributeListEntry::attribute, GNUNET_RECLAIM_Attribute::credential, GNUNET_RECLAIM_Presentation::credential_id, GNUNET_RECLAIM_Attribute::data, GNUNET_RECLAIM_Presentation::data, GNUNET_RECLAIM_Attribute::data_size, GNUNET_RECLAIM_Presentation::data_size, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_RECLAIM_attribute_value_to_string(), GNUNET_RECLAIM_id_is_equal, GNUNET_RECLAIM_id_is_zero, GNUNET_RECLAIM_presentation_number_to_typename(), GNUNET_RECLAIM_presentation_value_to_string(), GNUNET_STRINGS_data_to_string_alloc(), GNUNET_YES, is_claim_in_address_scope(), GNUNET_RECLAIM_AttributeList::list_head, GNUNET_RECLAIM_PresentationList::list_head, GNUNET_RECLAIM_Attribute::name, GNUNET_RECLAIM_AttributeListEntry::next, GNUNET_RECLAIM_PresentationListEntry::next, GNUNET_RECLAIM_PresentationListEntry::presentation, SERVER_ADDRESS, subject, GNUNET_RECLAIM_Attribute::type, and GNUNET_RECLAIM_Presentation::type.
Referenced by generate_id_token_body(), and OIDC_generate_userinfo().
| char * OIDC_generate_userinfo | ( | const struct GNUNET_CRYPTO_BlindablePublicKey * | sub_key, | 
| const struct GNUNET_RECLAIM_AttributeList * | attrs, | ||
| const struct GNUNET_RECLAIM_PresentationList * | presentations | ||
| ) | 
Generate userinfo JSON as string.
| sub_key | the subject (user) | 
| attrs | user attribute list | 
| presentations | credential presentation list (may be empty) | 
Definition at line 342 of file oidc_helper.c.
References generate_userinfo_json().
Referenced by consume_fail(), and consume_ticket().
| 
 | static | 
Definition at line 358 of file oidc_helper.c.
References GNUNET_TIME_Absolute::abs_value_us, generate_userinfo_json(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), and subject.
Referenced by OIDC_generate_id_token_hmac(), and OIDC_generate_id_token_rsa().
| char * OIDC_generate_id_token_rsa | ( | const char * | rp_uri, | 
| const struct GNUNET_CRYPTO_BlindablePublicKey * | 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 json_t * | secret_rsa_key | ||
| ) | 
Create a JWT using RSA256 algorithm from attributes.
| rp_uri | the RP URI | 
| sub_key | the public key of the subject | 
| attrs | the attribute list | 
| presentations | credential presentation list (may be empty) | 
| expiration_time | the validity of the token | 
| secret_rsa_key | the key used to sign the JWT | 
Definition at line 417 of file oidc_helper.c.
References generate_id_token_body(), GNUNET_asprintf(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, and result.
Referenced by token_endpoint().
| char * OIDC_generate_id_token_hmac | ( | const char * | rp_uri, | 
| const struct GNUNET_CRYPTO_BlindablePublicKey * | 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 using HMAC (HS256) from attributes.
| rp_uri | the RP URI | 
| sub_key | the public key of the subject | 
| attrs | the attribute list | 
| presentations | credential presentation list (may be empty) | 
| expiration_time | the validity of the token | 
| secret_key | the key used to sign the JWT | 
Creating the JWT signature. This might not be standards compliant, check.
Definition at line 470 of file oidc_helper.c.
References create_jwt_hmac_header(), fix_base64(), generate_id_token_body(), GNUNET_asprintf(), GNUNET_CRYPTO_hmac_raw(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_STRINGS_base64url_encode(), and result.
Referenced by token_endpoint().
| char * OIDC_build_authz_code | ( | const struct GNUNET_CRYPTO_BlindablePrivateKey * | 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.
| issuer | the issuer of the ticket, used to sign the ticket and nonce | 
| ticket | the ticket to include in the code | 
| attrs | list of attributes which are shared | 
| presentations | credential presentation list (may be empty) | 
| nonce | the nonce to include in the code | 
| code_challenge | PKCE code challenge | 
PLAINTEXT
END
Definition at line 563 of file oidc_helper.c.
References OIDC_Parameters::attr_list_len, OIDC_Parameters::code_challenge_len, GNUNET_RECLAIM_Ticket::gns_name, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_blinded_key_sign_(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_RECLAIM_attribute_list_serialize(), GNUNET_RECLAIM_attribute_list_serialize_get_size(), GNUNET_RECLAIM_presentation_list_serialize(), GNUNET_RECLAIM_presentation_list_serialize_get_size(), GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN, GNUNET_STRINGS_base64url_encode(), GNUNET_SYSERR, OIDC_Parameters::nonce_len, payload, OIDC_Parameters::pres_list_len, GNUNET_CRYPTO_SignaturePurpose::purpose, ticket, and OIDC_Parameters::ticket.
Referenced by oidc_ticket_issue_cb().
| 
 | static | 
Definition at line 695 of file oidc_helper.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_base64url_encode(), and GNUNET_SYSERR.
Referenced by OIDC_parse_authz_code().
| int OIDC_parse_authz_code | ( | const char * | rp_uri, | 
| const struct GNUNET_CRYPTO_BlindablePublicKey * | cid, | ||
| 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, | ||
| enum OIDC_VerificationOptions | opts, | ||
| char ** | emsg | ||
| ) | 
Parse reclaim ticket and nonce from authorization code.
This also verifies the signature in the code.
| audience | the expected audience of the code | 
| code | the string representation of the code | 
| code_verfier | PKCE code verifier. Optional, must be provided if used in request. | 
| ticket | where to store the ticket | 
| attrs | the attributes in the code | 
| presentations | credential presentation list | 
| nonce_str | where to store the nonce (if contained) | 
Definition at line 752 of file oidc_helper.c.
References OIDC_Parameters::attr_list_len, check_code_challenge(), OIDC_Parameters::code_challenge_len, GNUNET_RECLAIM_Ticket::gns_name, GNUNET_asprintf(), GNUNET_CRYPTO_blinded_key_signature_verify_(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNS_parse_ztld(), GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_attribute_list_deserialize(), GNUNET_RECLAIM_presentation_list_deserialize(), GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN, GNUNET_strdup, GNUNET_STRINGS_base64url_decode(), GNUNET_strndup, GNUNET_SYSERR, OIDC_Parameters::nonce_len, OIDC_VERIFICATION_NO_CODE_VERIFIER, OIDC_Parameters::pres_list_len, GNUNET_CRYPTO_SignaturePurpose::purpose, ticket, and OIDC_Parameters::ticket.
Referenced by consume_fail(), and token_endpoint().
| 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?
| access_token | the access token to include | 
| id_token | the id_token to include | 
| expiration_time | the expiration time of the token(s) | 
| token_response | where to store the response | 
Definition at line 871 of file oidc_helper.c.
References GNUNET_assert, and GNUNET_TIME_Relative::rel_value_us.
Referenced by token_endpoint().
| char * OIDC_access_token_new | ( | const struct GNUNET_RECLAIM_Ticket * | ticket, | 
| const char * | rp_uri | ||
| ) | 
Generate a new access token.
Definition at line 899 of file oidc_helper.c.
References GNUNET_asprintf(), GNUNET_free, GNUNET_STRINGS_base64_encode(), and ticket.
Referenced by token_endpoint().
| int OIDC_access_token_parse | ( | const char * | token, | 
| struct GNUNET_RECLAIM_Ticket ** | ticket, | ||
| char ** | rp_uri | ||
| ) | 
Parse an access token.
Definition at line 918 of file oidc_helper.c.
References GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, and ticket.
Referenced by userinfo_endpoint().
| 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-standard scope.
Checks if a claim is implicitly requested through standard scope(s)
| scopes | the scopes which have been requested | 
| attr | the attribute name to check | 
attribute matches requested scope
Definition at line 957 of file oidc_helper.c.
References GNUNET_free, GNUNET_NO, GNUNET_strdup, GNUNET_YES, OIDC_address_claims, OIDC_email_claims, OIDC_phone_claims, and OIDC_profile_claims.
Referenced by attr_in_claims_request().
| 
 | static | 
Standard claims represented by the "profile" scope in OIDC.
Definition at line 78 of file oidc_helper.c.
Referenced by OIDC_check_scopes_for_claim_request().
| 
 | static | 
Standard claims represented by the "email" scope in OIDC.
Definition at line 87 of file oidc_helper.c.
Referenced by OIDC_check_scopes_for_claim_request().
| 
 | static | 
Standard claims represented by the "phone" scope in OIDC.
Definition at line 94 of file oidc_helper.c.
Referenced by OIDC_check_scopes_for_claim_request().
| 
 | static | 
Standard claims represented by the "address" scope in OIDC.
Definition at line 101 of file oidc_helper.c.
Referenced by is_claim_in_address_scope(), and OIDC_check_scopes_for_claim_request().