mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
hanzoskills.com/llms.txt now opens with the install line, the API reference index and the company index, so an agent that lands on any one of the three can find the rest. robots.txt claimed 537 documents while llms.txt counts 920. The number is gone from robots.txt; llms.txt derives it. public/ is regenerated from scripts/site.py, which it had fallen behind: the copy-prompt menu and agent bar were in the generator and not in the committed pages. tests/site.mjs passes against the result. Co-authored-by: Hanzo Dev <[email protected]>
690 lines
35 KiB
HTML
690 lines
35 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>cryptography-certificate-management</title>
|
|
<meta name="color-scheme" content="dark">
|
|
<style>
|
|
/* Committed to one visual world: a dark instrument panel. No light variant —
|
|
the dot field and the hairline rules only read on black, and a naive
|
|
inversion would wash both out. Every colour is painted explicitly so the page
|
|
never borrows a host background. */
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
|
|
|
:root{
|
|
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
|
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
|
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
|
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
|
--mono:var(--font-zen-mono);
|
|
--sans:var(--font-zen-sans);
|
|
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
|
--r:999px; --r-soft:14px;
|
|
}
|
|
*{box-sizing:border-box}
|
|
html{-webkit-text-size-adjust:100%}
|
|
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
|
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
|
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
|
|
|
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
|
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
|
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
|
would cut off the copy-prompt menu. */
|
|
.hero{position:relative;border-bottom:1px solid var(--line)}
|
|
.hero::before{content:"";position:absolute;inset:0;
|
|
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
|
background-size:7px 7px;
|
|
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
pointer-events:none}
|
|
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
|
|
|
nav{border-bottom:1px solid var(--line)}
|
|
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
|
justify-content:space-between;align-items:center;gap:1rem}
|
|
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
|
display:inline-flex;align-items:center;gap:.6rem}
|
|
.brand i{font-style:normal;color:var(--faint)}
|
|
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
|
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
|
nav a.up:hover{color:var(--ink)}
|
|
|
|
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
|
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
|
h1 em{font-style:normal;color:var(--faint)}
|
|
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
|
|
|
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
|
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
|
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
|
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
|
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
|
line-height:1.2;font-weight:400}
|
|
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
|
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
|
.btn.solid:hover{background:#d8d8d4}
|
|
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
|
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
|
|
|
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
|
.copy{position:relative;display:inline-flex}
|
|
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
|
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
|
padding:.4rem;display:flex;flex-direction:column;
|
|
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
|
.menu[hidden]{display:none}
|
|
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
|
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
|
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
|
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
|
white-space:nowrap}
|
|
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
|
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
|
.mi:hover .mark{color:var(--ink)}
|
|
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
|
letter-spacing:.1em;text-transform:uppercase}
|
|
|
|
/* Works-with bar: one scrolling row, name and mark per agent. */
|
|
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
|
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
|
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
|
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
|
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
|
display:flex;align-items:center}
|
|
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
|
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
|
-webkit-overflow-scrolling:touch;
|
|
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
|
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
|
.bar::-webkit-scrollbar{display:none}
|
|
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
|
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
|
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
|
text-decoration:none;background:var(--ground)}
|
|
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
|
.agent .mark{width:.95rem;height:.95rem}
|
|
|
|
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
|
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
|
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
|
p{margin:0 0 1rem;max-width:70ch}
|
|
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
|
li{margin:.22rem 0}
|
|
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
|
text-decoration-color:var(--line-hi)}
|
|
a:hover{text-decoration-color:var(--ink)}
|
|
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
|
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
|
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
|
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
|
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
|
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
|
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
|
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
|
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
|
display:block;overflow-x:auto}
|
|
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
|
|
|
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
|
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
|
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
|
white-space:pre;line-height:1.9}
|
|
.curl b{color:var(--ink);font-weight:400}
|
|
.curl i{font-style:normal;color:var(--faint)}
|
|
|
|
/* index */
|
|
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
|
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
|
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
|
#q:focus{outline:none;border-color:var(--soft)}
|
|
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
|
text-transform:uppercase;margin:0 0 2rem}
|
|
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
|
padding-bottom:.45rem}
|
|
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
|
border-radius:var(--r-soft);text-decoration:none}
|
|
.row:hover{background:#0a0a0a}
|
|
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
|
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
|
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
|
color:var(--faint);font-size:.85rem}
|
|
footer a{color:var(--soft)}
|
|
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
|
margin:0 0 2rem;font-size:.85rem}
|
|
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
|
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
|
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
|
.fmap a:hover{text-decoration:underline}
|
|
.fmap div{color:var(--faint);line-height:1.5}
|
|
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
|
|
|
@media (max-width:640px){
|
|
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
|
.btns{gap:.5rem}
|
|
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
|
.copy,.copy .btn{width:100%;justify-content:center}
|
|
.menu{left:0;right:0;min-width:0}
|
|
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
|
.strip b{border-right:0;padding-right:0}
|
|
.bar{width:100%}
|
|
}
|
|
</style>
|
|
<link rel="alternate" type="text/markdown" href="/cryptography-certificate-management.md">
|
|
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/cryptography-certificate-management">
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/cryptography-certificate-management.md
|
|
Index: https://hanzoskills.com/llms.txt
|
|
Corpus: https://hanzoskills.com/all.md
|
|
Append .md to any path for the markdown twin. -->
|
|
<body>
|
|
<nav><div class="in">
|
|
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
|
<a class="up" href="/">All skills</a>
|
|
</div></nav>
|
|
|
|
<div class="wrap">
|
|
<h1>cryptography-certificate-management</h1><p class="lede">Certificate lifecycle management including rotation, renewal, monitoring, automation with Let's Encrypt and ACME</p><h1>Certificate Management</h1>
|
|
<p><strong>Scope</strong>: Certificate rotation, renewal, monitoring, Let's Encrypt, ACME protocol, automation <strong>Lines</strong>: ~350 <strong>Last Updated</strong>: 2025-10-27 <strong>Format Version</strong>: 1.0 (Atomic)</p>
|
|
<hr>
|
|
<h2>When to Use This Skill</h2>
|
|
<p>Activate this skill when:</p>
|
|
<ul><li>Managing certificate expiration</li><li>Automating certificate renewal</li><li>Implementing Let's Encrypt</li><li>Monitoring certificate health</li><li>Rotating certificates</li><li>Setting up ACME clients</li><li>Handling certificate revocation</li><li>Planning certificate infrastructure</li></ul>
|
|
<h2>Certificate Lifecycle</h2>
|
|
<pre><code>1. Generation → Create private key and CSR
|
|
2. Issuance → CA signs certificate
|
|
3. Deployment → Install on servers
|
|
4. Monitoring → Track expiration
|
|
5. Renewal → Get new certificate before expiry
|
|
6. Rotation → Replace old with new
|
|
7. Revocation → Invalidate if compromised (optional)</code></pre>
|
|
<hr>
|
|
<h2>Let's Encrypt & ACME</h2>
|
|
<h3>Overview</h3>
|
|
<p><strong>Let's Encrypt</strong>:</p>
|
|
<ul><li>Free, automated certificate authority</li><li>90-day certificate lifetime</li><li>ACME protocol for automation</li><li>Rate limits apply</li></ul>
|
|
<p><strong>ACME Protocol</strong>:</p>
|
|
<pre><code>1. Account creation
|
|
2. Domain validation (HTTP-01, DNS-01, TLS-ALPN-01)
|
|
3. Certificate request
|
|
4. Certificate issuance
|
|
5. Certificate renewal</code></pre>
|
|
<h3>Certbot</h3>
|
|
<p><strong>Installation</strong>:</p>
|
|
<pre><code class="lang-bash"># Ubuntu/Debian
|
|
sudo apt install certbot python3-certbot-nginx
|
|
|
|
# macOS
|
|
brew install certbot</code></pre>
|
|
<p><strong>HTTP-01 Challenge</strong> (webroot):</p>
|
|
<pre><code class="lang-bash"># Obtain certificate
|
|
sudo certbot certonly --webroot \
|
|
-w /var/www/html \
|
|
-d example.com \
|
|
-d www.example.com
|
|
|
|
# Certificates stored in:
|
|
# /etc/letsencrypt/live/example.com/fullchain.pem
|
|
# /etc/letsencrypt/live/example.com/privkey.pem</code></pre>
|
|
<p><strong>Nginx plugin</strong> (automatic):</p>
|
|
<pre><code class="lang-bash"># Obtain and install certificate
|
|
sudo certbot --nginx -d example.com -d www.example.com
|
|
|
|
# Certbot automatically:
|
|
# - Validates domain
|
|
# - Obtains certificate
|
|
# - Updates nginx config
|
|
# - Reloads nginx</code></pre>
|
|
<p><strong>DNS-01 Challenge</strong> (wildcards):</p>
|
|
<pre><code class="lang-bash"># For wildcard certificates
|
|
sudo certbot certonly --manual \
|
|
--preferred-challenges dns \
|
|
-d '*.example.com' \
|
|
-d example.com
|
|
|
|
# Add TXT record to DNS:
|
|
# _acme-challenge.example.com → [provided value]</code></pre>
|
|
<p><strong>Auto-renewal</strong>:</p>
|
|
<pre><code class="lang-bash"># Test renewal
|
|
sudo certbot renew --dry-run
|
|
|
|
# Setup cron (or systemd timer)
|
|
0 0,12 * * * certbot renew --quiet --post-hook "systemctl reload nginx"</code></pre>
|
|
<h3>acme.sh</h3>
|
|
<p><strong>Alternative ACME client</strong>:</p>
|
|
<pre><code class="lang-bash"># Install
|
|
⚠️ **SECURITY**: Piping curl to shell is dangerous. For production:</code></pre>
|
|
<h1>Download script first</h1>
|
|
<p>curl -O https://get.acme.sh</p>
|
|
<h1>Verify checksum</h1>
|
|
<p>sha256sum get.acme.sh</p>
|
|
<h1>Review content</h1>
|
|
<p>less get.acme.sh</p>
|
|
<h1>Then execute</h1>
|
|
<p>bash get.acme.sh</p>
|
|
<pre><code>For development/learning only:</code></pre>
|
|
<p>curl https://get.acme.sh | sh</p>
|
|
<h1>Issue certificate (HTTP validation)</h1>
|
|
<p>acme.sh --issue -d example.com -w /var/www/html</p>
|
|
<h1>Issue wildcard (DNS validation with Cloudflare)</h1>
|
|
<p>export CF_Token="your-cloudflare-api-token" # Placeholder - replace with actual API token from Cloudflare dashboard acme.sh --issue --dns dns_cf -d example.com -d '*.example.com'</p>
|
|
<h1>Install certificate</h1>
|
|
<p>acme.sh --install-cert -d example.com \ --key-file /etc/ssl/private/example.com.key \ --fullchain-file /etc/ssl/certs/example.com.crt \ --reloadcmd "systemctl reload nginx"</p>
|
|
<h1>Auto-renewal (automatic after install)</h1>
|
|
<p>acme.sh --cron</p>
|
|
<pre><code>
|
|
---
|
|
|
|
## Automation Patterns
|
|
|
|
### Pattern 1: Systemd Timer for Renewal
|
|
|
|
**Service file** (`/etc/systemd/system/certbot-renew.service`):</code></pre>
|
|
<p>[Unit] Description=Certbot Renewal</p>
|
|
<p>[Service] Type=oneshot ExecStart=/usr/bin/certbot renew --quiet --deploy-hook "systemctl reload nginx"</p>
|
|
<pre><code>
|
|
**Timer file** (`/etc/systemd/system/certbot-renew.timer`):</code></pre>
|
|
<p>[Unit] Description=Certbot Renewal Timer</p>
|
|
<p>[Timer] OnCalendar=daily RandomizedDelaySec=1h Persistent=true</p>
|
|
<p>[Install] WantedBy=timers.target</p>
|
|
<pre><code>
|
|
**Enable**:</code></pre>
|
|
<p>sudo systemctl enable --now certbot-renew.timer sudo systemctl list-timers certbot-renew.timer</p>
|
|
<pre><code>
|
|
### Pattern 2: Kubernetes cert-manager
|
|
|
|
**Install cert-manager**:</code></pre>
|
|
<p>kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml</p>
|
|
<pre><code>
|
|
**ClusterIssuer** (Let's Encrypt):</code></pre>
|
|
<p>apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata: name: letsencrypt-prod spec: acme: server: https://acme-v02.api.letsencrypt.org/directory email: [email protected] privateKeySecretRef: name: letsencrypt-prod solvers:</p>
|
|
<ul><li>http01:</li></ul>
|
|
<p> ingress: class: nginx</p>
|
|
<pre><code>
|
|
**Certificate resource**:</code></pre>
|
|
<p>apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: example-com-tls namespace: default spec: secretName: example-com-tls issuerRef: name: letsencrypt-prod kind: ClusterIssuer dnsNames:</p>
|
|
<ul><li>example.com</li><li>www.example.com</li></ul>
|
|
<pre><code>
|
|
**Ingress annotation** (automatic):</code></pre>
|
|
<p>apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example annotations: cert-manager.io/cluster-issuer: "letsencrypt-prod" spec: tls:</p>
|
|
<ul><li>hosts:</li><li>example.com</li></ul>
|
|
<p> secretName: example-com-tls rules:</p>
|
|
<ul><li>host: example.com</li></ul>
|
|
<p> http: paths:</p>
|
|
<ul><li>path: /</li></ul>
|
|
<p> pathType: Prefix backend: service: name: example port: number: 80</p>
|
|
<pre><code>
|
|
### Pattern 3: Custom Automation Script
|
|
|
|
**Python renewal script**:</code></pre>
|
|
<p>#!/usr/bin/env python3 import subprocess import ssl import socket from datetime import datetime, timedelta import smtplib from email.message import EmailMessage</p>
|
|
<p>def check_certificate_expiry(hostname, port=443): """Check days until certificate expires""" context = ssl.create_default_context() with socket.create_connection((hostname, port)) as sock: with context.wrap_socket(sock, server_hostname=hostname) as ssock: cert = ssock.getpeercert() not_after = datetime.strptime(cert['notAfter'], '%b %d %H:%M:%S %Y %Z') days_remaining = (not_after - datetime.now()).days return days_remaining</p>
|
|
<p>def renew_certificate(domain): """Renew certificate using certbot""" result = subprocess.run( ['certbot', 'renew', '--cert-name', domain, '--quiet'], capture_output=True, text=True ) return result.returncode == 0</p>
|
|
<p>def send_alert(subject, body): """Send email alert""" msg = EmailMessage() msg['Subject'] = subject msg['From'] = '[email protected]' msg['To'] = '[email protected]' msg.set_content(body)</p>
|
|
<p> with smtplib.SMTP('localhost') as s: s.send_message(msg)</p>
|
|
<p>def main(): domains = ['example.com', 'api.example.com']</p>
|
|
<p> for domain in domains: try: days = check_certificate_expiry(domain) print(f"{domain}: {days} days until expiry")</p>
|
|
<p> # Renew if < 30 days remaining if days < 30: print(f"Renewing {domain}...") if renew_certificate(domain): send_alert( f"Certificate renewed: {domain}", f"Successfully renewed certificate for {domain}" ) else: send_alert( f"Certificate renewal FAILED: {domain}", f"Failed to renew certificate for {domain}" )</p>
|
|
<p> # Alert if < 14 days and renewal failed elif days < 14: send_alert( f"Certificate expiring soon: {domain}", f"Certificate for {domain} expires in {days} days" )</p>
|
|
<p> except Exception as e: send_alert( f"Certificate check failed: {domain}", f"Error checking {domain}: {str(e)}" )</p>
|
|
<p>if __name__ == '__main__': main()</p>
|
|
<pre><code>
|
|
---
|
|
|
|
## Monitoring
|
|
|
|
### Check Expiration
|
|
|
|
**OpenSSL**:</code></pre>
|
|
<h1>Check expiration date</h1>
|
|
<p>echo | openssl s_client -connect example.com:443 2>/dev/null | \ openssl x509 -noout -dates</p>
|
|
<h1>Days until expiry</h1>
|
|
<p>echo | openssl s_client -connect example.com:443 2>/dev/null | \ openssl x509 -noout -enddate | \ awk -F= '{print $2}' | xargs -I {} date -d {} +%s | \ awk -v now=$(date +%s) '{print int(($1-now)/86400)}'</p>
|
|
<pre><code>
|
|
**Prometheus Exporter**:</code></pre>
|
|
<h1>ssl_exporter</h1>
|
|
<p>apiVersion: v1 kind: Service metadata: name: ssl-exporter spec: ports:</p>
|
|
<ul><li>port: 9219</li></ul>
|
|
<p> selector: app: ssl-exporter --- apiVersion: apps/v1 kind: Deployment metadata: name: ssl-exporter spec: template: spec: containers:</p>
|
|
<ul><li>name: ssl-exporter</li></ul>
|
|
<p> image: ribbybibby/ssl-exporter:latest args:</p>
|
|
<ul><li>--config.file=/config/ssl-exporter.yaml</li></ul>
|
|
<pre><code>
|
|
**Prometheus alert**:</code></pre>
|
|
<p>groups:</p>
|
|
<ul><li>name: certificates</li></ul>
|
|
<p> rules:</p>
|
|
<ul><li>alert: CertificateExpiringSoon</li></ul>
|
|
<p> expr: ssl_cert_not_after - time() < 86400 * 30 labels: severity: warning annotations: summary: "Certificate expiring in < 30 days" description: "Certificate for {{ $labels.instance }} expires in {{ $value | humanizeDuration }}"</p>
|
|
<pre><code>
|
|
### Monitoring Services
|
|
|
|
**SSL Labs API**:</code></pre>
|
|
<p>import requests import time</p>
|
|
<p>def check_ssl_labs(domain): """Check SSL configuration with SSL Labs""" api_url = "https://api.ssllabs.com/api/v3/analyze"</p>
|
|
<p> # Start scan requests.get(api_url, params={'host': domain, 'startNew': 'on'})</p>
|
|
<p> # Poll for results while True: resp = requests.get(api_url, params={'host': domain}).json() if resp['status'] == 'READY': grade = resp['endpoints'][0]['grade'] return grade time.sleep(30)</p>
|
|
<p>grade = check_ssl_labs('example.com') print(f"SSL Labs grade: {grade}")</p>
|
|
<pre><code>
|
|
---
|
|
|
|
## Certificate Rotation
|
|
|
|
### Zero-Downtime Rotation
|
|
|
|
**Strategy**:</code></pre>
|
|
<ol><li>Obtain new certificate</li><li>Deploy new certificate alongside old</li><li>Update configuration to use new</li><li>Reload/restart services</li><li>Verify new certificate active</li><li>Remove old certificate</li></ol>
|
|
<pre><code>
|
|
**Nginx example**:</code></pre>
|
|
<h1>1. Obtain new certificate</h1>
|
|
<p>certbot certonly --webroot -w /var/www/html -d example.com</p>
|
|
<h1>2. Test configuration</h1>
|
|
<p>nginx -t</p>
|
|
<h1>3. Reload nginx (no downtime)</h1>
|
|
<p>systemctl reload nginx</p>
|
|
<h1>4. Verify</h1>
|
|
<p>echo | openssl s_client -connect example.com:443 2>/dev/null | \ openssl x509 -noout -dates</p>
|
|
<pre><code>
|
|
### Multi-Server Rotation
|
|
|
|
**Ansible playbook**:</code></pre>
|
|
<hr>
|
|
<ul><li>name: Rotate certificates</li></ul>
|
|
<p> hosts: webservers tasks:</p>
|
|
<ul><li>name: Copy new certificate</li></ul>
|
|
<p> copy: src: "{{ item }}" dest: "/etc/ssl/certs/" mode: 0644 loop:</p>
|
|
<ul><li>example.com.crt</li><li>example.com-chain.crt</li></ul>
|
|
<ul><li>name: Copy private key</li></ul>
|
|
<p> copy: src: example.com.key dest: /etc/ssl/private/ mode: 0600</p>
|
|
<ul><li>name: Reload nginx</li></ul>
|
|
<p> systemd: name: nginx state: reloaded</p>
|
|
<ul><li>name: Verify certificate</li></ul>
|
|
<p> shell: | echo | openssl s_client -connect localhost:443 2>/dev/null | \ openssl x509 -noout -dates register: cert_check changed_when: false</p>
|
|
<ul><li>name: Display certificate info</li></ul>
|
|
<p> debug: var: cert_check.stdout</p>
|
|
<pre><code>
|
|
---
|
|
|
|
## Best Practices
|
|
|
|
### 1. Renewal Window
|
|
</code></pre>
|
|
<h1>✅ Good: Renew 30 days before expiry</h1>
|
|
<p>if [ $days_remaining -lt 30 ]; then renew_certificate fi</p>
|
|
<h1>❌ Bad: Wait until last minute</h1>
|
|
<p>if [ $days_remaining -lt 3 ]; then renew_certificate fi</p>
|
|
<pre><code>
|
|
### 2. Monitoring
|
|
</code></pre>
|
|
<h1>✅ Good: Multiple monitoring approaches</h1>
|
|
<ul><li>Prometheus metrics</li><li>Periodic checks</li><li>Alert 30 days before expiry</li></ul>
|
|
<h1>❌ Bad: No monitoring</h1>
|
|
<h1>(certificate expires, site goes down)</h1>
|
|
<pre><code>
|
|
### 3. Backup Certificates
|
|
</code></pre>
|
|
<h1>✅ Good: Backup before rotation</h1>
|
|
<p>cp /etc/ssl/certs/example.com.crt /backup/ certbot renew</p>
|
|
<h1>❌ Bad: No backup</h1>
|
|
<p>certbot renew</p>
|
|
<h1>(if renewal fails, no fallback)</h1>
|
|
<pre><code>
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Issue 1: Rate Limits
|
|
|
|
**Let's Encrypt limits**:</code></pre>
|
|
<ul><li>50 certificates per domain per week</li><li>5 duplicate certificates per week</li><li>300 new orders per account per 3 hours</li></ul>
|
|
<pre><code>
|
|
**Solution**: Use staging environment for testing</code></pre>
|
|
<p>certbot --staging -d example.com</p>
|
|
<pre><code>
|
|
### Issue 2: Renewal Failure
|
|
|
|
**Check renewal status**:</code></pre>
|
|
<p>certbot certificates</p>
|
|
<pre><code>
|
|
**Common issues**:
|
|
- Webroot path wrong
|
|
- DNS not propagated (DNS-01)
|
|
- Firewall blocking (HTTP-01)
|
|
- Rate limit exceeded
|
|
|
|
**Debug**:</code></pre>
|
|
<p>certbot renew --dry-run --debug</p>
|
|
<pre><code>
|
|
---
|
|
|
|
## Related Skills
|
|
|
|
- `cryptography-pki-fundamentals` - Certificate basics
|
|
- `cryptography-tls-configuration` - TLS setup
|
|
- `infrastructure-automation` - Deployment automation
|
|
- `observability-metrics-monitoring` - Monitoring setup
|
|
|
|
---
|
|
|
|
## Level 3: Resources
|
|
|
|
**Location**: `~/.hanzo/skills/cryptography/certificate-management/resources/`
|
|
|
|
This skill includes comprehensive Level 3 resources for production certificate management implementations:
|
|
|
|
### REFERENCE.md (~3,100 lines)
|
|
|
|
Comprehensive technical reference covering:
|
|
- **Fundamentals**: Digital certificates, X.509 standard, trust chains, PKI concepts
|
|
- **Certificate Components**: Subject, SANs, extensions, key usage, certificate formats (PEM, DER, PKCS#12)
|
|
- **Certificate Lifecycle**: Generation, CSR creation, issuance, deployment, monitoring, renewal, rotation, revocation
|
|
- **CA Hierarchies**: Root/intermediate CAs, public vs private CAs, trust models
|
|
- **ACME Protocol**: Challenge types (HTTP-01, DNS-01, TLS-ALPN-01), ACME flow, client implementations
|
|
- **Let's Encrypt**: Rate limits, staging environment, trust chain, wildcard certificates
|
|
- **Certificate Automation**: Certbot usage, acme.sh, renewal hooks, systemd timers
|
|
- **Kubernetes cert-manager**: Installation, issuers, certificate resources, ingress annotations
|
|
- **Mutual TLS (mTLS)**: Server/client configuration, service mesh integration, zero-trust patterns
|
|
- **Certificate Revocation**: CRL, OCSP, OCSP stapling, must-staple extension
|
|
- **Certificate Transparency**: CT logs, monitoring, unauthorized certificate detection
|
|
- **Certificate Pinning**: Public key pinning, HPKP (deprecated), mobile implementations
|
|
- **Monitoring**: Prometheus exporters, expiration tracking, alerting strategies
|
|
- **Best Practices**: Lifetime management, key protection, automation, testing, backup/recovery
|
|
- **Common Issues**: Troubleshooting expired certs, chain issues, key mismatches, SAN errors
|
|
- **Security**: Private key protection, validation requirements, weak cryptography avoidance
|
|
- **Compliance**: PCI-DSS, HIPAA, SOC2, GDPR certificate requirements
|
|
- **Tools**: OpenSSL, certbot, acme.sh, step CLI, cfssl, cert-manager, SSL Labs, testssl.sh
|
|
|
|
### Scripts (3 production-ready tools)
|
|
|
|
**validate_certificates.py** (580+ lines) - Comprehensive certificate validation
|
|
- Validates certificates from remote hosts or local files
|
|
- Checks expiration dates with configurable thresholds
|
|
- Detects weak algorithms (MD5, SHA-1, weak RSA keys)
|
|
- Validates certificate chains and hostname matching
|
|
- SAN validation including wildcard matching
|
|
- OCSP/CRL revocation checking support
|
|
- Compliance validation (PCI-DSS, HIPAA, SOC2)
|
|
- Batch validation from hosts file
|
|
- JSON output for CI/CD integration
|
|
- Detailed reporting with severity levels
|
|
- Usage: `./validate_certificates.py --host example.com --compliance PCI-DSS --json`
|
|
|
|
**renew_certificates.py** (450+ lines) - Automated ACME certificate renewal
|
|
- ACME protocol automation (Let's Encrypt, ZeroSSL)
|
|
- HTTP-01 and DNS-01 challenge support
|
|
- Automatic renewal based on expiration thresholds
|
|
- Pre/post/deploy hook support
|
|
- Automatic backup before renewal
|
|
- Rollback on renewal failure
|
|
- Batch renewal of all expiring certificates
|
|
- Dry-run mode for testing
|
|
- Staging environment support
|
|
- Custom ACME provider support
|
|
- DNS provider integration (Cloudflare, Route53, etc.)
|
|
- Usage: `./renew_certificates.py --domain example.com --dns-provider cloudflare --json`
|
|
|
|
**monitor_cert_expiry.sh** (550+ lines) - Certificate expiration monitoring
|
|
- Monitors certificates from remote hosts or local files
|
|
- Configurable warning/critical thresholds
|
|
- Multiple output formats (text, JSON, Prometheus, CSV)
|
|
- Batch monitoring from hosts file
|
|
- Directory scanning for certificate files
|
|
- Email/webhook/Slack alerting
|
|
- Certificate inventory export
|
|
- OCSP revocation status checking
|
|
- Prometheus metrics format for monitoring integration
|
|
- Color-coded terminal output
|
|
- Exit codes for CI/CD integration
|
|
- Usage: `./monitor_cert_expiry.sh --hosts-file hosts.txt --format prometheus --alert-email [email protected]`
|
|
|
|
### Examples (6 production-ready implementations)
|
|
|
|
**python/acme_automation.py** - ACME protocol automation from scratch
|
|
- Account registration and key management
|
|
- Certificate ordering with ACME protocol
|
|
- HTTP-01 challenge implementation
|
|
- DNS-01 challenge for wildcard certificates
|
|
- CSR generation with multiple SANs
|
|
- Complete ACME workflow demonstration
|
|
- Staging environment support
|
|
- Production-ready patterns
|
|
|
|
**python/mtls_server_client.py** - Mutual TLS implementation
|
|
- mTLS server with client certificate verification
|
|
- mTLS client with certificate authentication
|
|
- Certificate generation helper
|
|
- TLS version and cipher suite configuration
|
|
- Client certificate extraction and validation
|
|
- Zero-trust authentication pattern
|
|
- Service-to-service authentication example
|
|
|
|
**python/prometheus_cert_exporter.py** - Prometheus metrics exporter
|
|
- Exports certificate expiration metrics
|
|
- Multi-host monitoring support
|
|
- Prometheus-compatible metrics format
|
|
- Certificate metadata collection
|
|
- Expiration time tracking
|
|
- Validity status monitoring
|
|
- Error counting and duration tracking
|
|
- Health check endpoint
|
|
- Production-ready monitoring integration
|
|
|
|
**kubernetes/cert-manager-setup.yaml** - Comprehensive cert-manager configuration
|
|
- ClusterIssuers for Let's Encrypt (production and staging)
|
|
- DNS-01 solvers (Cloudflare, Route53)
|
|
- Certificate resources with SANs
|
|
- Wildcard certificate examples
|
|
- Ingress annotation automation
|
|
- Namespace-scoped issuers
|
|
- Private CA issuer configuration
|
|
- mTLS client certificates
|
|
- Certificate lifecycle management
|
|
- Renewal configuration
|
|
- Troubleshooting helpers
|
|
|
|
**bash/certbot-automation.sh** - Complete certbot automation suite
|
|
- HTTP-01 webroot validation
|
|
- Nginx plugin integration
|
|
- Wildcard certificates (manual and automated DNS)
|
|
- DNS provider integration (Cloudflare, Route53)
|
|
- Systemd timer setup for auto-renewal
|
|
- Pre/post/deploy hooks
|
|
- Certificate revocation
|
|
- Force renewal
|
|
- Staging environment testing
|
|
- Custom CSR usage
|
|
- Certificate monitoring
|
|
- Nginx installation automation
|
|
- 18+ production examples
|
|
|
|
**config/nginx-ssl-best-practices.conf** - Production Nginx SSL configuration
|
|
- Modern TLS 1.2/1.3 configuration
|
|
- Strong cipher suite selection
|
|
- OCSP stapling setup
|
|
- HSTS and security headers
|
|
- Let's Encrypt integration
|
|
- HTTP to HTTPS redirect
|
|
- Wildcard certificate support
|
|
- mTLS configuration
|
|
- Multiple domain examples
|
|
- SSL Labs A+ rating configuration
|
|
- Certificate renewal integration
|
|
- PHP-FPM and reverse proxy examples
|
|
|
|
### Quick Start
|
|
</code></pre>
|
|
<h1>Validate remote certificate</h1>
|
|
<p>cd ~/.hanzo/skills/cryptography/certificate-management/resources/scripts ./validate_certificates.py --host example.com --check-revocation</p>
|
|
<h1>Renew certificate automatically</h1>
|
|
<p>./renew_certificates.py --domain example.com --webroot /var/www/html --post-hook "systemctl reload nginx"</p>
|
|
<h1>Monitor certificate expiration</h1>
|
|
<p>./monitor_cert_expiry.sh --hosts-file hosts.txt --threshold-warning 30 --json</p>
|
|
<h1>Export Prometheus metrics</h1>
|
|
<p>./monitor_cert_expiry.sh --hosts-file hosts.txt --format prometheus > /var/lib/prometheus/cert_metrics.prom</p>
|
|
<h1>Run Python examples</h1>
|
|
<p>cd ../examples/python pip install cryptography acme josepy prometheus_client python acme_automation.py http01 python mtls_server_client.py setup && python mtls_server_client.py server python prometheus_cert_exporter.py --hosts example.com:443</p>
|
|
<h1>View comprehensive reference</h1>
|
|
<p>cd ../ less REFERENCE.md</p>
|
|
<pre><code>
|
|
### Integration Notes
|
|
|
|
**CI/CD Integration**:</code></pre>
|
|
<h1>.github/workflows/certificate-check.yml</h1>
|
|
<ul><li>name: Validate Certificates</li></ul>
|
|
<p> run: | ./scripts/validate_certificates.py \ --batch-file production-hosts.txt \ --compliance PCI-DSS \ --json \ --check-revocation</p>
|
|
<pre><code>
|
|
**Monitoring Setup**:</code></pre>
|
|
<h1>Prometheus scrape config</h1>
|
|
<p>scrape_configs:</p>
|
|
<ul><li>job_name: 'ssl-certificates'</li></ul>
|
|
<p> static_configs:</p>
|
|
<ul><li>targets: ['localhost:9117']</li></ul>
|
|
<p> scrape_interval: 60s</p>
|
|
<pre><code>
|
|
**Alerting**:</code></pre>
|
|
<h1>Prometheus alert rules</h1>
|
|
<ul><li>alert: CertificateExpiringSoon</li></ul>
|
|
<p> expr: ssl_certificate_expiry_seconds < 86400 * 30 labels: severity: warning annotations: summary: "Certificate expiring in < 30 days"</p>
|
|
<pre><code>
|
|
**Kubernetes Deployment**:</code></pre>
|
|
<h1>Install cert-manager</h1>
|
|
<p>kubectl apply -f examples/kubernetes/cert-manager-setup.yaml</p>
|
|
<h1>Check certificate status</h1>
|
|
<p>kubectl get certificates -A kubectl describe certificate example-com-tls</p>
|
|
<pre><code>
|
|
---
|
|
|
|
**Last Updated**: 2025-10-27
|
|
</code></pre>
|
|
<footer>
|
|
<div class="fmap">
|
|
<div><b>Build</b>
|
|
<a href="https://hanzo.app">hanzo.app</a> app builder
|
|
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
|
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
|
<div><b>Run</b>
|
|
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
|
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
|
<div><b>Account</b>
|
|
<a href="https://hanzo.id">hanzo.id</a> sign in
|
|
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
|
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
|
<div><b>Company</b>
|
|
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
|
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
|
</div>
|
|
<div class="fend"><a href="/cryptography-certificate-management.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |