~ubuntu-branches/ubuntu/trusty/gnutls26/trusty

« back to all changes in this revision

Viewing changes to src/common.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-10-01 15:28:13 UTC
  • mfrom: (12.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20111001152813-yygm1c4cxonfxhzy
* New upstream version.
  + Allow CA importing of 0 certificates to succeed. Closes: #640639
* Add libp11-kit-dev to libgnutls-dev dependencies. (see #643811)
* [20_guiledocstring.diff] guile: Fix docstring extraction with CPP 4.5+.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#undef localtime
28
28
#endif
29
29
 
 
30
#include <getpass.h>
 
31
 
30
32
#include <stdio.h>
31
33
#include <stdlib.h>
32
34
#include <string.h>
33
35
#include <gnutls/gnutls.h>
34
 
#include <gnutls/extra.h>
35
36
#include <gnutls/x509.h>
36
37
#include <gnutls/openpgp.h>
37
38
#include <time.h>
42
43
int print_cert;
43
44
extern int verbose;
44
45
 
45
 
static char buffer[5 * 1024];
46
 
 
47
46
const char str_unknown[] = "(unknown)";
48
47
 
49
48
/* Hex encodes the given data.
62
61
  for (i = 0; i < raw_size; i++)
63
62
    {
64
63
      sprintf (&(buf[i * 3]), "%02X%s", raw[i],
65
 
               (i == raw_size - 1) ? "" : ":");
 
64
               (i == raw_size - 1) ? "" : ":");
66
65
    }
67
66
  buf[sizeof (buf) - 1] = '\0';
68
67
 
94
93
      gnutls_x509_crt_init (&crt);
95
94
      ret = gnutls_x509_crt_import (crt, &cert_list[j], GNUTLS_X509_FMT_DER);
96
95
      if (ret < 0)
97
 
        {
98
 
          fprintf (stderr, "Decoding error: %s\n", gnutls_strerror (ret));
99
 
          return;
100
 
        }
 
96
        {
 
97
          fprintf (stderr, "Decoding error: %s\n", gnutls_strerror (ret));
 
98
          return;
 
99
        }
101
100
 
102
101
      printf (" - Certificate[%d] info:\n  - ", j);
103
102
 
104
103
      if (verbose)
105
 
        ret = gnutls_x509_crt_print (crt, GNUTLS_CRT_PRINT_FULL, &cinfo);
 
104
        ret = gnutls_x509_crt_print (crt, GNUTLS_CRT_PRINT_FULL, &cinfo);
106
105
      else
107
 
        ret = gnutls_x509_crt_print (crt, GNUTLS_CRT_PRINT_ONELINE, &cinfo);
 
106
        ret = gnutls_x509_crt_print (crt, GNUTLS_CRT_PRINT_ONELINE, &cinfo);
108
107
      if (ret == 0)
109
 
        {
110
 
          printf ("%s\n", cinfo.data);
111
 
          gnutls_free (cinfo.data);
112
 
        }
 
108
        {
 
109
          printf ("%s\n", cinfo.data);
 
110
          gnutls_free (cinfo.data);
 
111
        }
113
112
 
114
113
      if (print_cert)
115
 
        {
116
 
          size_t size;
117
 
 
118
 
          size = sizeof (buffer);
119
 
 
120
 
          ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM,
121
 
                                        buffer, &size);
122
 
          if (ret < 0)
123
 
            {
124
 
              fprintf (stderr, "Encoding error: %s\n", gnutls_strerror (ret));
125
 
              return;
126
 
            }
127
 
 
128
 
          fputs ("\n", stdout);
129
 
          fputs (buffer, stdout);
130
 
          fputs ("\n", stdout);
131
 
        }
 
114
        {
 
115
          size_t size = 0;
 
116
          char *p = NULL;
 
117
 
 
118
          ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM, p, &size);
 
119
          if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
 
120
            {
 
121
              p = malloc (size);
 
122
              if (!p)
 
123
                {
 
124
                  fprintf (stderr, "gnutls_malloc\n");
 
125
                  exit (1);
 
126
                }
 
127
 
 
128
              ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM,
 
129
                                            p, &size);
 
130
            }
 
131
          if (ret < 0)
 
132
            {
 
133
              fprintf (stderr, "Encoding error: %s\n", gnutls_strerror (ret));
 
134
              return;
 
135
            }
 
136
 
 
137
          fputs ("\n", stdout);
 
138
          fputs (p, stdout);
 
139
          fputs ("\n", stdout);
 
140
 
 
141
          gnutls_free (p);
 
142
        }
132
143
 
133
144
      if (j == 0 && hostname != NULL)
134
 
        {
135
 
          /* Check the hostname of the first certificate if it matches
136
 
           * the name of the host we connected to.
137
 
           */
138
 
          if (gnutls_x509_crt_check_hostname (crt, hostname) == 0)
139
 
            hostname_ok = 1;
140
 
          else
141
 
            hostname_ok = 2;
142
 
        }
 
145
        {
 
146
          /* Check the hostname of the first certificate if it matches
 
147
           * the name of the host we connected to.
 
148
           */
 
149
          if (gnutls_x509_crt_check_hostname (crt, hostname) == 0)
 
150
            hostname_ok = 1;
 
151
          else
 
152
            hostname_ok = 2;
 
153
        }
143
154
 
144
155
      gnutls_x509_crt_deinit (crt);
145
156
    }
147
158
  if (hostname_ok == 1)
148
159
    {
149
160
      printf ("- The hostname in the certificate does NOT match '%s'\n",
150
 
              hostname);
 
161
              hostname);
151
162
      if (!insecure)
152
 
        exit (1);
 
163
        exit (1);
153
164
    }
154
165
  else if (hostname_ok == 2)
155
166
    {
161
172
 
162
173
static void
163
174
print_openpgp_info (gnutls_session_t session, const char *hostname,
164
 
                    int insecure)
 
175
                    int insecure)
165
176
{
166
177
 
167
178
  gnutls_openpgp_crt_t crt;
178
189
 
179
190
      gnutls_openpgp_crt_init (&crt);
180
191
      ret = gnutls_openpgp_crt_import (crt, &cert_list[0],
181
 
                                       GNUTLS_OPENPGP_FMT_RAW);
 
192
                                       GNUTLS_OPENPGP_FMT_RAW);
182
193
      if (ret < 0)
183
 
        {
184
 
          fprintf (stderr, "Decoding error: %s\n", gnutls_strerror (ret));
185
 
          return;
186
 
        }
 
194
        {
 
195
          fprintf (stderr, "Decoding error: %s\n", gnutls_strerror (ret));
 
196
          return;
 
197
        }
187
198
 
188
199
      if (verbose)
189
 
        ret = gnutls_openpgp_crt_print (crt, GNUTLS_CRT_PRINT_FULL, &cinfo);
 
200
        ret = gnutls_openpgp_crt_print (crt, GNUTLS_CRT_PRINT_FULL, &cinfo);
190
201
      else
191
 
        ret =
192
 
          gnutls_openpgp_crt_print (crt, GNUTLS_CRT_PRINT_ONELINE, &cinfo);
 
202
        ret =
 
203
          gnutls_openpgp_crt_print (crt, GNUTLS_CRT_PRINT_ONELINE, &cinfo);
193
204
      if (ret == 0)
194
 
        {
195
 
          printf (" - %s\n", cinfo.data);
196
 
          gnutls_free (cinfo.data);
197
 
        }
 
205
        {
 
206
          printf (" - %s\n", cinfo.data);
 
207
          gnutls_free (cinfo.data);
 
208
        }
198
209
 
199
210
      if (print_cert)
200
 
        {
201
 
          size_t size;
202
 
 
203
 
          size = sizeof (buffer);
204
 
 
205
 
          ret = gnutls_openpgp_crt_export (crt, GNUTLS_OPENPGP_FMT_BASE64,
206
 
                                           buffer, &size);
207
 
          if (ret < 0)
208
 
            {
209
 
              fprintf (stderr, "Encoding error: %s\n", gnutls_strerror (ret));
210
 
              return;
211
 
            }
212
 
          fputs (buffer, stdout);
213
 
          fputs ("\n", stdout);
214
 
        }
 
211
        {
 
212
          size_t size = 0;
 
213
          char *p = NULL;
 
214
 
 
215
          ret = gnutls_openpgp_crt_export (crt, GNUTLS_OPENPGP_FMT_BASE64,
 
216
                                           p, &size);
 
217
          if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
 
218
            {
 
219
              p = malloc (size);
 
220
              if (!p)
 
221
                {
 
222
                  fprintf (stderr, "gnutls_malloc\n");
 
223
                  exit (1);
 
224
                }
 
225
 
 
226
              ret = gnutls_openpgp_crt_export (crt, GNUTLS_OPENPGP_FMT_BASE64,
 
227
                                               p, &size);
 
228
            }
 
229
          if (ret < 0)
 
230
            {
 
231
              fprintf (stderr, "Encoding error: %s\n", gnutls_strerror (ret));
 
232
              return;
 
233
            }
 
234
 
 
235
          fputs (p, stdout);
 
236
          fputs ("\n", stdout);
 
237
 
 
238
          gnutls_free (p);
 
239
        }
215
240
 
216
241
      if (hostname != NULL)
217
 
        {
218
 
          /* Check the hostname of the first certificate if it matches
219
 
           * the name of the host we connected to.
220
 
           */
221
 
          if (gnutls_openpgp_crt_check_hostname (crt, hostname) == 0)
222
 
            hostname_ok = 1;
223
 
          else
224
 
            hostname_ok = 2;
225
 
        }
 
242
        {
 
243
          /* Check the hostname of the first certificate if it matches
 
244
           * the name of the host we connected to.
 
245
           */
 
246
          if (gnutls_openpgp_crt_check_hostname (crt, hostname) == 0)
 
247
            hostname_ok = 1;
 
248
          else
 
249
            hostname_ok = 2;
 
250
        }
226
251
 
227
252
      gnutls_openpgp_crt_deinit (crt);
228
253
    }
230
255
  if (hostname_ok == 1)
231
256
    {
232
257
      printf ("- The hostname in the certificate does NOT match '%s'\n",
233
 
              hostname);
 
258
              hostname);
234
259
      if (!insecure)
235
 
        exit (1);
 
260
        exit (1);
236
261
    }
237
262
  else if (hostname_ok == 2)
238
263
    {
252
277
  if (rc < 0)
253
278
    {
254
279
      printf ("- Could not verify certificate (err: %s)\n",
255
 
              gnutls_strerror (rc));
 
280
              gnutls_strerror (rc));
256
281
      return;
257
282
    }
258
283
 
265
290
  if (gnutls_certificate_type_get (session) == GNUTLS_CRT_X509)
266
291
    {
267
292
      if (status & GNUTLS_CERT_REVOKED)
268
 
        printf ("- Peer's certificate chain revoked\n");
 
293
        printf ("- Peer's certificate chain revoked\n");
269
294
      if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
270
 
        printf ("- Peer's certificate issuer is unknown\n");
 
295
        printf ("- Peer's certificate issuer is unknown\n");
271
296
      if (status & GNUTLS_CERT_SIGNER_NOT_CA)
272
 
        printf ("- Peer's certificate issuer is not a CA\n");
 
297
        printf ("- Peer's certificate issuer is not a CA\n");
273
298
      if (status & GNUTLS_CERT_INSECURE_ALGORITHM)
274
 
        printf ("- Peer's certificate chain uses insecure algorithm\n");
 
299
        printf ("- Peer's certificate chain uses insecure algorithm\n");
275
300
      if (status & GNUTLS_CERT_NOT_ACTIVATED)
276
 
        printf
277
 
          ("- Peer's certificate chain uses not yet valid certificate\n");
 
301
        printf
 
302
          ("- Peer's certificate chain uses not yet valid certificate\n");
278
303
      if (status & GNUTLS_CERT_EXPIRED)
279
 
        printf ("- Peer's certificate chain uses expired certificate\n");
 
304
        printf ("- Peer's certificate chain uses expired certificate\n");
280
305
      if (status & GNUTLS_CERT_INVALID)
281
 
        printf ("- Peer's certificate is NOT trusted\n");
 
306
        printf ("- Peer's certificate is NOT trusted\n");
282
307
      else
283
 
        printf ("- Peer's certificate is trusted\n");
 
308
        printf ("- Peer's certificate is trusted\n");
284
309
    }
285
310
  else
286
311
    {
287
312
      if (status & GNUTLS_CERT_INVALID)
288
 
        printf ("- Peer's key is invalid\n");
 
313
        printf ("- Peer's key is invalid\n");
289
314
      else
290
 
        printf ("- Peer's key is valid\n");
 
315
        printf ("- Peer's key is valid\n");
291
316
      if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
292
 
        printf ("- Could not find a signer of the peer's key\n");
 
317
        printf ("- Could not find a signer of the peer's key\n");
293
318
    }
294
319
}
295
320
 
300
325
  printf (" - Using prime: %d bits\n", gnutls_dh_get_prime_bits (session));
301
326
  printf (" - Secret key: %d bits\n", gnutls_dh_get_secret_bits (session));
302
327
  printf (" - Peer's public key: %d bits\n",
303
 
          gnutls_dh_get_peers_public_bits (session));
 
328
          gnutls_dh_get_peers_public_bits (session));
304
329
 
305
330
  if (print_cert)
306
331
    {
313
338
 
314
339
      ret = gnutls_dh_get_group (session, &raw_gen, &raw_prime);
315
340
      if (ret)
316
 
        {
317
 
          fprintf (stderr, "gnutls_dh_get_group %d\n", ret);
318
 
          goto out;
319
 
        }
 
341
        {
 
342
          fprintf (stderr, "gnutls_dh_get_group %d\n", ret);
 
343
          goto out;
 
344
        }
320
345
 
321
346
      ret = gnutls_dh_params_init (&dh_params);
322
347
      if (ret)
323
 
        {
324
 
          fprintf (stderr, "gnutls_dh_params_init %d\n", ret);
325
 
          goto out;
326
 
        }
 
348
        {
 
349
          fprintf (stderr, "gnutls_dh_params_init %d\n", ret);
 
350
          goto out;
 
351
        }
327
352
 
328
353
      ret = gnutls_dh_params_import_raw (dh_params, &raw_prime, &raw_gen);
329
354
      if (ret)
330
 
        {
331
 
          fprintf (stderr, "gnutls_dh_params_import_raw %d\n", ret);
332
 
          goto out;
333
 
        }
 
355
        {
 
356
          fprintf (stderr, "gnutls_dh_params_import_raw %d\n", ret);
 
357
          goto out;
 
358
        }
334
359
 
335
360
      ret = gnutls_dh_params_export_pkcs3 (dh_params,
336
 
                                           GNUTLS_X509_FMT_PEM,
337
 
                                           params_data, &params_data_size);
 
361
                                           GNUTLS_X509_FMT_PEM,
 
362
                                           params_data, &params_data_size);
338
363
      if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
339
 
        {
340
 
          fprintf (stderr, "gnutls_dh_params_export_pkcs3 %d\n", ret);
341
 
          goto out;
342
 
        }
 
364
        {
 
365
          fprintf (stderr, "gnutls_dh_params_export_pkcs3 %d\n", ret);
 
366
          goto out;
 
367
        }
343
368
 
344
369
      params_data = gnutls_malloc (params_data_size);
345
370
      if (!params_data)
346
 
        {
347
 
          fprintf (stderr, "gnutls_malloc %d\n", ret);
348
 
          goto out;
349
 
        }
 
371
        {
 
372
          fprintf (stderr, "gnutls_malloc %d\n", ret);
 
373
          goto out;
 
374
        }
350
375
 
351
376
      ret = gnutls_dh_params_export_pkcs3 (dh_params,
352
 
                                           GNUTLS_X509_FMT_PEM,
353
 
                                           params_data, &params_data_size);
 
377
                                           GNUTLS_X509_FMT_PEM,
 
378
                                           params_data, &params_data_size);
354
379
      if (ret)
355
 
        {
356
 
          fprintf (stderr, "gnutls_dh_params_export_pkcs3-2 %d\n", ret);
357
 
          goto out;
358
 
        }
 
380
        {
 
381
          fprintf (stderr, "gnutls_dh_params_export_pkcs3-2 %d\n", ret);
 
382
          goto out;
 
383
        }
359
384
 
360
385
      printf (" - PKCS#3 format:\n\n%.*s\n", (int) params_data_size,
361
 
              params_data);
 
386
              params_data);
362
387
 
363
388
    out:
364
389
      gnutls_free (params_data);
394
419
       * side.
395
420
       */
396
421
      if (gnutls_srp_server_get_username (session) != NULL)
397
 
        printf ("- SRP authentication. Connected as '%s'\n",
398
 
                gnutls_srp_server_get_username (session));
 
422
        printf ("- SRP authentication. Connected as '%s'\n",
 
423
                gnutls_srp_server_get_username (session));
399
424
      break;
400
425
#endif
401
426
#ifdef ENABLE_PSK
403
428
      /* This returns NULL in server side.
404
429
       */
405
430
      if (gnutls_psk_client_get_hint (session) != NULL)
406
 
        printf ("- PSK authentication. PSK hint '%s'\n",
407
 
                gnutls_psk_client_get_hint (session));
 
431
        printf ("- PSK authentication. PSK hint '%s'\n",
 
432
                gnutls_psk_client_get_hint (session));
408
433
      /* This returns NULL in client side.
409
434
       */
410
435
      if (gnutls_psk_server_get_username (session) != NULL)
411
 
        printf ("- PSK authentication. Connected as '%s'\n",
412
 
                gnutls_psk_server_get_username (session));
 
436
        printf ("- PSK authentication. Connected as '%s'\n",
 
437
                gnutls_psk_server_get_username (session));
413
438
      if (kx == GNUTLS_KX_DHE_PSK)
414
 
        print_dh_info (session, "Ephemeral ");
 
439
        print_dh_info (session, "Ephemeral ");
415
440
      break;
416
441
#endif
417
442
    case GNUTLS_CRD_IA:
419
444
      break;
420
445
    case GNUTLS_CRD_CERTIFICATE:
421
446
      {
422
 
        char dns[256];
423
 
        size_t dns_size = sizeof (dns);
424
 
        unsigned int type;
 
447
        char dns[256];
 
448
        size_t dns_size = sizeof (dns);
 
449
        unsigned int type;
425
450
 
426
 
        /* This fails in client side */
427
 
        if (gnutls_server_name_get (session, dns, &dns_size, &type, 0) == 0)
428
 
          {
429
 
            printf ("- Given server name[%d]: %s\n", type, dns);
430
 
          }
 
451
        /* This fails in client side */
 
452
        if (gnutls_server_name_get (session, dns, &dns_size, &type, 0) == 0)
 
453
          {
 
454
            printf ("- Given server name[%d]: %s\n", type, dns);
 
455
          }
431
456
      }
432
457
 
433
458
      if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
434
 
        print_dh_info (session, "Ephemeral ");
 
459
        print_dh_info (session, "Ephemeral ");
435
460
 
436
461
      print_cert_info (session, hostname, insecure);
437
462
 
462
487
      printf ("- Session ID: %s\n", raw_to_string (id, id_size));
463
488
    }
464
489
 
 
490
  if (verbose)
 
491
    {
 
492
      gnutls_datum cb;
 
493
      int rc;
 
494
 
 
495
      rc =
 
496
        gnutls_session_channel_binding (session, GNUTLS_CB_TLS_UNIQUE, &cb);
 
497
      if (rc)
 
498
        fprintf (stderr, "Channel binding error: %s\n", gnutls_strerror (rc));
 
499
      else
 
500
        {
 
501
          size_t i;
 
502
 
 
503
          printf ("- Channel binding 'tls-unique': ");
 
504
          for (i = 0; i < cb.size; i++)
 
505
            printf ("%02x", cb.data[i]);
 
506
          printf ("\n");
 
507
        }
 
508
    }
 
509
 
 
510
  /* Warning: Do not print anything more here. The 'Compression:'
 
511
     output MUST be the last non-verbose output.  This is used by
 
512
     Emacs starttls.el code. */
465
513
 
466
514
  fflush (stdout);
467
515
 
482
530
      printf ("Unknown\n");
483
531
 
484
532
      if (!insecure)
485
 
        exit (1);
 
533
        exit (1);
486
534
      break;
487
535
    case GNUTLS_CRT_X509:
488
536
      printf ("X.509\n");
511
559
 
512
560
    printf ("Cipher suites:\n");
513
561
    for (i = 0; (name = gnutls_cipher_suite_info
514
 
                 (i, id, &kx, &cipher, &mac, &version)); i++)
 
562
                 (i, id, &kx, &cipher, &mac, &version)); i++)
515
563
      {
516
 
        printf ("%-50s\t0x%02x, 0x%02x\t%s\n",
517
 
                name,
518
 
                (unsigned char) id[0], (unsigned char) id[1],
519
 
                gnutls_protocol_get_name (version));
520
 
        if (verbose)
521
 
          printf ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
522
 
                  gnutls_kx_get_name (kx),
523
 
                  gnutls_cipher_get_name (cipher), gnutls_mac_get_name (mac));
 
564
        printf ("%-50s\t0x%02x, 0x%02x\t%s\n",
 
565
                name,
 
566
                (unsigned char) id[0], (unsigned char) id[1],
 
567
                gnutls_protocol_get_name (version));
 
568
        if (verbose)
 
569
          printf ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
 
570
                  gnutls_kx_get_name (kx),
 
571
                  gnutls_cipher_get_name (cipher), gnutls_mac_get_name (mac));
524
572
      }
525
573
  }
526
574
 
530
578
    printf ("Certificate types: ");
531
579
    for (; *p; p++)
532
580
      {
533
 
        printf ("%s", gnutls_certificate_type_get_name (*p));
534
 
        if (*(p + 1))
535
 
          printf (", ");
536
 
        else
537
 
          printf ("\n");
 
581
        printf ("CTYPE-%s", gnutls_certificate_type_get_name (*p));
 
582
        if (*(p + 1))
 
583
          printf (", ");
 
584
        else
 
585
          printf ("\n");
538
586
      }
539
587
  }
540
588
 
544
592
    printf ("Protocols: ");
545
593
    for (; *p; p++)
546
594
      {
547
 
        printf ("%s", gnutls_protocol_get_name (*p));
548
 
        if (*(p + 1))
549
 
          printf (", ");
550
 
        else
551
 
          printf ("\n");
 
595
        printf ("VERS-%s", gnutls_protocol_get_name (*p));
 
596
        if (*(p + 1))
 
597
          printf (", ");
 
598
        else
 
599
          printf ("\n");
552
600
      }
553
601
  }
554
602
 
558
606
    printf ("Ciphers: ");
559
607
    for (; *p; p++)
560
608
      {
561
 
        printf ("%s", gnutls_cipher_get_name (*p));
562
 
        if (*(p + 1))
563
 
          printf (", ");
564
 
        else
565
 
          printf ("\n");
 
609
        printf ("%s", gnutls_cipher_get_name (*p));
 
610
        if (*(p + 1))
 
611
          printf (", ");
 
612
        else
 
613
          printf ("\n");
566
614
      }
567
615
  }
568
616
 
572
620
    printf ("MACs: ");
573
621
    for (; *p; p++)
574
622
      {
575
 
        printf ("%s", gnutls_mac_get_name (*p));
576
 
        if (*(p + 1))
577
 
          printf (", ");
578
 
        else
579
 
          printf ("\n");
 
623
        printf ("%s", gnutls_mac_get_name (*p));
 
624
        if (*(p + 1))
 
625
          printf (", ");
 
626
        else
 
627
          printf ("\n");
580
628
      }
581
629
  }
582
630
 
586
634
    printf ("Key exchange algorithms: ");
587
635
    for (; *p; p++)
588
636
      {
589
 
        printf ("%s", gnutls_kx_get_name (*p));
590
 
        if (*(p + 1))
591
 
          printf (", ");
592
 
        else
593
 
          printf ("\n");
 
637
        printf ("%s", gnutls_kx_get_name (*p));
 
638
        if (*(p + 1))
 
639
          printf (", ");
 
640
        else
 
641
          printf ("\n");
594
642
      }
595
643
  }
596
644
 
600
648
    printf ("Compression: ");
601
649
    for (; *p; p++)
602
650
      {
603
 
        printf ("%s", gnutls_compression_get_name (*p));
604
 
        if (*(p + 1))
605
 
          printf (", ");
606
 
        else
607
 
          printf ("\n");
 
651
        printf ("COMP-%s", gnutls_compression_get_name (*p));
 
652
        if (*(p + 1))
 
653
          printf (", ");
 
654
        else
 
655
          printf ("\n");
608
656
      }
609
657
  }
610
658
 
614
662
    printf ("Public Key Systems: ");
615
663
    for (; *p; p++)
616
664
      {
617
 
        printf ("%s", gnutls_pk_algorithm_get_name (*p));
618
 
        if (*(p + 1))
619
 
          printf (", ");
620
 
        else
621
 
          printf ("\n");
 
665
        printf ("%s", gnutls_pk_algorithm_get_name (*p));
 
666
        if (*(p + 1))
 
667
          printf (", ");
 
668
        else
 
669
          printf ("\n");
622
670
      }
623
671
  }
624
672
 
628
676
    printf ("PK-signatures: ");
629
677
    for (; *p; p++)
630
678
      {
631
 
        printf ("%s", gnutls_sign_algorithm_get_name (*p));
632
 
        if (*(p + 1))
633
 
          printf (", ");
634
 
        else
635
 
          printf ("\n");
 
679
        printf ("SIGN-%s", gnutls_sign_algorithm_get_name (*p));
 
680
        if (*(p + 1))
 
681
          printf (", ");
 
682
        else
 
683
          printf ("\n");
636
684
      }
637
685
  }
638
686
}
639
687
 
640
 
static int depr_printed = 0;
641
 
#define DEPRECATED if (depr_printed==0) { \
642
 
  fprintf(stderr, "This method of specifying algorithms is deprecated. Please use the --priority option.\n"); \
643
 
  depr_printed = 1; \
644
 
  }
645
 
 
646
 
void
647
 
parse_protocols (char **protocols, int protocols_size, int *protocol_priority)
648
 
{
649
 
  int i, j;
650
 
 
651
 
  if (protocols != NULL && protocols_size > 0)
652
 
    {
653
 
      DEPRECATED;
654
 
 
655
 
      for (j = i = 0; i < protocols_size; i++)
656
 
        {
657
 
          if (strncasecmp (protocols[i], "SSL", 3) == 0)
658
 
            protocol_priority[j++] = GNUTLS_SSL3;
659
 
          else if (strncasecmp (protocols[i], "TLS1.1", 6) == 0)
660
 
            protocol_priority[j++] = GNUTLS_TLS1_1;
661
 
          else if (strncasecmp (protocols[i], "TLS1.2", 6) == 0)
662
 
            protocol_priority[j++] = GNUTLS_TLS1_2;
663
 
          else if (strncasecmp (protocols[i], "TLS", 3) == 0)
664
 
            protocol_priority[j++] = GNUTLS_TLS1_0;
665
 
          else
666
 
            fprintf (stderr, "Unknown protocol: '%s'\n", protocols[i]);
667
 
        }
668
 
      protocol_priority[j] = 0;
669
 
    }
670
 
}
671
 
 
672
 
void
673
 
parse_ciphers (char **ciphers, int nciphers, int *cipher_priority)
674
 
{
675
 
  int j, i;
676
 
 
677
 
 
678
 
  if (ciphers != NULL && nciphers > 0)
679
 
    {
680
 
      DEPRECATED;
681
 
      for (j = i = 0; i < nciphers; i++)
682
 
        {
683
 
          if (strncasecmp (ciphers[i], "AES-2", 5) == 0)
684
 
            cipher_priority[j++] = GNUTLS_CIPHER_AES_256_CBC;
685
 
          else if (strncasecmp (ciphers[i], "AES", 3) == 0)
686
 
            cipher_priority[j++] = GNUTLS_CIPHER_AES_128_CBC;
687
 
          else if (strncasecmp (ciphers[i], "3DE", 3) == 0)
688
 
            cipher_priority[j++] = GNUTLS_CIPHER_3DES_CBC;
689
 
          else if (strcasecmp (ciphers[i], "ARCFOUR-40") == 0)
690
 
            cipher_priority[j++] = GNUTLS_CIPHER_ARCFOUR_40;
691
 
          else if (strcasecmp (ciphers[i], "ARCFOUR") == 0)
692
 
            cipher_priority[j++] = GNUTLS_CIPHER_ARCFOUR_128;
693
 
#ifdef  ENABLE_CAMELLIA
694
 
          else if (strncasecmp (ciphers[i], "CAMELLIA-2", 10) == 0)
695
 
            cipher_priority[j++] = GNUTLS_CIPHER_CAMELLIA_256_CBC;
696
 
          else if (strncasecmp (ciphers[i], "CAM", 3) == 0)
697
 
            cipher_priority[j++] = GNUTLS_CIPHER_CAMELLIA_128_CBC;
698
 
#endif
699
 
          else if (strncasecmp (ciphers[i], "NUL", 3) == 0)
700
 
            cipher_priority[j++] = GNUTLS_CIPHER_NULL;
701
 
          else
702
 
            fprintf (stderr, "Unknown cipher: '%s'\n", ciphers[i]);
703
 
        }
704
 
      cipher_priority[j] = 0;
705
 
    }
706
 
}
707
 
 
708
 
void
709
 
parse_macs (char **macs, int nmacs, int *mac_priority)
710
 
{
711
 
  int i, j;
712
 
 
713
 
 
714
 
  if (macs != NULL && nmacs > 0)
715
 
    {
716
 
      DEPRECATED;
717
 
      for (j = i = 0; i < nmacs; i++)
718
 
        {
719
 
          if (strncasecmp (macs[i], "MD5", 3) == 0)
720
 
            mac_priority[j++] = GNUTLS_MAC_MD5;
721
 
          else if (strncasecmp (macs[i], "RMD", 3) == 0)
722
 
            mac_priority[j++] = GNUTLS_MAC_RMD160;
723
 
          else if (strncasecmp (macs[i], "SHA512", 6) == 0)
724
 
            mac_priority[j++] = GNUTLS_MAC_SHA512;
725
 
          else if (strncasecmp (macs[i], "SHA384", 6) == 0)
726
 
            mac_priority[j++] = GNUTLS_MAC_SHA384;
727
 
          else if (strncasecmp (macs[i], "SHA256", 6) == 0)
728
 
            mac_priority[j++] = GNUTLS_MAC_SHA256;
729
 
          else if (strncasecmp (macs[i], "SHA", 3) == 0)
730
 
            mac_priority[j++] = GNUTLS_MAC_SHA1;
731
 
          else
732
 
            fprintf (stderr, "Unknown MAC: '%s'\n", macs[i]);
733
 
        }
734
 
      mac_priority[j] = 0;
735
 
    }
736
 
}
737
 
 
738
 
void
739
 
parse_ctypes (char **ctype, int nctype, int *cert_type_priority)
740
 
{
741
 
  int i, j;
742
 
 
743
 
  if (ctype != NULL && nctype > 0)
744
 
    {
745
 
      DEPRECATED;
746
 
      for (j = i = 0; i < nctype; i++)
747
 
        {
748
 
          if (strncasecmp (ctype[i], "OPE", 3) == 0)
749
 
            cert_type_priority[j++] = GNUTLS_CRT_OPENPGP;
750
 
          else if (strncasecmp (ctype[i], "X", 1) == 0)
751
 
            cert_type_priority[j++] = GNUTLS_CRT_X509;
752
 
          else
753
 
            fprintf (stderr, "Unknown certificate type: '%s'\n", ctype[i]);
754
 
        }
755
 
      cert_type_priority[j] = 0;
756
 
    }
757
 
}
758
 
 
759
 
void
760
 
parse_kx (char **kx, int nkx, int *kx_priority)
761
 
{
762
 
  int i, j;
763
 
 
764
 
 
765
 
  if (kx != NULL && nkx > 0)
766
 
    {
767
 
      DEPRECATED;
768
 
      for (j = i = 0; i < nkx; i++)
769
 
        {
770
 
          if (strcasecmp (kx[i], "SRP") == 0)
771
 
            kx_priority[j++] = GNUTLS_KX_SRP;
772
 
          else if (strcasecmp (kx[i], "SRP-RSA") == 0)
773
 
            kx_priority[j++] = GNUTLS_KX_SRP_RSA;
774
 
          else if (strcasecmp (kx[i], "SRP-DSS") == 0)
775
 
            kx_priority[j++] = GNUTLS_KX_SRP_DSS;
776
 
          else if (strcasecmp (kx[i], "RSA") == 0)
777
 
            kx_priority[j++] = GNUTLS_KX_RSA;
778
 
          else if (strcasecmp (kx[i], "PSK") == 0)
779
 
            kx_priority[j++] = GNUTLS_KX_PSK;
780
 
          else if (strcasecmp (kx[i], "DHE-PSK") == 0)
781
 
            kx_priority[j++] = GNUTLS_KX_DHE_PSK;
782
 
          else if (strcasecmp (kx[i], "RSA-EXPORT") == 0)
783
 
            kx_priority[j++] = GNUTLS_KX_RSA_EXPORT;
784
 
          else if (strncasecmp (kx[i], "DHE-RSA", 7) == 0)
785
 
            kx_priority[j++] = GNUTLS_KX_DHE_RSA;
786
 
          else if (strncasecmp (kx[i], "DHE-DSS", 7) == 0)
787
 
            kx_priority[j++] = GNUTLS_KX_DHE_DSS;
788
 
          else if (strncasecmp (kx[i], "ANON", 4) == 0)
789
 
            kx_priority[j++] = GNUTLS_KX_ANON_DH;
790
 
          else
791
 
            fprintf (stderr, "Unknown key exchange: '%s'\n", kx[i]);
792
 
        }
793
 
      kx_priority[j] = 0;
794
 
    }
795
 
}
796
 
 
797
 
void
798
 
parse_comp (char **comp, int ncomp, int *comp_priority)
799
 
{
800
 
  int i, j;
801
 
 
802
 
  if (comp != NULL && ncomp > 0)
803
 
    {
804
 
      DEPRECATED;
805
 
      for (j = i = 0; i < ncomp; i++)
806
 
        {
807
 
          if (strncasecmp (comp[i], "NUL", 3) == 0)
808
 
            comp_priority[j++] = GNUTLS_COMP_NULL;
809
 
          else if (strncasecmp (comp[i], "ZLI", 3) == 0)
810
 
            comp_priority[j++] = GNUTLS_COMP_DEFLATE;
811
 
          else if (strncasecmp (comp[i], "DEF", 3) == 0)
812
 
            comp_priority[j++] = GNUTLS_COMP_DEFLATE;
813
 
          else if (strncasecmp (comp[i], "LZO", 3) == 0)
814
 
            comp_priority[j++] = GNUTLS_COMP_LZO;
815
 
          else
816
 
            fprintf (stderr, "Unknown compression: '%s'\n", comp[i]);
817
 
        }
818
 
      comp_priority[j] = 0;
819
 
    }
820
 
}
821
 
 
822
688
void
823
689
sockets_init (void)
824
690
{
858
724
 
859
725
  return ntohs (server_port->s_port);
860
726
}
 
727