Account for entries missing the 'force-https' mode.
authorGeorgios Kontaxis <redacted>
Mon, 22 Aug 2016 18:48:24 +0000 (14:48 -0400)
committerGeorgios Kontaxis <redacted>
Mon, 22 Aug 2016 18:48:24 +0000 (14:48 -0400)
Makefile
get_list.sh
hstsPreloadChromium.py
makedb.py

index 537424a2e875373b698a393050a65e5e987c2b79..3a31c3c57e1f7f1515431f243bd8295ee4667d47 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,11 @@
 
 all: db.sqlite3
 
-chromium_hsts_list.dat:
+transport_security_state_static:
        bash get_list.sh
 
-db.sqlite3: chromium_hsts_list.dat
+db.sqlite3: transport_security_state_static
        python makedb.py
 
 clean:
-       rm -i chromium_hsts_list.dat db.sqlite3
+       rm -i transport_security_state_static db.sqlite3
index e0aa7a8b4a4c1a3de39189a8f740a8cca21b6f89..289db1580023b71a0a82d9f539a67d408fdab6c6 100644 (file)
@@ -4,4 +4,4 @@
 URL="https://chromium.googlesource.com/chromium/src/net/+/master/http/transport_security_state_static.json?format=TEXT"
 
 curl -L "${URL}" | base64 --decode |
-       egrep -v "^([ ]*\/\/|$)" > "chromium_hsts_list.dat";
+       egrep -v "^([ ]*\/\/|$)" > "transport_security_state_static";
index b87ca7041f26427a41de91491a631a03e988f434..65d06a9fb8686789b701f8a07bb6e349604a7a13 100755 (executable)
@@ -29,6 +29,7 @@ class hstsPreloadChromium:
 
        def __init__(self, dbPath):
                conn = sqlite3.connect(dbpath)
+               conn.row_factory = sqlite3.Row
                conn.text_factory = str
                self._dbConnCursor = conn.cursor()
 
@@ -38,16 +39,18 @@ class hstsPreloadChromium:
                for hostname in entries:
                        self.verbose and print("hsts '%s' : " % hostname, end="")
 
-                       self._dbConnCursor.execute('SELECT domain from hsts where domain=?',
+                       self._dbConnCursor.execute('SELECT name,mode from entries where name=?',
                                (hostname,))
                        match = self._dbConnCursor.fetchone()
                        if match:
+                               self.verbose and print("HIT")
+                               if match["mode"] != "force-https":
+                                       continue
                                hits.append(hostname)
-                               self.verbose and print("TRUE")
                                continue
 
                        # Lookup was a miss.
-                       self.verbose and print("FALSE")
+                       self.verbose and print("MISS")
 
                        # Look for ever shorter wildcards.
                        labels = hostname.strip(".").split(".")
@@ -57,16 +60,18 @@ class hstsPreloadChromium:
 
                                self.verbose and print("hsts '%s' : " % hsts_wild, end="")
 
-                               self._dbConnCursor.execute('SELECT domain from hsts where domain=?',
+                               self._dbConnCursor.execute('SELECT name,mode from entries where name=?',
                                        (hsts_wild,))
                                match = self._dbConnCursor.fetchone()
                                if match:
+                                       self.verbose and print("HIT")
+                                       if match["mode"] != "force-https":
+                                               break
                                        hits.append(hostname)
-                                       self.verbose and print("TRUE")
                                        break
 
                                # Wildcard lookup was a miss.
-                               self.verbose and print("FALSE")
+                               self.verbose and print("MISS")
 
                return hits
 
index 59789669f776de5a550a08e50b3e1214ecf2a156..b7cc2c6e73a7b54a827bc3977590029a13d40526 100644 (file)
--- a/makedb.py
+++ b/makedb.py
@@ -15,23 +15,24 @@ import time
 
 dirname = os.path.dirname(sys.argv[0])
 
-# Populate hsts records array
-hsts = []
+# Populate entries array
+entries = []
 
-f = file(os.path.join(dirname, "chromium_hsts_list.dat"), "r")
+f = file(os.path.join(dirname, "transport_security_state_static"), "r")
 j = json.loads(f.read())
 f.close()
 
 for entry in j["entries"]:
-       if not "mode" in entry or entry["mode"] != "force-https":
-               continue
        # We expect a name.
        if not "name" in entry:
                continue
-       hsts.append((entry["name"],))
+       mode = ""
+       if "mode" in entry:
+               mode = entry["mode"]
+       entries.append((entry["name"],mode))
        if not "include_subdomains" in entry or entry["include_subdomains"] != True:
                continue
-       hsts.append(("*.%s" % entry["name"],))
+       entries.append(("*.%s" % entry["name"],mode))
 
 # Make it happen
 conn = sqlite3.connect("db.sqlite3")
@@ -44,15 +45,15 @@ c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",
 match = c.fetchone()
 if not match:
        c.execute("CREATE TABLE last_generated (epoch integer);")
-       c.execute("CREATE TABLE hsts (domain text);")
-       c.execute("CREATE INDEX hsts_domain on hsts (domain);")
+       c.execute("CREATE TABLE entries (name text, mode text);")
+       c.execute("CREATE INDEX name on entries (name);")
 
 c.execute('DELETE FROM last_generated');
 c.execute('INSERT INTO last_generated VALUES(?)',
        (str(int(time.time())),))
 
-c.execute('DELETE FROM hsts');
-c.executemany('INSERT INTO hsts VALUES (?)', hsts)
+c.execute('DELETE FROM entries');
+c.executemany('INSERT INTO entries VALUES (?,?)', entries)
 
 conn.commit()
 conn.close()
git clone https://git.99rst.org/PROJECT