def __init__(self, ca): LOG.debug('=== Creating CertificateAuthorityController ===') self.ca = ca self.ca_repo = repo.get_ca_repository() self.project_ca_repo = repo.get_project_ca_repository() self.preferred_ca_repo = repo.get_preferred_ca_repository() self.project_repo = repo.get_project_repository()
def validate_ca_id(project_id, order_meta): ca_id = order_meta.get('ca_id') if not ca_id: return ca_repo = repo.get_ca_repository() ca = ca_repo.get(ca_id, suppress_exception=True) if not ca: raise exception.InvalidCAID(ca_id=ca_id) project_ca_repo = repo.get_project_ca_repository() project_cas, offset, limit, total = project_ca_repo.get_by_create_date( project_id=project_id, suppress_exception=True ) if total < 1: return for project_ca in project_cas: if ca.id == project_ca.ca_id: return raise exception.CANotDefinedForProject( ca_id=ca_id, project_id=project_id)
def validate_ca_id(project_id, order_meta): ca_id = order_meta.get('ca_id') if not ca_id: return ca_repo = repo.get_ca_repository() ca = ca_repo.get(ca_id, suppress_exception=True) if not ca: raise exception.InvalidCAID(ca_id=ca_id) if ca.project_id and ca.project_id != project_id: raise exception.UnauthorizedSubCA() project_ca_repo = repo.get_project_ca_repository() project_cas, offset, limit, total = project_ca_repo.get_by_create_date( project_id=project_id, suppress_exception=True ) if total < 1: return for project_ca in project_cas: if ca.id == project_ca.ca_id: return raise exception.CANotDefinedForProject( ca_id=ca_id, project_id=project_id)
def __init__(self): LOG.debug('Creating CertificateAuthoritiesController') self.ca_repo = repo.get_ca_repository() self.project_ca_repo = repo.get_project_ca_repository() self.preferred_ca_repo = repo.get_preferred_ca_repository() self.project_repo = repo.get_project_repository() self.validator = None
def __init__(self): LOG.debug('Creating CertificateAuthoritiesController') self.ca_repo = repo.get_ca_repository() self.project_ca_repo = repo.get_project_ca_repository() self.preferred_ca_repo = repo.get_preferred_ca_repository() self.project_repo = repo.get_project_repository() self.validator = validators.NewCAValidator() self.quota_enforcer = quota.QuotaEnforcer('cas', self.ca_repo) # Populate the CA table at start up cert_resources.refresh_certificate_resources()
def __init__(self, conf=CONF, invoke_args=(), invoke_kwargs={}): self.ca_repo = repos.get_ca_repository() super(CertificatePluginManager, self).__init__( conf.certificate.namespace, conf.certificate.enabled_certificate_plugins, invoke_on_load=False, # Defer creating plugins to utility below. invoke_args=invoke_args, invoke_kwds=invoke_kwargs) plugin_utils.instantiate_plugins(self, invoke_args, invoke_kwargs)
def __init__(self, conf=CONF, invoke_on_load=True, invoke_args=(), invoke_kwargs={}): self.ca_repo = repos.get_ca_repository() super(CertificatePluginManager, self).__init__( conf.certificate.namespace, conf.certificate.enabled_certificate_plugins, invoke_on_load=invoke_on_load, invoke_args=invoke_args, invoke_kwds=invoke_kwargs )
def delete_subordinate_ca(external_project_id, ca): """Deletes a subordinate CA and any related artifacts :param external_project_id: external project ID :param ca: class:`models.CertificateAuthority` to be deleted :return: None """ # TODO(alee) See if the checks below can be moved to the RBAC code # Check that this CA is a subCA if ca.project_id is None: raise excep.CannotDeleteBaseCA() # Check that the user's project owns this subCA project = res.get_or_create_project(external_project_id) if ca.project_id != project.id: raise excep.UnauthorizedSubCA() project_ca_repo = repos.get_project_ca_repository() (project_cas, _, _, _) = project_ca_repo.get_by_create_date(project_id=project.id, ca_id=ca.id, suppress_exception=True) preferred_ca_repo = repos.get_preferred_ca_repository() (preferred_cas, _, _, _) = preferred_ca_repo.get_by_create_date(project_id=project.id, ca_id=ca.id, suppress_exception=True) # Can not delete a project preferred CA, if other project CAs exist. One # of those needs to be designated as the preferred CA first. if project_cas and preferred_cas and not is_last_project_ca(project.id): raise excep.CannotDeletePreferredCA() # Remove the CA as preferred if preferred_cas: preferred_ca_repo.delete_entity_by_id(preferred_cas[0].id, external_project_id) # Remove the CA from project list if project_cas: project_ca_repo.delete_entity_by_id(project_cas[0].id, external_project_id) # Delete the CA entry from plugin cert_plugin = cert.CertificatePluginManager().get_plugin_by_name( ca.plugin_name) cert_plugin.delete_ca(ca.plugin_ca_id) # Finally, delete the CA entity from the CA repository ca_repo = repos.get_ca_repository() ca_repo.delete_entity_by_id(entity_id=ca.id, external_project_id=external_project_id)
def __init__(self, conf=CONF, invoke_args=(), invoke_kwargs={}): self.ca_repo = repos.get_ca_repository() super(CertificatePluginManager, self).__init__( conf.certificate.namespace, conf.certificate.enabled_certificate_plugins, invoke_on_load=False, # Defer creating plugins to utility below. invoke_args=invoke_args, invoke_kwds=invoke_kwargs ) plugin_utils.instantiate_plugins( self, invoke_args, invoke_kwargs)
def create_certificate_authority(project=None, parsed_ca_in=None, session=None): if not parsed_ca_in: parsed_ca_in = {'plugin_name': 'plugin_name', 'plugin_ca_id': 'plugin_ca_id', 'expiration:': 'expiration', 'creator_id': 'creator_id', 'project_id': project.id} certificate_authority = models.CertificateAuthority( parsed_ca_in=parsed_ca_in) cert_auth_repo = repositories.get_ca_repository() cert_auth_repo.create_from(certificate_authority, session=session) return certificate_authority
def delete_subordinate_ca(external_project_id, ca): """Deletes a subordinate CA and any related artifacts :param external_project_id: external project ID :param ca: class:`models.CertificateAuthority` to be deleted :return: None """ # TODO(alee) See if the checks below can be moved to the RBAC code # Check that this CA is a subCA if ca.project_id is None: raise excep.CannotDeleteBaseCA() # Check that the user's project owns this subCA project = res.get_or_create_project(external_project_id) if ca.project_id != project.id: raise excep.UnauthorizedSubCA() project_ca_repo = repos.get_project_ca_repository() (project_cas, _, _, _) = project_ca_repo.get_by_create_date( project_id=project.id, ca_id=ca.id, suppress_exception=True) preferred_ca_repo = repos.get_preferred_ca_repository() (preferred_cas, _, _, _) = preferred_ca_repo.get_by_create_date( project_id=project.id, ca_id=ca.id, suppress_exception=True) # Can not delete a project preferred CA, if other project CAs exist. One # of those needs to be designated as the preferred CA first. if project_cas and preferred_cas and not is_last_project_ca(project.id): raise excep.CannotDeletePreferredCA() # Remove the CA as preferred if preferred_cas: preferred_ca_repo.delete_entity_by_id(preferred_cas[0].id, external_project_id) # Remove the CA from project list if project_cas: project_ca_repo.delete_entity_by_id(project_cas[0].id, external_project_id) # Delete the CA entry from plugin cert_plugin = cert.CertificatePluginManager().get_plugin_by_name( ca.plugin_name) cert_plugin.delete_ca(ca.plugin_ca_id) # Finally, delete the CA entity from the CA repository ca_repo = repos.get_ca_repository() ca_repo.delete_entity_by_id( entity_id=ca.id, external_project_id=external_project_id)
def create_subordinate_ca(project_model, name, description, subject_dn, parent_ca_ref, creator_id): """Create a subordinate CA :param name - name of the subordinate CA :param: description - description of the subordinate CA :param: subject_dn - subject DN of the subordinate CA :param: parent_ca_ref - Barbican URL reference to the parent CA :param: creator_id - id for creator of the subordinate CA :return: :class models.CertificateAuthority model object for new sub CA """ # check that the parent ref exists and is accessible parent_ca_id = hrefs.get_ca_id_from_ref(parent_ca_ref) ca_repo = repos.get_ca_repository() parent_ca = ca_repo.get(entity_id=parent_ca_id, suppress_exception=True) if not parent_ca: raise excep.InvalidParentCA(parent_ca_ref=parent_ca_ref) # Parent CA must be a base CA or a subCA owned by this project if (parent_ca.project_id is not None and parent_ca.project_id != project_model.id): raise excep.UnauthorizedSubCA() # get the parent plugin, raises CertPluginNotFound if missing cert_plugin = cert.CertificatePluginManager().get_plugin_by_name( parent_ca.plugin_name) # confirm that the plugin supports creating subordinate CAs if not cert_plugin.supports_create_ca(): raise excep.SubCAsNotSupported() # make call to create the subordinate ca create_ca_dto = cert.CACreateDTO( name=name, description=description, subject_dn=subject_dn, parent_ca_id=parent_ca.plugin_ca_id) new_ca_dict = cert_plugin.create_ca(create_ca_dto) if not new_ca_dict: raise excep.SubCANotCreated(name=name) # create and store the subordinate CA as a new certificate authority object new_ca_dict['plugin_name'] = parent_ca.plugin_name new_ca_dict['creator_id'] = creator_id new_ca_dict['project_id'] = project_model.id new_ca = models.CertificateAuthority(new_ca_dict) ca_repo.create_from(new_ca) return new_ca
def _get_cert_plugin(barbican_meta, barbican_meta_for_plugins_dto, order_model, project_model): cert_plugin_name = barbican_meta.get('plugin_name') if cert_plugin_name: return cert.CertificatePluginManager().get_plugin_by_name( cert_plugin_name) ca_id = _get_ca_id(order_model.meta, project_model.id) if ca_id: ca = repos.get_ca_repository().get(ca_id) barbican_meta_for_plugins_dto.plugin_ca_id = ca.plugin_ca_id return cert.CertificatePluginManager().get_plugin_by_name( ca.plugin_name) else: return cert.CertificatePluginManager().get_plugin(order_model.meta)
def create_certificate_authority(project=None, parsed_ca_in=None, session=None): if not parsed_ca_in: parsed_ca_in = { 'plugin_name': 'plugin_name', 'plugin_ca_id': 'plugin_ca_id', 'expiration:': 'expiration', 'creator_id': 'creator_id', 'project_id': project.id } certificate_authority = models.CertificateAuthority( parsed_ca_in=parsed_ca_in) cert_auth_repo = repositories.get_ca_repository() cert_auth_repo.create_from(certificate_authority, session=session) return certificate_authority
# limitations under the License. import os import uuid import mock from barbican.common import resources from barbican.model import models from barbican.model import repositories from barbican.tests.api.controllers import test_acls from barbican.tests.api import test_resources_policy as test_policy from barbican.tests import utils order_repo = repositories.get_order_repository() project_repo = repositories.get_project_repository() ca_repo = repositories.get_ca_repository() project_ca_repo = repositories.get_project_ca_repository() container_repo = repositories.get_container_repository() generic_key_meta = { 'name': 'secretname', 'algorithm': 'AES', 'bit_length': 256, 'mode': 'cbc', 'payload_content_type': 'application/octet-stream' } class WhenCreatingOrdersUsingOrdersResource(utils.BarbicanAPIBaseTestCase): def test_can_create_a_new_order(self): resp, order_uuid = create_order(self.app,
# 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 mock from six import moves from barbican.common import exception from barbican.common import hrefs from barbican.common import resources as res from barbican.model import models from barbican.model import repositories from barbican.tests import utils project_repo = repositories.get_project_repository() ca_repo = repositories.get_ca_repository() project_ca_repo = repositories.get_project_repository() preferred_ca_repo = repositories.get_preferred_ca_repository() def create_ca(parsed_ca, id_ref="id"): """Generate a CA entity instance.""" ca = models.CertificateAuthority(parsed_ca) ca.id = id_ref return ca class WhenTestingCAsResource(utils.BarbicanAPIBaseTestCase): def test_should_get_list_certificate_authorities(self): self.app.extra_environ = {