Skip to content

Commit 36e49fc

Browse files
committed
mtc_worker: Add instructions for local dev
1 parent 95b2ef7 commit 36e49fc

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

crates/mtc_worker/README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
# Merkle Tree CA Worker
22

3-
A Rust implementation of a [Merkle Tree CA][] for deployment on [Cloudflare Workers](https://workers.cloudflare.com/).
3+
A Rust implementation of a [Merkle Tree CA](https://github.com/davidben/merkle-tree-certs/) (MTCA) for deployment on [Cloudflare Workers](https://workers.cloudflare.com/).
4+
5+
Much of the API and the internal architecture of the Merkle Tree CA is shared by the [Static CT Log](../ct_worker/README.md). This Worker also implements issuance of Merkle Tree Certificates (MTCs). The issuance API should be considered unstable. For now, its primary purpose is to support an experimental deployment of the MTC specification.
6+
7+
## Development
8+
9+
`node` and `npm` are required to run the Worker locally. First, use `npm` to install `wrangler`:
10+
11+
```bash
12+
npm install -g wrangler@latest
13+
```
14+
15+
Then use `wrangler` to run the Worker locally from this directory:
16+
17+
```bash
18+
npx wrangler dev -e=dev
19+
```
20+
21+
The Worker doesn't implement a full-blown MTCA. Instead, it implements what we call a **bootstrap MTCA**. For every MTC requested, the requester must provide a **bootstrap certificate**. A bootstrap certificate is a standard X.509 certificate chain that must have a path to a root certificate trusted by `mtc_worker`. By default, the root store for is the intersection of Chrome's and Mozilla's trust stores.
22+
23+
To test the basic functionality, run the following script from this directory:
24+
25+
```bash
26+
./test-dev.sh
27+
```
28+
29+
This script does the following:
30+
31+
1. Fetch a bootstrap certificate chain
32+
33+
1. Submit the bootstrap certificate chain to the MTCA running locally
34+
35+
1. Wait for the next landmark to be minted
36+
37+
1. Request the signatureless MTC from the MTCA running locally
38+
39+
### Overriding the trust store
40+
41+
It may be useful to provide your own roots for testing. To do so:
42+
43+
1. Build the Worker with the `"dev-bootstrap-roots"` feature. Note that `wrangler` invokes `cargo` with a custom build script, so the simplest thing to do is to edit the `Cargo.toml` file by adding `"dev-boostrap-roots"` to the default feature set.
44+
45+
1. Append your roots to [`dev-bootstrap-roots.pem`](./dev-bootstrap-roots.pem).
46+
47+
## Deployment
48+
49+
See the [`ct_worker` documentation](../ct_worker/README.md#deployment-to-a-custom-domain) for deployment to a custom domain.
450

551
## License
652

crates/mtc_worker/test-dev.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
add_entry_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 ${add_entry_resp} | jq '.landmark_id'`
49+
echo "Landmark id: ${landmark_id}"
50+
51+
echo ${add_entry_resp} | jq -r '.data' | base64 -d |\
52+
openssl x509 -inform DER -outform PEM

0 commit comments

Comments
 (0)