summaryrefslogtreecommitdiff
path: root/src/common/tortls.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-10-22 16:41:35 +0000
committerNick Mathewson <nickm@torproject.org>2003-10-22 16:41:35 +0000
commit7604cfe61b7ae997c850bdc175b9e4e9684d020c (patch)
treeef955719e52cfc4357f0a7bed792d251f694d7ea /src/common/tortls.c
parentcf2fe9d1da0b91302355542d60050ae720ceaf5d (diff)
downloadtor-7604cfe61b7ae997c850bdc175b9e4e9684d020c.tar.gz
tor-7604cfe61b7ae997c850bdc175b9e4e9684d020c.zip
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. svn:r658
Diffstat (limited to 'src/common/tortls.c')
-rw-r--r--src/common/tortls.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c
index b9f3dbab38..b7f13aae0f 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -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 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa,
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 @@ tor_tls_verify(tor_tls *tls)
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;
}