#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;
};
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))
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;
}
#include "or.h"
+/* How far in the future do we allow a router to get? (seconds) */
+#define ROUTER_ALLOW_SKEW (30*60)
+
extern or_options_t options; /* command-line and config-file options */
static int the_directory_is_dirty = 1;
tor_free(desc_tmp);
/* Okay. Now check whether the fingerprint is recognized. */
if (!dirserv_router_fingerprint_is_known(ri)) {
- log(LOG_WARN, "Identity is unrecognized for descriptor");
+ log_fn(LOG_WARN, "Identity is unrecognized for descriptor");
+ goto err;
+ }
+ /* Is there too much clock skew? */
+ if (ri->published_on > time(NULL)+ROUTER_ALLOW_SKEW) {
+ log_fn(LOG_WARN, "Publication time for nickname %s is too far in the future; possible clock skew.", ri->nickname);
goto err;
}
/* Do we already have an entry for this router? */