Example #1
0
File: root.py Project: r3boot/pki
    def initca(self, pwfile=None):
        """ initca:     Generate the key and certificate for this CA
        """
        if pwfile and not os.path.exists(pwfile):
            log.warning("{0} does not exist".format(pwfile))
            return False

        log.info("Generating key and csr for {0} CA".format(self.name))
        self.genkey(self.ca_data["cfg"], self.name, pwfile)

        log.info("Generating certificate for {0} CA".format(self.name))
        self.selfsign(self.ca_data["cfg"], self.name, pwfile)
Example #2
0
    def setup(self):
        """Initialize the file structure for this CA
        """
        log.info('Setup directories for {0} CA'.format(self.name))
        ca_directories = ['certs', 'cfg', 'crl', 'csr', 'db', 'private']

        for directory in ca_directories:
            fdir = '{0}/{1}'.format(self.basedir, directory)
            if not os.path.exists(fdir):
                log.info('Creating {0}/{1}'.format(self.name, directory))
                os.mkdir(fdir)

        log.info('Initialize databases for {0} CA'.format(self.name))
        for empty_file in [self.ca_data['db'], self.ca_data['db_attr']]:
            open(empty_file, 'w').write('')

        for serial_file in [self.ca_data['crt_idx'], self.ca_data['crl_idx']]:
            open(serial_file, 'w').write('01\n')

        log.info('Installing configuration file for {0} CA'.format(self.name))
        cfgfile = '{0}/cfg/{1}.cfg'.format(self.basedir, self.name)

        cfg = {}
        cfg.update(self.config['common'])

        if self.ca_type != CA_PARENT:
            cfg.update(self.config[self.ca_type])
        else:
            cfg['cn'] = '{0} CA'.format(CA_PARENT)

        cfg.update(self.ca_data)

        cfg['crypto'] = self.config['crypto']
        cfg['basedir'] = self.basedir
        cfg['ca_type'] = self.ca_type
        cfg['name'] = self.name
        cfg['days'] = self.days
        cfg['certsdir'] = self.crtdir

        template_file = '{0}/templates/root.template'.format(self.workspace)
        if not os.path.exists(template_file):
            log.error('{0} not found'.format(template_file))
        template_data = open(template_file, 'r').read()

        template = mako.template.Template(template_data)
        cfg_data = template.render(**cfg)
        open(cfgfile, 'w').write('{0}\n'.format(cfg_data))
Example #3
0
File: log.py Project: r3boot/pki
 def test_info_heading(self):
     the_message = 'Informational message'
     log.info(the_message)
     output = open(LOG_FILE, 'r').read().strip()
     assert 'INFO' in output
Example #4
0
File: log.py Project: r3boot/pki
 def test_info_no_handler(self):
     log.LOGGER = None
     assert log.info('Informational message') is None
     log.LOGGER = log.get_handler(CFG_FILE, LOG_HANDLER)