2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @author Martin Schanzenbach
22 * @file include/gnunet_identity_provider_lib.h
23 * @brief GNUnet Identity Provider library
26 #ifndef IDENTITY_TOKEN_H
27 #define IDENTITY_TOKEN_H
29 #include "gnunet_crypto_lib.h"
37 struct TokenAttr *attr_head;
42 struct TokenAttr *attr_tail;
47 struct GNUNET_CRYPTO_EcdsaSignature signature;
52 struct GNUNET_CRYPTO_EcdsaPublicKey aud_key;
60 struct TokenAttr *next;
65 struct TokenAttr *prev;
75 struct TokenAttrValue *val_head;
80 struct TokenAttrValue *val_tail;
89 struct TokenAttrValue *next;
94 struct TokenAttrValue *prev;
102 * Attribute int value
103 * used if NULL == value
108 struct TokenTicketPayload
123 struct GNUNET_CRYPTO_EcdsaPublicKey identity_key;
132 struct TokenTicketPayload *payload;
137 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
142 struct GNUNET_CRYPTO_EcdsaSignature signature;
147 struct GNUNET_CRYPTO_EcdsaPublicKey aud_key;
153 * Create an identity token
155 * @param iss the issuer string for the token
156 * @param aud the audience of the token
158 * @return a new token
160 struct IdentityToken*
161 token_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *iss,
162 const struct GNUNET_CRYPTO_EcdsaPublicKey* aud);
165 * Destroy an identity token
167 * @param token the token to destroy
170 token_destroy (struct IdentityToken*token);
173 * Add a new key value pair to the token
175 * @param token the token to modify
177 * @param value the value
180 token_add_attr (struct IdentityToken *token,
185 * Add a new key value pair to the token
187 * @param token the token to modify
189 * @param value the value
192 token_add_attr_int (struct IdentityToken *token,
199 * Add a value to a TokenAttribute
201 * @param attr the token attribute
202 * @param value value to add
205 token_attr_add_value (const struct TokenAttr *attr,
209 * Add a new key value pair to the token with the value as json
211 * @param the token to modify
213 * @param value the value
217 token_add_json (const struct IdentityToken *token,
222 * Serialize a token. The token will be signed and base64 according to the
223 * JWT format. The signature is base32-encoded ECDSA.
224 * The resulting JWT is encrypted using
225 * ECDHE for the audience and Base64
226 * encoded in result. The audience requires the ECDHE public key P
227 * to decrypt the token T. The key P is included in the result and prepended
230 * @param token the token to serialize
231 * @param priv_key the private key used to sign the token
232 * @param ecdhe_privkey the ECDHE private key used to encrypt the token
233 * @param result P,Base64(E(T))
235 * @return GNUNET_OK on success
238 token_serialize (const struct IdentityToken*token,
239 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
240 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdhe_privkey,
244 * Parses the serialized token and returns a token
246 * @param data the serialized token
247 * @param priv_key the private key of the audience
248 * @param result the token
250 * @return GNUNET_OK on success
253 token_parse (const char* data,
254 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
255 struct IdentityToken **result);
258 * Parses the serialized token and returns a token
259 * This variant is intended for the party that issued the token and also
260 * wants to decrypt the serialized token.
262 * @param data the serialized token
263 * @param priv_key the private (!) ECDHE key
264 * @param aud_key the identity of the audience
265 * @param result the token
267 * @return GNUNET_OK on success
270 token_parse2 (const char* data,
271 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
272 const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
273 struct IdentityToken **result);
278 * Returns a JWT-string representation of the token
280 * @param token the token
281 * @param priv_key the private key used to sign the JWT
282 * @param result the JWT
284 * @return GNUNET_OK on success
287 token_to_string (const struct IdentityToken *token,
288 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
293 * Creates a ticket that can be exchanged by the audience for
294 * the token. The token must be placed under the label
296 * @param nonce nonce provided by the audience that requested the ticket
297 * @param iss_pkey the issuer pubkey used to sign the ticket
298 * @param label the label encoded in the ticket
299 * @param aud_ley the audience pubkey used to encrypt the ticket payload
304 ticket_create (uint64_t nonce,
305 const struct GNUNET_CRYPTO_EcdsaPublicKey* iss_pkey,
307 const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key);
310 * Serialize a ticket. Returns the Base64 representation of the ticket.
311 * Format: Base64( { payload: E(Payload), ecdhe: K, signature: signature } )
313 * @param ticket the ticket to serialize
314 * @param priv_key the issuer private key to sign the ticket payload
315 * @param result the serialized ticket
317 * @return GNUNET_OK on success
320 ticket_serialize (struct TokenTicket *ticket,
321 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
327 * @param the ticket to destroy
330 ticket_destroy (struct TokenTicket *ticket);
333 * Parses a serialized ticket
335 * @param data the serialized ticket
336 * @param priv_key the audience private key
337 * @param ticket the ticket
339 * @return GNUNET_OK on success
342 ticket_parse (const char* raw_data,
343 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
344 struct TokenTicket **ticket);