From: Nikos Mavrogiannopoulos Date: Wed, 24 Oct 2007 11:21:42 +0000 (+0300) Subject: updated some examples. X-Git-Tag: gnutls_2_1_4~20^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6cf29d4aff604932a45e642ff58ef3f386e33107;p=thirdparty%2Fgnutls.git updated some examples. --- diff --git a/doc/examples/ex-serv-export.c b/doc/examples/ex-serv-export.c index 7a20b0e902..f8c80cf9b6 100644 --- a/doc/examples/ex-serv-export.c +++ b/doc/examples/ex-serv-export.c @@ -19,6 +19,7 @@ #include #include #include +#include /* for gcry_control */ #define KEYFILE "key.pem" #define CERTFILE "cert.pem" @@ -82,16 +83,25 @@ gnutls_dh_params_t dh_params; */ gnutls_rsa_params_t rsa_params; +static char srp_dh_group2048[] = + "-----BEGIN DH PARAMETERS-----\n" + "MIIBBwKCAQCsa9tBMkqam/Fm3l4TiVgvr3K2ZRmH7gf8MZKUPbVgUKNzKcu0oJnt\n" + "gZPgdXdnoT3VIxKrSwMxDc1/SKnaBP1Q6Ag5ae23Z7DPYJUXmhY6s2YaBfvV+qro\n" + "KRipli8Lk7hV+XmT7Jde6qgNdArb9P90c1nQQdXDPqcdKB5EaxR3O8qXtDoj+4AW\n" + "dr0gekNsZIHx0rkHhxdGGludMuaI+HdIVEUjtSSw1X1ep3onddLs+gMs+9v1L7N4\n" + "YWAnkATleuavh05zA85TKZzMBBx7wwjYKlaY86jQw4JxrjX46dv7tpS1yAPYn3rk\n" + "Nd4jbVJfVHWbZeNy/NaO8g+nER+eSv9zAgEC\n" + "-----END DH PARAMETERS-----\n"; + int generate_dh_params (void) { - /* Generate Diffie Hellman parameters - for use with DHE - * kx algorithms. These should be discarded and regenerated - * once a day, once a week or once a month. Depends on the - * security requirements. +gnutls_datum dparams = { srp_dh_group2048, sizeof( srp_dh_group2048) }; + /* Here instead of generating Diffie Hellman parameters (for use with DHE + * kx algorithms) we import them. */ gnutls_dh_params_init (&dh_params); - gnutls_dh_params_generate2 (dh_params, DH_BITS); + gnutls_dh_params_import_pkcs3 (dh_params, &dparams, GNUTLS_X509_FMT_PEM); return 0; } @@ -102,9 +112,9 @@ generate_rsa_params (void) gnutls_rsa_params_init (&rsa_params); /* Generate RSA parameters - for use with RSA-export - * cipher suites. These should be discarded and regenerated - * once a day, once every 500 transactions etc. Depends on the - * security requirements. + * cipher suites. This is an RSA private key and should be + * discarded and regenerated once a day, once every 500 + * transactions etc. Depends on the security requirements. */ gnutls_rsa_params_generate2 (rsa_params, 512); @@ -128,10 +138,15 @@ main (void) strcpy (name, "Echo Server"); + /* to disallow usage of the blocking /dev/random + */ + gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); + /* this must be called once in the program */ gnutls_global_init (); + gnutls_certificate_allocate_credentials (&cert_cred); gnutls_certificate_set_x509_trust_file (cert_cred, CAFILE, diff --git a/doc/examples/ex-serv1.c b/doc/examples/ex-serv1.c index e331542a05..e0327e7f27 100644 --- a/doc/examples/ex-serv1.c +++ b/doc/examples/ex-serv1.c @@ -19,6 +19,7 @@ #include #include #include +#include /* for gcry_control */ #define KEYFILE "key.pem" #define CERTFILE "cert.pem" @@ -71,9 +72,11 @@ generate_dh_params (void) { /* Generate Diffie Hellman parameters - for use with DHE - * kx algorithms. These should be discarded and regenerated - * once a day, once a week or once a month. Depending on the - * security requirements. + * kx algorithms. When short bit length is used, it might + * be wise to regenerate parameters. + * + * Check the ex-serv-export.c example for using static + * parameters. */ gnutls_dh_params_init (&dh_params); gnutls_dh_params_generate2 (dh_params, DH_BITS); @@ -94,6 +97,10 @@ main (void) char buffer[MAX_BUF + 1]; int optval = 1; + /* to disallow usage of the blocking /dev/random + */ + gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); + /* this must be called once in the program */ gnutls_global_init ();