diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-06-03 16:18:26 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-06-03 16:18:26 +0200 |
commit | 56b0281e7cc0a3d05afff14d95753162b8cfb63c (patch) | |
tree | e79a52d90387a9c7ba348cbea66a2da92181b5bd /src/psk.c | |
parent | 327551481196975622559f5ed66d40a6e5ce592b (diff) | |
download | gnutls-56b0281e7cc0a3d05afff14d95753162b8cfb63c.tar.gz |
psktool: Support --netconf-hint.
Diffstat (limited to 'src/psk.c')
-rw-r--r-- | src/psk.c | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2007 Free Software Foundation + * Copyright (C) 2005, 2007, 2008 Free Software Foundation * * This file is part of GNUTLS. * @@ -130,21 +130,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"); |