summaryrefslogtreecommitdiff
path: root/src/psk.c
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-06-03 16:18:26 +0200
committerSimon Josefsson <simon@josefsson.org>2008-06-03 16:18:26 +0200
commit56b0281e7cc0a3d05afff14d95753162b8cfb63c (patch)
treee79a52d90387a9c7ba348cbea66a2da92181b5bd /src/psk.c
parent327551481196975622559f5ed66d40a6e5ce592b (diff)
downloadgnutls-56b0281e7cc0a3d05afff14d95753162b8cfb63c.tar.gz
psktool: Support --netconf-hint.
Diffstat (limited to 'src/psk.c')
-rw-r--r--src/psk.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/psk.c b/src/psk.c
index 1602e6e146..94a66f3450 100644
--- a/src/psk.c
+++ b/src/psk.c
@@ -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");