You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.8 KiB
77 lines
1.8 KiB
6 years ago
|
#!/usr/bin/env python3
|
||
7 years ago
|
|
||
7 years ago
|
from base64 import b64decode
|
||
|
from hashlib import sha256
|
||
7 years ago
|
import requests
|
||
|
|
||
|
|
||
6 years ago
|
REPO = "certifi/python-certifi"
|
||
7 years ago
|
|
||
|
|
||
|
def fetch_certdata():
|
||
6 years ago
|
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
|
||
7 years ago
|
certdata = r.text
|
||
|
|
||
|
return commithash, certdata
|
||
7 years ago
|
|
||
|
|
||
|
def process_certdata(data):
|
||
|
certs = {}
|
||
6 years ago
|
lines = [x.strip() for x in data.split("\n")]
|
||
7 years ago
|
label = None
|
||
|
value = None
|
||
|
for line in lines:
|
||
6 years ago
|
if line.startswith("# Label: "):
|
||
|
assert label is None
|
||
|
assert value is None
|
||
7 years ago
|
label = line.split('"')[1]
|
||
6 years ago
|
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
|
||
7 years ago
|
certs[label] = b64decode(value)
|
||
|
label, value = None, None
|
||
|
else:
|
||
|
if value is not None:
|
||
|
value += line
|
||
|
|
||
7 years ago
|
return certs
|
||
|
|
||
|
|
||
|
def main():
|
||
7 years ago
|
commithash, certdata = fetch_certdata()
|
||
|
|
||
6 years ago
|
print("# fetched from https://github.com/%s" % REPO)
|
||
|
print("# commit %s" % commithash)
|
||
7 years ago
|
|
||
7 years ago
|
certs = process_certdata(certdata)
|
||
|
|
||
|
size = sum([len(x) for x in certs.values()])
|
||
6 years ago
|
print(
|
||
|
"# certs: %d | digests size: %d | total size: %d"
|
||
|
% (len(certs), len(certs) * 32, size)
|
||
|
)
|
||
7 years ago
|
|
||
6 years ago
|
print("cert_bundle = [")
|
||
7 years ago
|
for k, v in certs.items():
|
||
7 years ago
|
h = sha256(v)
|
||
6 years ago
|
print(" # %s" % k)
|
||
|
print(" # %s" % h.hexdigest())
|
||
|
print(" %s," % h.digest())
|
||
|
print("]")
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
if __name__ == "__main__":
|
||
7 years ago
|
main()
|