Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update url for wosign log #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 67 additions & 51 deletions submit-cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,86 @@
import requests

try:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except:
pass
pass

LOGS = {
'pilot' : 'https://ct.googleapis.com/pilot',
'aviator' : 'https://ct.googleapis.com/aviator',
'rocketeer' : 'https://ct.googleapis.com/rocketeer',
'icarus' : 'https://ct.googleapis.com/icarus',
'skydiver' : 'https://ct.googleapis.com/skydiver',
# 'certly Log Server' : 'https://log.certly.io',
'symantec' : 'https://ct.ws.symantec.com',
'digicert' : 'https://ct1.digicert-ct.com/log',
#'Google \'Submariner\' log' : 'https://ct.googleapis.com/submariner',
# 'Izenpe Log Server' :'https://ct.izenpe.com',
'venafi' : 'https://ctlog.api.venafi.com',
'vega' : 'https://vega.ws.symantec.com',
'cnnic' : 'https://ctserver.cnnic.cn',
'startssl' : 'https://ct.startssl.com',
#'GDCA CT Log Server' : 'https://ct.gdca.com.cn',
'wosign' : 'https://ct.wosign.com',
#'Akamai Log' : 'https://ct.akamai.com',
'certificatetransparency.cn' : 'https://www.certificatetransparency.cn/ct',
'venafigen2' : 'http://ctlog-gen2.api.venafi.com',
'pilot' : 'https://ct.googleapis.com/pilot',
'aviator' : 'https://ct.googleapis.com/aviator',
'rocketeer' : 'https://ct.googleapis.com/rocketeer',
'icarus' : 'https://ct.googleapis.com/icarus',
'skydiver' : 'https://ct.googleapis.com/skydiver',
# 'certly Log Server' : 'https://log.certly.io',
'symantec' : 'https://ct.ws.symantec.com',
'digicert' : 'https://ct1.digicert-ct.com/log',
#'Google \'Submariner\' log' : 'https://ct.googleapis.com/submariner',
# 'Izenpe Log Server' :'https://ct.izenpe.com',
'venafi' : 'https://ctlog.api.venafi.com',
'vega' : 'https://vega.ws.symantec.com',
'cnnic' : 'https://ctserver.cnnic.cn',
'startssl' : 'https://ct.startssl.com',
#'GDCA CT Log Server' : 'https://ct.gdca.com.cn',
'wosign' : 'https://ctlog.wosign.com',
#'Akamai Log' : 'https://ct.akamai.com',
'certificatetransparency.cn' : 'https://www.certificatetransparency.cn/ct',
'venafigen2' : 'http://ctlog-gen2.api.venafi.com',
}

logs_json = requests.get("https://www.gstatic.com/ct/log_list/log_list.json")
logs = {}

try:
logs_aux = logs_json.json().get("logs")

for l in logs_aux:
logs.update({l.get("description"): "https://" + l.get("url")})
print "https://" + l.get("url")
except ValueError:
print "Error at logs list updating, using default list instead."
logs = LOGS



parser = argparse.ArgumentParser(description='Submit a certificate to logs')
parser.add_argument("--cert", type=argparse.FileType('r'), action="append", required=True,
help="Certificate chain. Specify multiple times, start with the leaf, continuing to the root.")
parser.add_argument("--cert", type=argparse.FileType('r'), action="append", required=True,
help="Certificate chain. Specify multiple times, start with the leaf, continuing to the root.")
parser.add_argument("--log", action='append', type=str,
help="logs to submit the cert to. Specify multiple times for explicit choice, or leave blank for all.")
help="logs to submit the cert to. Specify multiple times for explicit choice, or leave blank for all.")

args = parser.parse_args()

certdata = []
num_certs = 0
for c in args.cert:
lines = ''.join(c.readlines())
if lines.count('-----BEGIN CERTIFICATE-----') > 1:
print "Error: Specify one certificate per file, with multiple --cert arguments, in the order of leaf, intermediate, root"
sys.exit(-1)
lines = lines.replace("-----BEGIN CERTIFICATE-----", "")
lines = lines.replace("-----END CERTIFICATE-----", "")
lines = lines.replace("\r", "")
lines = lines.replace("\n", "")
certdata.append(lines)
lines = ''.join(c.readlines())
if lines.count('-----BEGIN CERTIFICATE-----') > 1:
print "Error: Specify one certificate per file, with multiple --cert arguments, in the order of leaf, intermediate, root"
sys.exit(-1)
lines = lines.replace("-----BEGIN CERTIFICATE-----", "")
lines = lines.replace("-----END CERTIFICATE-----", "")
lines = lines.replace("\r", "")
lines = lines.replace("\n", "")
certdata.append(lines)



data = '{"chain" : ["' + '", "'.join(certdata) + '"]}'

for l in LOGS:
if not args.log or [x for x in args.log if x in l.lower()]:
try:
r = requests.post(LOGS[l] + "/ct/v1/add-chain", data=data, verify=False, timeout=2)
if r.status_code != 200:
print("Error {0} while submitting to {1}".format(r.status_code, l))
print(r.text)
else:
r = json.loads(r.text)
print(l)
print("\tTimestamp", r['timestamp'])
print("\tSignature", r['signature'])
print("\tCommand: ./write-sct.py --stdout --time " + str(r['timestamp']) + " --sig " + str(r['signature']) + " --log " + l)
except Exception as e:
print("Error communicating with", l)
print(e)
for l in logs:
if not args.log or [x for x in args.log if x in l.lower()]:
try:
r = requests.post(logs[l] + "ct/v1/add-chain", data=data, verify=False, timeout=2)
#r = requests.post(logs[l] + "ct/v2/submit-entry", data=data, verify=False, timeout=2)
if r.status_code != 200:
print("Error {0} while submitting to {1}".format(r.status_code, l))
print(r.text)
else:
r = json.loads(r.text)
print(l)
print("\tTimestamp", r['timestamp'])
print("\tSignature", r['signature'])
print("\tCommand: ./write-sct.py --stdout --time " + str(r['timestamp']) + " --sig " + str(r['signature']) + " --log " + l)
except Exception as e:
print("Error communicating with", l)
print(e)