-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreadable_fix.py
executable file
·48 lines (39 loc) · 1.1 KB
/
readable_fix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# This script cleans up after a bug in --readable that left some certs missing
# from the readable table :/
import dbconnect
import openssl_dump
import os
db,dbc = dbconnect.dbconnect()
db1,dbc1 = dbconnect.dbconnect()
q = """
select fingerprint,path from all_certs
where fingerprint not in (
select fingerprint from readable
)
"""
print q
dbc.execute(q)
batch = dbc.fetchmany(1000)
while batch:
fds = []
for fprt, path in batch:
# Let the IO subsystem figure out an efficient way to suck all these certs
# into RAM
f = os.open(path, os.O_NONBLOCK)
fds.append(f)
os.read(f,2048)
q = []
for fprt,path in batch:
print path
pem_certs, output_texts, fingerprints = openssl_dump.toOpensslText(path)
try:
n = fingerprints.index(fprt)
q.append('("%s", "%s")' % (db1.escape_string(fprt), db1.escape_string(output_texts[n])))
except ValueError:
print "Fingerprint", fprt, "is not in"
print fingerprints
q = 'INSERT INTO readable VALUES ' + ', '.join(q)
dbc1.execute(q)
for fd in fds: os.close(fd)
batch = dbc.fetchmany(1000)