
Return the signing CA certificate. Closes bug: 1409037 Change-Id: I57ec9b657dd2bedf4b13a45703f7fd0c6d1d4a0b
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import logging
|
|
|
|
import pecan
|
|
from pecan import rest
|
|
|
|
from anchor import auth
|
|
from anchor import certificate_ops
|
|
from anchor import jsonloader
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RobotsController(rest.RestController):
|
|
"""Serves /robots.txt that disallows search bots."""
|
|
|
|
@pecan.expose(content_type="text/plain")
|
|
def get(self):
|
|
return "User-agent: *\nDisallow: /\n"
|
|
|
|
|
|
class GenericInstanceController(rest.RestController):
|
|
"""Handles requests to /xxx/ra_name."""
|
|
def __init__(self, ra_name):
|
|
self.ra_name = ra_name
|
|
|
|
|
|
class SignInstanceController(GenericInstanceController):
|
|
"""Handles POST requests to /sign/instance."""
|
|
@pecan.expose(content_type="text/plain")
|
|
def post(self):
|
|
ra_name = self.ra_name
|
|
|
|
logger.debug("processing signing request in registration authority %s",
|
|
ra_name)
|
|
auth_result = auth.validate(ra_name,
|
|
pecan.request.POST.get('user'),
|
|
pecan.request.POST.get('secret'))
|
|
csr = certificate_ops.parse_csr(pecan.request.POST.get('csr'),
|
|
pecan.request.POST.get('encoding'))
|
|
certificate_ops.validate_csr(ra_name, auth_result, csr, pecan.request)
|
|
|
|
return certificate_ops.dispatch_sign(ra_name, csr)
|
|
|
|
|
|
class CAInstanceController(GenericInstanceController):
|
|
"""Handles POST requests to /ca/ra_name."""
|
|
@pecan.expose(content_type="text/plain")
|
|
def get(self):
|
|
ra_name = self.ra_name
|
|
|
|
return certificate_ops.get_ca(ra_name)
|
|
|
|
|
|
class RAController(rest.RestController):
|
|
def __init__(self, subcontroller):
|
|
self._subcontroller = subcontroller
|
|
|
|
@pecan.expose()
|
|
def _lookup(self, ra_name, *remaining):
|
|
if ra_name in jsonloader.registration_authority_names():
|
|
return self._subcontroller(ra_name), remaining
|
|
pecan.abort(404)
|
|
|
|
|
|
class V1Controller(rest.RestController):
|
|
sign = RAController(SignInstanceController)
|
|
ca = RAController(CAInstanceController)
|
|
|
|
|
|
class RootController(object):
|
|
robots = RobotsController()
|
|
v1 = V1Controller()
|