60 for (i = 0; i < n; i++) {
73 const HstsData_t *node = v1;
74 const char *host = v2;
87 _MSG(
"HSTS: removed policy for %s\n", policy->host);
98 time_t ret, now = time(NULL);
99 struct tm *tm = gmtime(&now);
101 if (seconds_from_now > INT_MAX - tm->tm_sec)
102 tm->tm_sec = INT_MAX;
104 tm->tm_sec += seconds_from_now;
107 if (ret == (time_t) -1)
118 const HstsData_t *node1 = v1, *node2 = v2;
128 _MSG(
"HSTS: %s %s%s: until %s", (policy ?
"modify" :
"add"), host,
129 (subdomains ?
" and subdomains" :
""), ctime(&exp));
131 if (policy == NULL) {
132 policy =
dNew0(HstsData_t, 1);
136 policy->subdomains = subdomains;
137 policy->expires_at = exp;
153 len = strcspn(str,
"=;");
156 while (len && (str[len - 1] ==
' ' || str[len - 1] ==
'\t'))
169 if (**header_str ==
'=') {
176 len = strcspn(str,
";");
179 while (len && (str[len - 1] ==
' ' || str[len - 1] ==
'\t'))
194 *str += strcspn(*str,
";");
206 _MSG(
"HSTS header for %s: %s\n", host, header);
210 _MSG(
"But there were certificate warnings, so ignore it (!)\n");
227 max_age = strtol(value, NULL, 10);
230 max_age_valid =
TRUE;
242 MSG(
"HSTS: header contains unknown attribute: '%s'\n", attr);
261 time_t now = time(NULL);
265 _MSG(
"HSTS: expired\n");
278 _MSG(
"HSTS: matched host %s\n", host);
285 const char *domain_str;
287 for (domain_str = strchr(host+1,
'.');
288 domain_str != NULL && *domain_str;
289 domain_str = strchr(domain_str+1,
'.')) {
292 if (policy && policy->subdomains) {
293 _MSG(
"HSTS: matched %s under %s subdomain rule\n", host,
311 const long ONE_YEAR = 60 * 60 * 24 * 365;
313 char *rc, *subdomains;
318 while (!feof(stream)) {
321 if (!rc && ferror(stream)) {
322 MSG_WARN(
"HSTS: Error while reading preload entries: %s\n",
330 if (line[0] !=
'\0' && line[0] !=
'#') {
334 while (line[i] !=
'\0' && !
dIsspace(line[i]))
335 domain[j++] = line[i++];
342 subdomains = line + i;
349 MSG_WARN(
"HSTS: format of line not recognized. Ignoring '%s'.\n",
359 struct tm future_tm = {7, 14, 3, 19, 0, 138, 0, 0, 0, 0, 0};
366 fclose(preload_file);
void dList_insert_sorted(Dlist *lp, void *data, dCompareFunc func)
Insert an element into a sorted list.
int dStrAsciiCasecmp(const char *s1, const char *s2)
char * dStrstrip(char *s)
Remove leading and trailing whitespace.
char * dStrdup(const char *s)
Dlist * dList_new(int size)
Create a new empty list.
int dList_length(Dlist *lp)
For completing the ADT.
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
char * dStrndup(const char *s, size_t sz)
void * dList_find_sorted(Dlist *lp, const void *data, dCompareFunc func)
Search a sorted list.
void dList_free(Dlist *lp)
Free a list (not its elements)
void dList_remove(Dlist *lp, const void *data)
static int dIsdigit(unsigned char c)
#define dNew0(type, count)
static int dIsspace(unsigned char c)
static void Hsts_preload(FILE *stream)
bool_t a_Hsts_require_https(const char *host)
static time_t Hsts_future_time(long seconds_from_now)
Return the time_t for a future time.
static int Domain_node_cmp(const void *v1, const void *v2)
Compare function for searching domains.
static void Hsts_eat_value(const char **str)
Advance past any value.
static time_t hsts_latest_representable_time
void a_Hsts_freeall(void)
void a_Hsts_set(const char *header, const DilloUrl *url)
The response for this url had an HSTS header, so let's take action.
static void Hsts_set_policy(const char *host, long max_age, bool_t subdomains)
static char * Hsts_parse_value(const char **header_str)
Get the value in *header_str.
static void Hsts_free_policy(HstsData_t *p)
static HstsData_t * Hsts_get_policy(const char *host)
static void Hsts_remove_policy(HstsData_t *policy)
static char * Hsts_parse_attr(const char **header_str)
Read the next attribute.
static bool_t Hsts_expired(HstsData_t *policy)
static int Domain_node_domain_str_cmp(const void *v1, const void *v2)
Compare function for searching a domain node by domain string.
void a_Hsts_init(FILE *preload_file)
DilloPrefs prefs
Global Data.
bool_t http_strict_transport_security
int a_Tls_certificate_is_clean(const DilloUrl *url)
Did everything seem proper with the certificate – no warnings to click through?.