You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
6.2 KiB

  1. From da16f9c20dda74dc689c9564d1791cc2af3ede9d Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <daniel@makrotopia.org>
  3. Date: Thu, 28 Feb 2019 16:23:40 +0100
  4. Subject: [PATCH] rest-plugins: include headers in dist sources
  5. ---
  6. src/rest-plugins/Makefile.am | 2 ++
  7. 1 file changed, 2 insertions(+)
  8. --- a/src/rest-plugins/Makefile.am
  9. +++ b/src/rest-plugins/Makefile.am
  10. @@ -30,6 +30,7 @@ endif
  11. libgnunet_plugin_rest_reclaim_la_SOURCES = \
  12. plugin_rest_reclaim.c \
  13. + json_reclaim.h \
  14. json_reclaim.c
  15. libgnunet_plugin_rest_reclaim_la_LIBADD = \
  16. $(top_builddir)/src/identity/libgnunetidentity.la \
  17. @@ -117,6 +118,7 @@ libgnunet_plugin_rest_gns_la_LDFLAGS = \
  18. libgnunet_plugin_rest_openid_connect_la_SOURCES = \
  19. plugin_rest_openid_connect.c \
  20. + oidc_helper.h \
  21. oidc_helper.c
  22. libgnunet_plugin_rest_openid_connect_la_LIBADD = \
  23. $(top_builddir)/src/identity/libgnunetidentity.la \
  24. --- /dev/null
  25. +++ b/src/rest-plugins/oidc_helper.h
  26. @@ -0,0 +1,111 @@
  27. +/*
  28. + This file is part of GNUnet
  29. + Copyright (C) 2010-2015 GNUnet e.V.
  30. +
  31. + GNUnet is free software: you can redistribute it and/or modify it
  32. + under the terms of the GNU Affero General Public License as published
  33. + by the Free Software Foundation, either version 3 of the License,
  34. + or (at your option) any later version.
  35. +
  36. + GNUnet is distributed in the hope that it will be useful, but
  37. + WITHOUT ANY WARRANTY; without even the implied warranty of
  38. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  39. + Affero General Public License for more details.
  40. +
  41. + You should have received a copy of the GNU Affero General Public License
  42. + along with this program. If not, see <http://www.gnu.org/licenses/>.
  43. +
  44. + SPDX-License-Identifier: AGPL3.0-or-later
  45. + */
  46. +
  47. +/**
  48. + * @file reclaim/oidc_helper.h
  49. + * @brief helper library for OIDC related functions
  50. + * @author Martin Schanzenbach
  51. + */
  52. +
  53. +#ifndef JWT_H
  54. +#define JWT_H
  55. +
  56. +#define JWT_ALG "alg"
  57. +
  58. +/* Use 512bit HMAC */
  59. +#define JWT_ALG_VALUE "HS512"
  60. +
  61. +#define JWT_TYP "typ"
  62. +
  63. +#define JWT_TYP_VALUE "jwt"
  64. +
  65. +#define SERVER_ADDRESS "https://api.reclaim"
  66. +
  67. +/**
  68. + * Create a JWT from attributes
  69. + *
  70. + * @param aud_key the public of the audience
  71. + * @param sub_key the public key of the subject
  72. + * @param attrs the attribute list
  73. + * @param expiration_time the validity of the token
  74. + * @param secret_key the key used to sign the JWT
  75. + * @return a new base64-encoded JWT string.
  76. + */
  77. +char*
  78. +OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
  79. + const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
  80. + const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
  81. + const struct GNUNET_TIME_Relative *expiration_time,
  82. + const char *nonce,
  83. + const char *secret_key);
  84. +
  85. +/**
  86. + * Builds an OIDC authorization code including
  87. + * a reclaim ticket and nonce
  88. + *
  89. + * @param issuer the issuer of the ticket, used to sign the ticket and nonce
  90. + * @param ticket the ticket to include in the code
  91. + * @param nonce the nonce to include in the code
  92. + * @return a new authorization code (caller must free)
  93. + */
  94. +char*
  95. +OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
  96. + const struct GNUNET_RECLAIM_Ticket *ticket,
  97. + const char* nonce);
  98. +
  99. +/**
  100. + * Parse reclaim ticket and nonce from
  101. + * authorization code.
  102. + * This also verifies the signature in the code.
  103. + *
  104. + * @param audience the expected audience of the code
  105. + * @param code the string representation of the code
  106. + * @param ticket where to store the ticket
  107. + * @param nonce where to store the nonce
  108. + * @return GNUNET_OK if successful, else GNUNET_SYSERR
  109. + */
  110. +int
  111. +OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
  112. + const char* code,
  113. + struct GNUNET_RECLAIM_Ticket **ticket,
  114. + char **nonce);
  115. +
  116. +/**
  117. + * Build a token response for a token request
  118. + * TODO: Maybe we should add the scope here?
  119. + *
  120. + * @param access_token the access token to include
  121. + * @param id_token the id_token to include
  122. + * @param expiration_time the expiration time of the token(s)
  123. + * @param token_response where to store the response
  124. + */
  125. +void
  126. +OIDC_build_token_response (const char *access_token,
  127. + const char *id_token,
  128. + const struct GNUNET_TIME_Relative *expiration_time,
  129. + char **token_response);
  130. +/**
  131. + * Generate a new access token
  132. + */
  133. +char*
  134. +OIDC_access_token_new ();
  135. +
  136. +
  137. +#endif
  138. --- /dev/null
  139. +++ b/src/rest-plugins/json_reclaim.h
  140. @@ -0,0 +1,48 @@
  141. +/*
  142. + This file is part of GNUnet.
  143. + Copyright (C) 2009-2018 GNUnet e.V.
  144. +
  145. + GNUnet is free software: you can redistribute it and/or modify it
  146. + under the terms of the GNU Affero General Public License as published
  147. + by the Free Software Foundation, either version 3 of the License,
  148. + or (at your option) any later version.
  149. +
  150. + GNUnet is distributed in the hope that it will be useful, but
  151. + WITHOUT ANY WARRANTY; without even the implied warranty of
  152. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  153. + Affero General Public License for more details.
  154. +
  155. + You should have received a copy of the GNU Affero General Public License
  156. + along with this program. If not, see <http://www.gnu.org/licenses/>.
  157. +
  158. + SPDX-License-Identifier: AGPL3.0-or-later
  159. +*/
  160. +
  161. +/**
  162. + * @file rest-plugins/json_reclaim.h
  163. + * @brief JSON handling of reclaim data
  164. + * @author Martin Schanzenbach
  165. + */
  166. +#include "platform.h"
  167. +#include "gnunet_util_lib.h"
  168. +#include "gnunet_json_lib.h"
  169. +#include "gnunet_reclaim_service.h"
  170. +#include "gnunet_reclaim_attribute_lib.h"
  171. +
  172. +/**
  173. + * JSON Specification for Reclaim claims.
  174. + *
  175. + * @param ticket struct of GNUNET_RECLAIM_ATTRIBUTE_Claim to fill
  176. + * @return JSON Specification
  177. + */
  178. +struct GNUNET_JSON_Specification
  179. +GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr);
  180. +
  181. +/**
  182. + * JSON Specification for Reclaim tickets.
  183. + *
  184. + * @param ticket struct of GNUNET_RECLAIM_Ticket to fill
  185. + * @return JSON Specification
  186. + */
  187. +struct GNUNET_JSON_Specification
  188. +GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket);