mirror of
https://github.com/laurivosandi/certidude
synced 2025-01-09 15:47:37 +00:00
40 lines
1.9 KiB
Python
40 lines
1.9 KiB
Python
import falcon
|
|
import logging
|
|
from certidude import const, config
|
|
from .utils import AuthorityHandler
|
|
from .utils.firewall import whitelist_subnets
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class RevocationListResource(AuthorityHandler):
|
|
@whitelist_subnets(config.CRL_SUBNETS)
|
|
def on_get(self, req, resp):
|
|
# Primarily offer DER encoded CRL as per RFC5280
|
|
# This is also what StrongSwan expects
|
|
if req.client_accepts("application/x-pkcs7-crl"):
|
|
resp.set_header("Content-Type", "application/x-pkcs7-crl")
|
|
resp.append_header(
|
|
"Content-Disposition",
|
|
("attachment; filename=%s.crl" % const.HOSTNAME))
|
|
# Convert PEM to DER
|
|
logger.debug("Serving revocation list (DER) to %s", req.context.get("remote_addr"))
|
|
resp.body = self.authority.export_crl(pem=False)
|
|
elif req.client_accepts("application/x-pem-file"):
|
|
if req.get_param_as_bool("wait"):
|
|
url = config.LONG_POLL_SUBSCRIBE % "crl"
|
|
resp.status = falcon.HTTP_SEE_OTHER
|
|
resp.set_header("Location", url)
|
|
logger.debug("Redirecting to CRL request to %s", url)
|
|
resp.body = "Redirecting to %s" % url
|
|
else:
|
|
resp.set_header("Content-Type", "application/x-pem-file")
|
|
resp.append_header(
|
|
"Content-Disposition",
|
|
("attachment; filename=%s-crl.pem" % const.HOSTNAME))
|
|
logger.debug("Serving revocation list (PEM) to %s", req.context.get("remote_addr"))
|
|
resp.body = self.authority.export_crl()
|
|
else:
|
|
logger.debug("Client %s asked revocation list in unsupported format" % req.context.get("remote_addr"))
|
|
raise falcon.HTTPUnsupportedMediaType(
|
|
"Client did not accept application/x-pkcs7-crl or application/x-pem-file")
|