|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +bootstrap_cert_hostname="cloudflareresearch.com" |
| 6 | +landmark_interval_secs=`jq '.logs.dev2.landmark_interval_secs' config.dev.json` |
| 7 | +submission_url=`jq -r '.logs.dev2.submission_url' config.dev.json` |
| 8 | + |
| 9 | +# Get a bootstrap certificate chain. |
| 10 | +bootstrap_cert_chain=`mktemp` |
| 11 | +echo | openssl s_client \ |
| 12 | + -connect ${bootstrap_cert_hostname}:443 \ |
| 13 | + -servername ${bootstrap_cert_hostname} \ |
| 14 | + -showcerts 2>/dev/null |\ |
| 15 | + sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' \ |
| 16 | + > ${bootstrap_cert_chain} |
| 17 | + |
| 18 | +spki_der=`openssl x509 -in ${bootstrap_cert_chain} -pubkey -noout |\ |
| 19 | + openssl pkey -pubin -inform pem -outform der | base64` |
| 20 | + |
| 21 | +add_entry_req=`cat ${bootstrap_cert_chain} |\ |
| 22 | + while (set -o pipefail; |
| 23 | + openssl x509 -outform DER 2>/dev/null |\ |
| 24 | + base64); do :; done |\ |
| 25 | + sed '/^$/d' | sed 's/.*/"&"/' | jq -sc '{"chain":.}'` |
| 26 | + |
| 27 | +# Add entry for the bootstrap certificate. |
| 28 | +add_entry_resp=`curl -f --no-progress-meter -X POST \ |
| 29 | + -H "Content-Type: application/json" \ |
| 30 | + -d ${add_entry_req} \ |
| 31 | + "${submission_url}add-entry"` |
| 32 | + |
| 33 | +leaf_index=`echo ${add_entry_resp} | jq '.leaf_index'` |
| 34 | +echo "Leaf index: ${leaf_index}" |
| 35 | + |
| 36 | +# Wait for the next landmark to be minted. |
| 37 | +echo "Waiting ${landmark_interval_secs}s for the next landmark" |
| 38 | +sleep ${landmark_interval_secs} |
| 39 | + |
| 40 | +get_cert_req="{\"leaf_index\":${leaf_index},\"spki_der\":\"${spki_der}\"}" |
| 41 | + |
| 42 | +# Fetch the completed MTC. |
| 43 | +get_cert_resp=`curl -f --no-progress-meter -X POST \ |
| 44 | + -H "Content-Type: application/json" \ |
| 45 | + -d ${get_cert_req} \ |
| 46 | + "${submission_url}get-certificate"` |
| 47 | + |
| 48 | +landmark_id=`echo ${get_cert_resp} | jq '.landmark_id'` |
| 49 | +echo "Landmark id: ${landmark_id}" |
| 50 | + |
| 51 | +echo ${get_cert_resp} | jq -r '.data' | base64 -d |\ |
| 52 | + openssl x509 -inform DER -outform PEM |
0 commit comments