]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
updated some examples.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 24 Oct 2007 11:21:42 +0000 (14:21 +0300)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 24 Oct 2007 11:21:42 +0000 (14:21 +0300)
doc/examples/ex-serv-export.c
doc/examples/ex-serv1.c

index 7a20b0e902ce773dac5e1d715b608265c77e6547..f8c80cf9b60ee83178535af153f50f29f4ca6f8f 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <gnutls/gnutls.h>
+#include <gcrypt.h> /* 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,
index e331542a05daa7dd526d49808ca4f9f85a550adb..e0327e7f27b096eca18a5f982ccda38d6dfb7132 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <gnutls/gnutls.h>
+#include <gcrypt.h> /* 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 ();