# .github/workflows/cert-check.yml
name: Certificate Pin Monitor
on:
  schedule:
    - cron: '0 9 * * 1'  # Every Monday at 9am UTC
  workflow_dispatch:

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Extract current cert SPKI hash
        run: |
          LIVE_HASH=$(openssl s_client \
            -connect pocketboard-api.onrender.com:443 \
            -showcerts </dev/null 2>/dev/null | \
            awk '/Certificate chain/{p=1} p' | \
            awk '/-----BEGIN CERTIFICATE-----/{c++; p=""; if(c==2)p=1} p{print}' | \
            openssl x509 -noout -pubkey | \
            openssl pkey -pubin -outform DER | \
            openssl dgst -sha256 -binary | base64)
          echo "Live hash: $LIVE_HASH"
          grep -q "$LIVE_HASH" network-security-config.xml
        # Fails (and sends alert) if hash not found in config
