[or-cvs] Clock skew fixes.

Nick Mathewson nickm at seul.org
Wed Oct 22 16:41:38 UTC 2003


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv11427/src/common

Modified Files:
	tortls.c 
Log Message:
Clock skew fixes.

Allow some slop (currently 3 minutes) when checking certificate validity.

Change certificate lifetime from 1 year to 2 days.  Since we
regenerate regularly (we regenerate regularly, right??), this
shouldn't be a problem.

Have directories reject descriptors published too far in the future
(currently 30 minutes).  If dirservs don't do this:
    0) Today is January 1, 2000.
    1) A very skewed server publishes descriptor X with a declared
       publication time of August 1, 2000.
    2) The directory includes X.
    3) Because of certificate lifetime issues, nobody can use the
       skewed server.
    4) The server fixes its skew, and goes to republish a new descriptor Y
       with publication time of January 1, 2000.
    5) But because the directory already has a "more recent" descriptor X,
       it rejects descriptor "Y" as superseded!

This patch should make step 2 go away.



Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- tortls.c	21 Oct 2003 09:48:58 -0000	1.27
+++ tortls.c	22 Oct 2003 16:41:35 -0000	1.28
@@ -22,6 +22,11 @@
 #include <openssl/asn1.h>
 #include <openssl/bio.h>
 
+/* How long do certificates live? (sec) */
+#define CERT_LIFETIME  (2*24*60*60)
+/* How much clock skew do we tolerate when checking certificates? (sec) */
+#define CERT_ALLOW_SKEW (3*60)
+
 struct tor_tls_context_st {
   SSL_CTX *ctx;
 };
@@ -166,7 +171,7 @@
     goto error;
   if (!X509_time_adj(X509_get_notBefore(x509),0,&start_time))
     goto error;
-  end_time = start_time + 24*60*60*365;
+  end_time = start_time + CERT_LIFETIME;
   if (!X509_time_adj(X509_get_notAfter(x509),0,&end_time))
     goto error;
   if (!X509_set_pubkey(x509, pkey))
@@ -499,18 +504,20 @@
   X509 *cert = NULL;
   EVP_PKEY *pkey = NULL;
   RSA *rsa = NULL;
-  time_t now;
+  time_t now, t;
   crypto_pk_env_t *r = NULL;
   if (!(cert = SSL_get_peer_certificate(tls->ssl)))
     return NULL;
   
   now = time(NULL);
-  if (X509_cmp_time(X509_get_notBefore(cert), &now) > 0) {
-    log_fn(LOG_WARN,"X509_get_notBefore(cert) is in the future");
+  t = now - CERT_ALLOW_SKEW;
+  if (X509_cmp_time(X509_get_notBefore(cert), &t) > 0) {
+    log_fn(LOG_WARN,"Certificate becomes valid in the future: possible clock skew.");
     goto done;
   }
-  if (X509_cmp_time(X509_get_notAfter(cert), &now) < 0) {
-    log_fn(LOG_WARN,"X509_get_notAfter(cert) is in the past");
+  t = now + CERT_ALLOW_SKEW;
+  if (X509_cmp_time(X509_get_notAfter(cert), &t) < 0) {
+    log_fn(LOG_WARN,"Certificate already expired; possible clock skew.");
     goto done;
   }
   



More information about the tor-commits mailing list