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

« back to all changes in this revision

Viewing changes to tests/netconf-psk.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:
1
 
/*
2
 
 * Copyright (C) 2008, 2010 Free Software Foundation, Inc.
3
 
 *
4
 
 * Author: Simon Josefsson
5
 
 *
6
 
 * This file is part of GnuTLS.
7
 
 *
8
 
 * GnuTLS is free software; you can redistribute it and/or modify it
9
 
 * under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 3 of the License, or
11
 
 * (at your option) any later version.
12
 
 *
13
 
 * GnuTLS is distributed in the hope that it will be useful, but
14
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with GnuTLS; if not, write to the Free Software Foundation,
20
 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
# include <config.h>
25
 
#endif
26
 
 
27
 
#include <stdio.h>
28
 
#include <stdlib.h>
29
 
#include <string.h>
30
 
#include <sys/types.h>
31
 
#include <unistd.h>
32
 
 
33
 
#include <gnutls/gnutls.h>
34
 
 
35
 
#include "utils.h"
36
 
 
37
 
static void
38
 
tls_log_func (int level, const char *str)
39
 
{
40
 
  fprintf (stderr, "<%d>| %s", level, str);
41
 
}
42
 
 
43
 
void
44
 
doit (void)
45
 
{
46
 
  const char *known =
47
 
    "\x88\xf3\x82\x4b\x3e\x56\x59\xf5\x2d\x00"
48
 
    "\xe9\x59\xba\xca\xb9\x54\xb6\x54\x03\x44";
49
 
  gnutls_datum_t key = { NULL, 0 };
50
 
 
51
 
  gnutls_global_init ();
52
 
 
53
 
  gnutls_global_set_log_function (tls_log_func);
54
 
  if (debug)
55
 
    gnutls_global_set_log_level (2);
56
 
 
57
 
  if (gnutls_psk_netconf_derive_key ("password", "psk_identity",
58
 
                                     "psk_identity_hint", &key) == 0)
59
 
    {
60
 
      if (debug)
61
 
        success ("success: gnutls_psk_netconf_derive_key\n");
62
 
    }
63
 
  else
64
 
    fail ("gnutls_psk_netconf_derive_key failure\n");
65
 
 
66
 
  if (debug)
67
 
    hexprint (key.data, key.size);
68
 
 
69
 
  if (key.size == 20 && memcmp (key.data, known, 20) == 0)
70
 
    {
71
 
      if (debug)
72
 
        success ("success: match.\n");
73
 
    }
74
 
  else
75
 
    fail ("FAIL: key differ.\n");
76
 
 
77
 
  gnutls_free (key.data);
78
 
 
79
 
  gnutls_global_deinit ();
80
 
}