4
0

crl.go 799 B

1234567891011121314151617181920212223242526272829303132
  1. package api
  2. import (
  3. "encoding/pem"
  4. "net/http"
  5. "github.com/smallstep/certificates/api/render"
  6. )
  7. // CRL is an HTTP handler that returns the current CRL in DER or PEM format
  8. func CRL(w http.ResponseWriter, r *http.Request) {
  9. crlBytes, err := mustAuthority(r.Context()).GetCertificateRevocationList()
  10. if err != nil {
  11. render.Error(w, err)
  12. return
  13. }
  14. _, formatAsPEM := r.URL.Query()["pem"]
  15. if formatAsPEM {
  16. w.Header().Add("Content-Type", "application/x-pem-file")
  17. w.Header().Add("Content-Disposition", "attachment; filename=\"crl.pem\"")
  18. _ = pem.Encode(w, &pem.Block{
  19. Type: "X509 CRL",
  20. Bytes: crlBytes,
  21. })
  22. } else {
  23. w.Header().Add("Content-Type", "application/pkix-crl")
  24. w.Header().Add("Content-Disposition", "attachment; filename=\"crl.der\"")
  25. w.Write(crlBytes)
  26. }
  27. }