2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
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"
47 struct GNUNET_CRYPTO_EcdsaSignature signature;
52 struct GNUNET_CRYPTO_EcdsaPublicKey aud_key;
55 struct TokenTicketPayload
70 struct GNUNET_CRYPTO_EcdsaPublicKey identity_key;
79 struct TokenTicketPayload *payload;
84 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
89 struct GNUNET_CRYPTO_EcdsaSignature signature;
94 struct GNUNET_CRYPTO_EcdsaPublicKey aud_key;
100 * Create an identity token
102 * @param iss the issuer string for the token
103 * @param aud the audience of the token
105 * @return a new token
107 struct IdentityToken*
108 token_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *iss,
109 const struct GNUNET_CRYPTO_EcdsaPublicKey* aud);
112 * Destroy an identity token
114 * @param token the token to destroy
117 token_destroy (struct IdentityToken*token);
120 * Add a new key value pair to the token
122 * @param token the token to modify
124 * @param value the value
127 token_add_attr (const struct IdentityToken *token,
132 * Add a new key value pair to the token with the value as json
134 * @param the token to modify
136 * @param value the value
140 token_add_json (const struct IdentityToken *token,
145 * Serialize a token. The token will be signed and base64 according to the
146 * JWT format. The signature is base32-encoded ECDSA.
147 * The resulting JWT is encrypted using
148 * ECDHE for the audience and Base64
149 * encoded in result. The audience requires the ECDHE public key P
150 * to decrypt the token T. The key P is included in the result and prepended
153 * @param token the token to serialize
154 * @param priv_key the private key used to sign the token
155 * @param ecdhe_privkey the ECDHE private key used to encrypt the token
156 * @param result P,Base64(E(T))
158 * @return GNUNET_OK on success
161 token_serialize (const struct IdentityToken*token,
162 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
163 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdhe_privkey,
167 * Parses the serialized token and returns a token
169 * @param data the serialized token
170 * @param priv_key the private key of the audience
171 * @param result the token
173 * @return GNUNET_OK on success
176 token_parse (const char* data,
177 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
178 struct IdentityToken **result);
181 * Parses the serialized token and returns a token
182 * This variant is intended for the party that issued the token and also
183 * wants to decrypt the serialized token.
185 * @param data the serialized token
186 * @param priv_key the private (!) ECDHE key
187 * @param aud_key the identity of the audience
188 * @param result the token
190 * @return GNUNET_OK on success
193 token_parse2 (const char* data,
194 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
195 const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
196 struct IdentityToken **result);
201 * Returns a JWT-string representation of the token
203 * @param token the token
204 * @param priv_key the private key used to sign the JWT
205 * @param result the JWT
207 * @return GNUNET_OK on success
210 token_to_string (const struct IdentityToken *token,
211 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
216 * Creates a ticket that can be exchanged by the audience for
217 * the token. The token must be placed under the label
219 * @param nonce_str nonce provided by the audience that requested the ticket
220 * @param iss_pkey the issuer pubkey used to sign the ticket
221 * @param label the label encoded in the ticket
222 * @param aud_ley the audience pubkey used to encrypt the ticket payload
227 ticket_create (const char* nonce_str,
228 const struct GNUNET_CRYPTO_EcdsaPublicKey* iss_pkey,
230 const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key);
233 * Serialize a ticket. Returns the Base64 representation of the ticket.
234 * Format: Base64( { payload: E(Payload), ecdhe: K, signature: signature } )
236 * @param ticket the ticket to serialize
237 * @param priv_key the issuer private key to sign the ticket payload
238 * @param result the serialized ticket
240 * @return GNUNET_OK on success
243 ticket_serialize (struct TokenTicket *ticket,
244 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
250 * @param the ticket to destroy
253 ticket_destroy (struct TokenTicket *ticket);
256 * Parses a serialized ticket
258 * @param data the serialized ticket
259 * @param priv_key the audience private key
260 * @param ticket the ticket
262 * @return GNUNET_OK on success
265 ticket_parse (const char* raw_data,
266 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
267 struct TokenTicket **ticket);