2018-09-30 13:42:58 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-01-07 21:43:14 +00:00
|
|
|
|
2018-01-08 22:56:08 +00:00
|
|
|
from base64 import b64decode
|
|
|
|
from hashlib import sha256
|
2018-01-07 21:43:14 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
|
2018-07-31 09:35:09 +00:00
|
|
|
REPO = "certifi/python-certifi"
|
2018-01-07 23:56:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def fetch_certdata():
|
2018-07-31 09:35:09 +00:00
|
|
|
r = requests.get("https://api.github.com/repos/%s/git/refs/heads/master" % REPO)
|
|
|
|
assert r.status_code == 200
|
|
|
|
commithash = r.json()["object"]["sha"]
|
|
|
|
|
|
|
|
r = requests.get(
|
|
|
|
"https://raw.githubusercontent.com/%s/%s/certifi/cacert.pem"
|
|
|
|
% (REPO, commithash)
|
|
|
|
)
|
|
|
|
assert r.status_code == 200
|
2018-01-07 23:56:39 +00:00
|
|
|
certdata = r.text
|
|
|
|
|
|
|
|
return commithash, certdata
|
2018-01-07 21:43:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def process_certdata(data):
|
|
|
|
certs = {}
|
2018-07-31 09:35:09 +00:00
|
|
|
lines = [x.strip() for x in data.split("\n")]
|
2018-01-07 21:43:14 +00:00
|
|
|
label = None
|
|
|
|
value = None
|
|
|
|
for line in lines:
|
2018-07-31 09:35:09 +00:00
|
|
|
if line.startswith("# Label: "):
|
|
|
|
assert label is None
|
|
|
|
assert value is None
|
2018-01-07 21:43:14 +00:00
|
|
|
label = line.split('"')[1]
|
2018-07-31 09:35:09 +00:00
|
|
|
elif line == "-----BEGIN CERTIFICATE-----":
|
|
|
|
assert label is not None
|
|
|
|
assert value is None
|
|
|
|
value = ""
|
|
|
|
elif line == "-----END CERTIFICATE-----":
|
|
|
|
assert label is not None
|
|
|
|
assert value is not None
|
2018-01-08 22:56:08 +00:00
|
|
|
certs[label] = b64decode(value)
|
|
|
|
label, value = None, None
|
|
|
|
else:
|
|
|
|
if value is not None:
|
|
|
|
value += line
|
|
|
|
|
2018-01-07 21:43:14 +00:00
|
|
|
return certs
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-01-07 23:56:39 +00:00
|
|
|
commithash, certdata = fetch_certdata()
|
|
|
|
|
2018-07-31 09:35:09 +00:00
|
|
|
print("# fetched from https://github.com/%s" % REPO)
|
|
|
|
print("# commit %s" % commithash)
|
2018-01-07 21:43:14 +00:00
|
|
|
|
2018-01-07 23:56:39 +00:00
|
|
|
certs = process_certdata(certdata)
|
|
|
|
|
|
|
|
size = sum([len(x) for x in certs.values()])
|
2018-07-31 09:35:09 +00:00
|
|
|
print(
|
|
|
|
"# certs: %d | digests size: %d | total size: %d"
|
|
|
|
% (len(certs), len(certs) * 32, size)
|
|
|
|
)
|
2018-01-07 21:43:14 +00:00
|
|
|
|
2018-07-31 09:35:09 +00:00
|
|
|
print("cert_bundle = [")
|
2018-01-07 21:43:14 +00:00
|
|
|
for k, v in certs.items():
|
2018-01-08 22:56:08 +00:00
|
|
|
h = sha256(v)
|
2018-07-31 09:35:09 +00:00
|
|
|
print(" # %s" % k)
|
|
|
|
print(" # %s" % h.hexdigest())
|
|
|
|
print(" %s," % h.digest())
|
|
|
|
print("]")
|
2018-01-07 21:43:14 +00:00
|
|
|
|
|
|
|
|
2018-07-31 09:35:09 +00:00
|
|
|
if __name__ == "__main__":
|
2018-01-07 21:43:14 +00:00
|
|
|
main()
|