swift
10 lines · 1 tab
Kai Nakamura
Apr 2026
1 tab
final class PinnedSessionDelegate: NSObject, URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard let serverTrust = challenge.protectionSpace.serverTrust else {
completionHandler(.cancelAuthenticationChallenge, nil)
return
}
completionHandler(.useCredential, URLCredential(trust: serverTrust))
}
}
1 file · swift
Explain with highlit
Certificate pinning is useful in high-risk mobile scenarios, but it has real operational cost. I use it selectively, plan backup pins, and make sure the team can rotate infrastructure without bricking clients. Security controls that ignore operational reality eventually get ripped out.
Related snips
json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyInsecureTransport",
"Effect": "Deny",
S3 bucket policy that enforces TLS and blocks public reads
s3
aws
tls
by Kai Nakamura
1 tab
go
package deps
import (
"crypto/tls"
"crypto/x509"
"net/http"
mTLS client configuration with custom root CA pool
go
security
tls
by Leah Thompson
1 tab
nginx
server {
listen 443 ssl;
server_name internal-api.example.com;
ssl_certificate /etc/nginx/tls/server.crt;
ssl_certificate_key /etc/nginx/tls/server.key;
Mutual TLS between internal services with Nginx
mtls
tls
nginx
by Kai Nakamura
1 tab
yaml
# Install cert-manager (Helm)
# helm install cert-manager jetstack/cert-manager # --namespace cert-manager # --create-namespace # --set installCRDs=true
---
# ClusterIssuer for Let's Encrypt (staging)
apiVersion: cert-manager.io/v1
SSL/TLS certificates with Lets Encrypt and cert-manager
ssl
tls
certificates
by Ryan Nakamura
2 tabs
python
import requests
response = requests.get('https://crt.sh/', params={'q': '%.example.com', 'output': 'json'}, timeout=15)
response.raise_for_status()
certs = response.json()
print(certs[:5])
Certificate transparency checks for unexpected certificate issuance
certificate-transparency
tls
monitoring
by Kai Nakamura
1 tab
bash
#!/usr/bin/env bash
set -euo pipefail
certbot renew --quiet --deploy-hook "systemctl reload nginx"
openssl x509 -enddate -noout -in /etc/letsencrypt/live/example.com/fullchain.pem
TLS certificate automation with certbot and strict renewal checks
tls
certificates
certbot
by Kai Nakamura
1 tab
Share this code
Here's the card — post it anywhere.