~ubuntu-branches/ubuntu/natty/gnutls26/natty

« back to all changes in this revision

Viewing changes to tests/anonself.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2009-08-14 19:14:29 UTC
  • mfrom: (1.1.7 upstream) (12.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090814191429-6hovzz3oaqq101rm
Tags: 2.8.3-1
* New upstream version.
  + Stops hardcoding a hard dependency on the versions of gcrypt and tasn it
    was built against. Closes: #540449
  + Fixes CVE-2009-2730, a vulnerability related to NUL bytes in X.509
    certificate name fields. Closes: #541439        GNUTLS-SA-2009-4
    http://lists.gnu.org/archive/html/help-gnutls/2009-08/msg00011.html
* Drop 15_chainverify_expiredcert.diff, included upstream.
* Urgency high, since 541439 applies to testing, too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation
 
2
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation
3
3
 *
4
4
 * Author: Simon Josefsson
5
5
 *
37
37
#include <unistd.h>
38
38
#include <gnutls/gnutls.h>
39
39
 
 
40
#include "tcp.c"
 
41
 
40
42
#include "utils.h"
41
43
 
42
44
static void
51
53
#define MAX_BUF 1024
52
54
#define MSG "Hello TLS"
53
55
 
54
 
/* Connects to the peer and returns a socket
55
 
 * descriptor.
56
 
 */
57
 
int
58
 
tcp_connect (void)
59
 
{
60
 
  const char *PORT = "5556";
61
 
  const char *SERVER = "127.0.0.1";
62
 
  int err, sd;
63
 
  struct sockaddr_in sa;
64
 
 
65
 
  /* connects to server
66
 
   */
67
 
  sd = socket (AF_INET, SOCK_STREAM, 0);
68
 
 
69
 
  memset (&sa, '\0', sizeof (sa));
70
 
  sa.sin_family = AF_INET;
71
 
  sa.sin_port = htons (atoi (PORT));
72
 
  inet_pton (AF_INET, SERVER, &sa.sin_addr);
73
 
 
74
 
  err = connect (sd, (struct sockaddr *) &sa, sizeof (sa));
75
 
  if (err < 0)
76
 
    {
77
 
      fprintf (stderr, "Connect error\n");
78
 
      exit (1);
79
 
    }
80
 
 
81
 
  return sd;
82
 
}
83
 
 
84
 
/* closes the given socket descriptor.
85
 
 */
86
 
void
87
 
tcp_close (int sd)
88
 
{
89
 
  shutdown (sd, SHUT_RDWR);     /* no more receptions */
90
 
  close (sd);
91
 
}
92
 
 
93
 
void
 
56
static void
94
57
client (void)
95
58
{
96
59
  int ret, sd, ii;
189
152
/* These are global */
190
153
gnutls_anon_server_credentials_t anoncred;
191
154
 
192
 
gnutls_session_t
 
155
static gnutls_session_t
193
156
initialize_tls_session (void)
194
157
{
195
158
  gnutls_session_t session;
215
178
static int
216
179
generate_dh_params (void)
217
180
{
218
 
  const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) };
219
 
  /* Generate Diffie Hellman parameters - for use with DHE
 
181
  const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) };
 
182
  /* Generate Diffie-Hellman parameters - for use with DHE
220
183
   * kx algorithms. These should be discarded and regenerated
221
184
   * once a day, once a week or once a month. Depending on the
222
185
   * security requirements.
235
198
char buffer[MAX_BUF + 1];
236
199
int optval = 1;
237
200
 
238
 
void
 
201
static void
239
202
server_start (void)
240
203
{
241
204
  /* Socket operations
253
216
  sa_serv.sin_addr.s_addr = INADDR_ANY;
254
217
  sa_serv.sin_port = htons (PORT);      /* Server Port number */
255
218
 
256
 
  setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (int));
 
219
  setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, sizeof (int));
257
220
 
258
221
  err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv));
259
222
  if (err == -1)
274
237
  success ("server: ready. Listening to port '%d'.\n", PORT);
275
238
}
276
239
 
277
 
void
 
240
static void
278
241
server (void)
279
242
{
280
243
  /* this must be called once in the program
323
286
  i = 0;
324
287
  for (;;)
325
288
    {
326
 
      bzero (buffer, MAX_BUF + 1);
 
289
      memset (buffer, 0, MAX_BUF + 1);
327
290
      ret = gnutls_record_recv (session, buffer, MAX_BUF);
328
291
 
329
292
      if (ret == 0)