#!/usr/bin/env bash
# Fetch the inputs for the sec-ref.tools expiry study and check they are the copies the
# published figures came from. None is committed.
#  - Tranco list PY2NJ (top 100k; the study uses the top 10k), https://tranco-list.eu/
#  - Published IP ranges of the managed edges used to classify who serves a site. These
#    change; the copies used are fetched once, on the scan date, and their sha256 recorded
#    in data/edge-ranges/SHA256SUMS by this script.
set -euo pipefail
cd "$(dirname "$0")"
mkdir -p data/edge-ranges
T=data/tranco-PY2NJ.csv
[ -f "$T" ] || curl -fsSL -o "$T" "https://tranco-list.eu/download/PY2NJ/100000"
echo "7b3b5a453b5cb4124dd85a35f34c3327b94b2efd9c928961176a581b8b3bb7d5  $T" | sha256sum -c -
cd data/edge-ranges
if [ ! -f SHA256SUMS ]; then
  curl -fsSL -o cloudflare-v4.txt https://www.cloudflare.com/ips-v4
  curl -fsSL -o fastly.json https://api.fastly.com/public-ip-list
  curl -fsSL -o aws.json https://ip-ranges.amazonaws.com/ip-ranges.json
  curl -fsSL -o goog.json https://www.gstatic.com/ipranges/goog.json
  curl -fsSL -o cloud.json https://www.gstatic.com/ipranges/cloud.json
  date -u +%Y-%m-%dT%H:%M:%SZ > FETCHED
  sha256sum cloudflare-v4.txt fastly.json aws.json goog.json cloud.json FETCHED > SHA256SUMS
fi
sha256sum -c SHA256SUMS
