[tor-commits] [tor/master] Make dir servers include a "Date:" http header more often
nickm at torproject.org
nickm at torproject.org
Thu Sep 14 21:20:54 UTC 2017
commit eb429232ef11f15f8a9f2ad60cc106103648a525
Author: Roger Dingledine <arma at torproject.org>
Date: Wed Sep 13 23:19:04 2017 -0400
Make dir servers include a "Date:" http header more often
Directory servers now include a "Date:" http header for response
codes other than 200. Clients starting with a skewed clock and a
recent consensus were getting "304 Not modified" responses from
directory authorities, so without a Date header the client would
never hear about a wrong clock.
Fixes bug 23499; bugfix on 0.0.8rc1.
---
changes/bug23499 | 6 ++++++
src/or/directory.c | 22 ++++++++++++++++++----
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/changes/bug23499 b/changes/bug23499
new file mode 100644
index 000000000..e53b03c34
--- /dev/null
+++ b/changes/bug23499
@@ -0,0 +1,6 @@
+ o Minor bugfixes:
+ - Directory servers now include a "Date:" http header for response
+ codes other than 200. Clients starting with a skewed clock and a
+ recent consensus were getting "304 Not modified" responses from
+ directory authorities, so without a Date header the client would
+ never hear about a wrong clock. Fixes bug 23499; bugfix on 0.0.8rc1.
diff --git a/src/or/directory.c b/src/or/directory.c
index 9551b4155..0c79b4659 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -3479,14 +3479,28 @@ static void
write_http_status_line(dir_connection_t *conn, int status,
const char *reason_phrase)
{
- char buf[256];
- if (!reason_phrase)
+ char buf[256+RFC1123_TIME_LEN+1];
+ char *datestring = NULL;
+
+ if (!reason_phrase) { /* bullet-proofing */
reason_phrase = "unspecified";
- if (tor_snprintf(buf, sizeof(buf), "HTTP/1.0 %d %s\r\n\r\n",
- status, reason_phrase) < 0) {
+ }
+
+ if (server_mode(get_options())) {
+ /* include the Date: header, but only if we're a relay or bridge */
+ char datebuf[RFC1123_TIME_LEN+1];
+ format_rfc1123_time(datebuf, time(NULL));
+ tor_asprintf(&datestring, "Date: %s\r\n", datebuf);
+ }
+
+ if (tor_snprintf(buf, sizeof(buf), "HTTP/1.0 %d %s\r\n%s\r\n",
+ status, reason_phrase, datestring?datestring:"") < 0) {
log_warn(LD_BUG,"status line too long.");
+ tor_free(datestring);
return;
}
+ tor_free(datestring);
+
log_debug(LD_DIRSERV,"Wrote status 'HTTP/1.0 %d %s'", status, reason_phrase);
connection_buf_add(buf, strlen(buf), TO_CONN(conn));
}
More information about the tor-commits
mailing list