diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-06-04 10:21:57 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-06-04 10:21:57 +0200 |
commit | 639425f8b816802560d3dc563e5a31107e6be3f5 (patch) | |
tree | 9a4b4ef5d2e26022f3deca4cbff906e085aa1a66 /src/psk.c | |
parent | 6aea6e159330e2a7a00817deff33546af37c8a18 (diff) | |
parent | aa2c7264a52b993aca39c613e5fe1aed7511c972 (diff) | |
download | gnutls-639425f8b816802560d3dc563e5a31107e6be3f5.tar.gz |
Merge branch 'gnutls_with_netconf'
Conflicts:
ChangeLog
Makefile.am
NEWS
configure.in
doc/examples/Makefile.am
doc/gnutls.texi
doc/manpages/Makefile.am
src/cli.c
src/psk-gaa.c
src/psk.gaa
tests/Makefile.am
Diffstat (limited to 'src/psk.c')
-rw-r--r-- | src/psk.c | 48 |
1 files changed, 38 insertions, 10 deletions
@@ -128,21 +128,49 @@ main (int argc, char **argv) exit (1); } - if (info.key_size < 1) - info.key_size = 16; - - ret = gc_pseudo_random ((char *) key, info.key_size); - if (ret != GC_OK) + if (info.netconf_hint) { - fprintf (stderr, "Not enough randomness\n"); - exit (1); + char *passwd; + + if (info.key_size != 0 && info.key_size != 20) + { + fprintf (stderr, "For netconf, key size must always be 20.\n"); + exit (1); + } + + passwd = getpass ("Enter password: "); + if (passwd == NULL) + { + fprintf (stderr, "Please specify a password\n"); + exit (1); + } + + ret = gnutls_psk_netconf_derive_key (passwd, + info.username, + info.netconf_hint, + &dkey); } + else + { + if (info.key_size < 1) + info.key_size = 16; - printf ("Generating a random key for user '%s'\n", info.username); + printf ("Generating a random key for user '%s'\n", info.username); + + ret = gc_pseudo_random ((char *) key, info.key_size); + if (ret != GC_OK) + { + fprintf (stderr, "Not enough randomness\n"); + exit (1); + } + + dkey.data = key; + dkey.size = info.key_size; + } - dkey.data = key; - dkey.size = info.key_size; ret = gnutls_hex_encode (&dkey, hex_key, &hex_key_size); + if (info.netconf_hint) + gnutls_free (dkey.data); if (ret < 0) { fprintf (stderr, "HEX encoding error\n"); |