crl.go 831 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. pemBytes := pem.EncodeToMemory(&pem.Block{
  17. Type: "X509 CRL",
  18. Bytes: crlBytes,
  19. })
  20. w.Header().Add("Content-Type", "application/x-pem-file")
  21. w.Header().Add("Content-Disposition", "attachment; filename=\"crl.pem\"")
  22. w.Write(pemBytes)
  23. } else {
  24. w.Header().Add("Content-Type", "application/pkix-crl")
  25. w.Header().Add("Content-Disposition", "attachment; filename=\"crl.der\"")
  26. w.Write(crlBytes)
  27. }
  28. }