|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Dynamically building the PSK keysHi, I'm working on the sample programs provided in the source examples folder and I would like some help from you. I'm trying to do a DH key exchange with PSK authentication. The client sample (ex-client-psk.c) assigns the pre shared key as follows: const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; The server sample (ex-serv-psk.c) does the key assignment in the callback function pskfunc as follows: key->data = gnutls_malloc (4); char * somekey = "DEADBEEF"; key -> data = somekey; My question is : since data in the struct gnutls_datum_t has been defined as unsigned char, why doesn't this assignment work ? Can you please help me how I can make the PSK keys to be dynamic and make the authentication to succeed ? I'll really appreciate your help. Ram G _______________________________________________ Help-gnutls mailing list Help-gnutls@... http://lists.gnu.org/mailman/listinfo/help-gnutls |
|
|
Re: Dynamically building the PSK keysRam G wrote:
> Hi, > > I'm working on the sample programs provided in the source examples folder > and I would like some help from you. I'm trying to do a DH key exchange with > PSK authentication. > > The client sample (ex-client-psk.c) assigns the pre shared key as follows: > > const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; > > The server sample (ex-serv-psk.c) does the key assignment in the callback > function pskfunc as follows: > > key->data = gnutls_malloc (4); > key->data[0] = 0xDE; > key->data[1] = 0xAD; > key->data[2] = 0xBE; > key->data[3] = 0xEF; > key->size = 4; It is not the same as above. Above you use 8 bytes and here 4. Use instead: key->data[0] = 'D'; key->data[1] = 'E'; key->data[2] = 'A'; key->data[3] = 'D'; key->data[4] = 'B'; key->data[5] = 'E'; key->data[6] = 'E'; key->data[7] = 'F'; key->size = 8; > I would like to assign the pre-shared key dynamically. If I assign the PSK > in the server as follows, it does not work. I get the error "Decryption has > failed". Actually how the keys are going to be generated? You have to think about that seriously and make sure that the key generation is not weakening the cryptosystem. To be on the safe side, and especially if you are not experienced in the field use the tools provided by gnutls for the key generation. regards, Nikos _______________________________________________ Help-gnutls mailing list Help-gnutls@... http://lists.gnu.org/mailman/listinfo/help-gnutls |
|
|
|
|
|
Re: Dynamically building the PSK keysI think you are keeping the same confusion in data formats.
A string with characters "ABCD" is saved in memory as characters 'A' (ascii 0x41), 'B' (ascii 0x42), 'C' (ascii 0x43) and 'D' (ascii 0x44) in 4 bytes, not as 2 bytes 0xAB and 0xCD.
Greetings -- David Marín Carreño 2009/7/14 Ram G <mydevforums@...>
_______________________________________________ Help-gnutls mailing list Help-gnutls@... http://lists.gnu.org/mailman/listinfo/help-gnutls |
|
|
Re: Dynamically building the PSK keysFinally I could complete the handshake using DHE-PSK. I followed the samples ex-client-psk.c and ex-serv-psk.c but instead of hardcoded keys, I dynamically assigned the keys as follows:
char * dynamickeys; //Could be any string with hex characters like DEADBEEF
atohx(key->data,dynamickeys);
Here is the atohx function I got from the following link:
char * atohx(char * dst, const char * src)
{ int lsb,msb; char * ret; ret = dst; for(lsb = 0, msb = 0; *src; src += 2) { msb = tolower(*src); lsb = tolower(*(src + 1)); msb -= isdigit(msb) ? 0x30 : 0x57; lsb -= isdigit(lsb) ? 0x30 : 0x57; if((msb < 0x0 || msb > 0xf) || (lsb < 0x0 || lsb > 0xf)) { *ret = 0; return NULL; } *dst++ = (char)(lsb | (msb << 4)); } *dst = 0; return ret; } Thanks to all for all your suggestions.
Thanks
Ramg
On Wed, Jul 15, 2009 at 3:24 AM, David Marín Carreño <davefx@...> wrote: I think you are keeping the same confusion in data formats. _______________________________________________ Help-gnutls mailing list Help-gnutls@... http://lists.gnu.org/mailman/listinfo/help-gnutls |
|
|
Re: Dynamically building the PSK keysRam G wrote:
> Finally I could complete the handshake using DHE-PSK. I followed the samples > ex-client-psk.c and ex-serv-psk.c but instead of hardcoded keys, I > dynamically assigned the keys as follows: > > char * dynamickeys; //Could be any string with hex characters like DEADBEEF > atohx(key->data,dynamickeys); If you want to use passwords for psk please use gnutls_psk_netconf_derive_key(). If you just want to convert hex to binary data you can just use gnutls_hex_encode and decode. PSK works with keys (not passwords) that are usually derived from a device such as /dev/(u)random. regards, Nikos _______________________________________________ Help-gnutls mailing list Help-gnutls@... http://lists.gnu.org/mailman/listinfo/help-gnutls |
| Free embeddable forum powered by Nabble | Forum Help |