~ubuntu-branches/ubuntu/oneiric/gnutls26/oneiric

« back to all changes in this revision

Viewing changes to lib/gnutls_extensions.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation
 
2
 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
 
3
 * Free Software Foundation, Inc.
3
4
 *
4
5
 * Author: Nikos Mavrogiannopoulos, Simon Josefsson
5
6
 *
6
 
 * This file is part of GNUTLS.
 
7
 * This file is part of GnuTLS.
7
8
 *
8
 
 * The GNUTLS library is free software; you can redistribute it and/or
 
9
 * The GnuTLS is free software; you can redistribute it and/or
9
10
 * modify it under the terms of the GNU Lesser General Public License
10
11
 * as published by the Free Software Foundation; either version 2.1 of
11
12
 * the License, or (at your option) any later version.
35
36
#include <ext_server_name.h>
36
37
#include <ext_oprfi.h>
37
38
#include <ext_srp.h>
 
39
#include <ext_session_ticket.h>
 
40
#include <ext_safe_renegotiation.h>
 
41
#include <ext_signature.h>
 
42
#include <ext_safe_renegotiation.h>
38
43
#include <gnutls_num.h>
39
44
 
40
45
typedef struct
42
47
  const char *name;
43
48
  uint16_t type;
44
49
  gnutls_ext_parse_type_t parse_type;
 
50
 
 
51
  /* this function must return 0 when Not Applicable
 
52
   * size of extension data if ok
 
53
   * < 0 on other error.
 
54
   */
45
55
  gnutls_ext_recv_func recv_func;
 
56
 
 
57
  /* this function must return 0 when Not Applicable
 
58
   * size of extension data if ok
 
59
   * GNUTLS_E_INT_RET_0 if extension data size is zero
 
60
   * < 0 on other error.
 
61
   */
46
62
  gnutls_ext_send_func send_func;
47
63
} gnutls_extension_entry;
48
64
 
133
149
      type = _gnutls_read_uint16 (&data[pos]);
134
150
      pos += 2;
135
151
 
136
 
      _gnutls_debug_log ("EXT[%p]: Received extension '%s/%d'\n", session,
 
152
      _gnutls_debug_log ("EXT[%p]: Found extension '%s/%d'\n", session,
137
153
                         _gnutls_extension_get_name (type), type);
138
154
 
139
155
      if ((ret = _gnutls_extension_list_check (session, type)) < 0)
153
169
      ext_recv = _gnutls_ext_func_recv (type, parse_type);
154
170
      if (ext_recv == NULL)
155
171
        continue;
 
172
 
 
173
 
156
174
      if ((ret = ext_recv (session, sdata, size)) < 0)
157
175
        {
158
176
          gnutls_assert ();
170
188
 * This list is used to check whether the (later) received
171
189
 * extensions are the ones we requested.
172
190
 */
173
 
static void
 
191
void
174
192
_gnutls_extension_list_add (gnutls_session_t session, uint16_t type)
175
193
{
176
194
 
178
196
    {
179
197
      if (session->internals.extensions_sent_size < MAX_EXT_TYPES)
180
198
        {
181
 
          session->internals.extensions_sent[session->
182
 
                                             internals.extensions_sent_size] =
183
 
            type;
 
199
          session->internals.extensions_sent[session->internals.
 
200
                                             extensions_sent_size] = type;
184
201
          session->internals.extensions_sent_size++;
185
202
        }
186
203
      else
192
209
 
193
210
int
194
211
_gnutls_gen_extensions (gnutls_session_t session, opaque * data,
195
 
                        size_t data_size)
 
212
                        size_t data_size, gnutls_ext_parse_type_t parse_type)
196
213
{
197
214
  int size;
198
215
  uint16_t pos = 0;
199
216
  opaque *sdata;
200
 
  int sdata_size;
 
217
  size_t sdata_size;
201
218
  size_t i;
202
219
 
203
220
  if (data_size < 2)
224
241
      if (p->send_func == NULL)
225
242
        continue;
226
243
 
 
244
      if (parse_type != GNUTLS_EXT_ANY && p->parse_type != parse_type)
 
245
        continue;
 
246
 
227
247
      size = p->send_func (session, sdata, sdata_size);
228
 
      if (size > 0)
 
248
      if (size > 0 || size == GNUTLS_E_INT_RET_0)
229
249
        {
 
250
          if (size == GNUTLS_E_INT_RET_0)
 
251
            size = 0;
 
252
 
230
253
          if (data_size < pos + (size_t) size + 4)
231
254
            {
232
255
              gnutls_assert ();
304
327
  if (ret != GNUTLS_E_SUCCESS)
305
328
    return ret;
306
329
 
 
330
  ret = gnutls_ext_register (GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
 
331
                             "SAFE_RENEGOTIATION",
 
332
                             GNUTLS_EXT_MANDATORY,
 
333
                             _gnutls_safe_renegotiation_recv_params,
 
334
                             _gnutls_safe_renegotiation_send_params);
 
335
  if (ret != GNUTLS_E_SUCCESS)
 
336
    return ret;
 
337
 
307
338
#ifdef ENABLE_OPRFI
308
339
  ret = gnutls_ext_register (GNUTLS_EXTENSION_OPAQUE_PRF_INPUT,
309
340
                             "OPAQUE_PRF_INPUT",
324
355
    return ret;
325
356
#endif
326
357
 
 
358
#ifdef ENABLE_SESSION_TICKET
 
359
  ret = gnutls_ext_register (GNUTLS_EXTENSION_SESSION_TICKET,
 
360
                             "SESSION_TICKET",
 
361
                             GNUTLS_EXT_TLS,
 
362
                             _gnutls_session_ticket_recv_params,
 
363
                             _gnutls_session_ticket_send_params);
 
364
  if (ret != GNUTLS_E_SUCCESS)
 
365
    return ret;
 
366
#endif
 
367
 
 
368
  ret = gnutls_ext_register (GNUTLS_EXTENSION_SIGNATURE_ALGORITHMS,
 
369
                             "SIGNATURE_ALGORITHMS",
 
370
                             GNUTLS_EXT_TLS,
 
371
                             _gnutls_signature_algorithm_recv_params,
 
372
                             _gnutls_signature_algorithm_send_params);
 
373
  if (ret != GNUTLS_E_SUCCESS)
 
374
    return ret;
 
375
 
327
376
  return GNUTLS_E_SUCCESS;
328
377
}
329
378
 
336
385
}
337
386
 
338
387
/**
339
 
 * gnutls_ext_register - Register a handler for a TLS extension
 
388
 * gnutls_ext_register:
340
389
 * @type: the 16-bit integer referring to the extension type
341
390
 * @name: human printable name of the extension used for debugging
342
391
 * @parse_type: either #GNUTLS_EXT_TLS or %GNUTLS_EXT_APPLICATION.