]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
make sure that a valid number of days is entered
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 6 Jul 2013 14:48:06 +0000 (16:48 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 6 Jul 2013 14:54:29 +0000 (16:54 +0200)
src/certtool.c

index 9cd72cae7753999704efb3c4067f3fad9022c86f..04566ca9d4e3cd3feb29d7fd695d8383085371b5 100644 (file)
@@ -240,6 +240,7 @@ generate_certificate (gnutls_privkey_t * ret_key,
   int ret;
   int client;
   int days, result, ca_status = 0, is_ike = 0, path_len;
+  time_t secs, now;
   int vers;
   unsigned int usage = 0, server;
   gnutls_x509_crq_t crq;        /* request */
@@ -329,11 +330,17 @@ generate_certificate (gnutls_privkey_t * ret_key,
 
   gnutls_x509_crt_set_activation_time (crt, time (NULL));
 
-  days = get_days ();
+  now = time(NULL);
+  
+  do 
+    {
+      days = get_days ();
+      secs = days * 24 * 60 * 60 + now;
+    }
+  while (secs < now || (unsigned)(secs-now)/(24*60*60) != (unsigned)days);
 
   result =
-    gnutls_x509_crt_set_expiration_time (crt,
-                                         time (NULL) + ((time_t) days) * 24 * 60 * 60);
+    gnutls_x509_crt_set_expiration_time (crt, secs);
   if (result < 0)
     error (EXIT_FAILURE, 0, "set_expiration: %s", gnutls_strerror (result));