certidude/certidude/api/revoked.py

45 lines
1.9 KiB
Python
Raw Normal View History

import click
2016-03-29 10:28:58 +00:00
import falcon
2016-03-30 19:00:18 +00:00
import json
import logging
2017-01-30 06:29:01 +00:00
from certidude import const, config
from certidude.firewall import whitelist_subnets
2017-04-04 05:02:08 +00:00
logger = logging.getLogger(__name__)
class RevocationListResource(object):
def __init__(self, authority):
self.authority = authority
@whitelist_subnets(config.CRL_SUBNETS)
def on_get(self, req, resp):
2016-03-29 10:28:58 +00:00
# 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))
2016-03-29 10:28:58 +00:00
# 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)
2016-03-29 10:28:58 +00:00
elif req.client_accepts("application/x-pem-file"):
2017-01-30 06:29:01 +00:00
if req.get_param_as_bool("wait"):
url = config.LONG_POLL_SUBSCRIBE % "crl"
2017-01-30 06:29:01 +00:00
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
2017-01-30 06:29:01 +00:00
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()
2016-03-29 10:28:58 +00:00
else:
logger.debug("Client %s asked revocation list in unsupported format" % req.context.get("remote_addr"))
2016-03-29 10:28:58 +00:00
raise falcon.HTTPUnsupportedMediaType(
"Client did not accept application/x-pkcs7-crl or application/x-pem-file")