2021-10-30 07:52:50 +00:00
|
|
|
package api
|
|
|
|
|
2021-11-02 05:26:07 +00:00
|
|
|
import (
|
|
|
|
"encoding/pem"
|
|
|
|
"net/http"
|
2022-09-14 18:50:11 +00:00
|
|
|
|
|
|
|
"github.com/smallstep/certificates/api/render"
|
2021-11-02 05:26:07 +00:00
|
|
|
)
|
2021-10-30 07:52:50 +00:00
|
|
|
|
2021-11-04 06:05:07 +00:00
|
|
|
// CRL is an HTTP handler that returns the current CRL in DER or PEM format
|
2022-07-13 00:56:47 +00:00
|
|
|
func CRL(w http.ResponseWriter, r *http.Request) {
|
|
|
|
crlBytes, err := mustAuthority(r.Context()).GetCertificateRevocationList()
|
2021-10-30 07:52:50 +00:00
|
|
|
if err != nil {
|
2022-09-14 18:50:11 +00:00
|
|
|
render.Error(w, err)
|
2021-11-04 06:05:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-14 18:50:11 +00:00
|
|
|
_, formatAsPEM := r.URL.Query()["pem"]
|
2021-11-04 06:05:07 +00:00
|
|
|
if formatAsPEM {
|
2023-05-03 20:49:26 +00:00
|
|
|
w.Header().Add("Content-Type", "application/x-pem-file")
|
|
|
|
w.Header().Add("Content-Disposition", "attachment; filename=\"crl.pem\"")
|
|
|
|
|
|
|
|
_ = pem.Encode(w, &pem.Block{
|
2021-11-04 06:05:07 +00:00
|
|
|
Type: "X509 CRL",
|
|
|
|
Bytes: crlBytes,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
w.Header().Add("Content-Type", "application/pkix-crl")
|
|
|
|
w.Header().Add("Content-Disposition", "attachment; filename=\"crl.der\"")
|
2022-09-14 18:50:11 +00:00
|
|
|
w.Write(crlBytes)
|
2021-11-04 06:05:07 +00:00
|
|
|
}
|
2021-10-30 07:52:50 +00:00
|
|
|
}
|