示例#1
0
def install_service_cert(options):
    ''' Install a private key for a specific service '''
    from shutil import copyfile

    service = '' if not options.service else options.service.lower()
    if service != 'lighthouse':
        print('The "service" option is not "lighthouse". Currently, keys can only be installed for the Lighthouse module.')
        sys.exit(1)

    source_keyfile = options.keyfile
    if not source_keyfile:
        print('No private key file given!')
        sys.exit(1)

    if not os.path.isfile(source_keyfile):
        print('Private key file "{}" was not found.'.format(source_keyfile))
        sys.exit(1)

    pub_key, sec_key = zmq.auth.load_certificate(source_keyfile)
    if not sec_key:
        print('The given keyfile does not contain a secret key!')

    lconf = LocalConfig()
    target_keyfile = lconf.zcurve_secret_keyfile_for_module(service)
    if os.path.isfile(target_keyfile) and not options.force:
        print('We already have a secret key for this service on the current machine. You can override the existing one by specifying "--force".')
        sys.exit(2)

    try:
        copyfile(source_keyfile, target_keyfile)
    except Exception as e:
        print('Failed to install new secret key as {}: {}'.format(target_keyfile, str(e)))
        sys.exit(3)
    print('Installed private key as {}'.format(target_keyfile))
示例#2
0
    def __init__(self, verbose=False):
        self._server = None
        self._ctx = zmq.Context.instance()

        if verbose:
            log.basicConfig(level=log.DEBUG, format="[%(levelname)s] %(message)s")

        lconf = LocalConfig()
        self._trusted_keys_dir = lconf.zcurve_trusted_certs_dir + '/'
        self._server_private_key = lconf.zcurve_secret_keyfile_for_module(LkModule.LIGHTHOUSE)

        self._jobs_endpoint = lconf.lighthouse_endpoint
        self._worker = JobWorker()