Exemplo n.º 1
0
def get_ssl_context() -> ssl.SSLContext:
    proxy_config = ServiceRegistry.get_proxy_config()
    ret = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    try:
        ret.load_cert_chain(certfile=proxy_config["gateway_cert"],
                            keyfile=proxy_config["gateway_key"])
    except FileNotFoundError:
        raise RuntimeError("Gateway cert or key file not found")
    return ret
Exemplo n.º 2
0
    async def on_checkin_fail(self, err_code):
        """Checks for invalid certificate as cause for checkin failures"""
        if err_code == grpc.StatusCode.PERMISSION_DENIED:
            # Immediately bootstrap if the error is PERMISSION_DENIED
            return await self.bootstrap()
        proxy_config = ServiceRegistry.get_proxy_config()
        host = proxy_config['cloud_address']
        port = proxy_config['cloud_port']
        certfile = proxy_config['gateway_cert']
        keyfile = proxy_config['gateway_key']

        not_valid = await \
            cert_is_invalid(host, port, certfile, keyfile, self._loop)
        await self._cert_is_invalid_done(not_valid)
        return not_valid  # for testing
Exemplo n.º 3
0
 async def _schedule_bootstrap_if_cert_is_invalid(self, err_code):
     """
     Checks for invalid certificate as cause for state reporting failures
     """
     if err_code == grpc.StatusCode.PERMISSION_DENIED:
         await self._bootstrap_manager.schedule_bootstrap_now()
         return
     proxy_config = ServiceRegistry.get_proxy_config()
     host = proxy_config['cloud_address']
     port = proxy_config['cloud_port']
     cert_file = proxy_config['gateway_cert']
     key_file = proxy_config['gateway_key']
     not_valid = await \
         cert_is_invalid(host, port, cert_file, key_file, self._loop)
     if not_valid:
         logging.info('Bootstrapping due to invalid certificate')
         await self._bootstrap_manager.schedule_bootstrap_now()
Exemplo n.º 4
0
    def on_checkin_fail(self, err_code):
        """Checks for invalid certificate as cause for checkin failures"""
        if err_code == grpc.StatusCode.PERMISSION_DENIED:
            # Immediately bootstrap if the error is PERMISSION_DENIED
            self.bootstrap()
            return
        logging.info('Checking cert validity')
        proxy_config = ServiceRegistry.get_proxy_config()
        host = proxy_config['cloud_address']
        port = proxy_config['cloud_port']
        certfile = proxy_config['gateway_cert']
        keyfile = proxy_config['gateway_key']

        future = asyncio.ensure_future(
            cert_is_invalid(host, port, certfile, keyfile, self._loop),
            loop=self._loop,
        )
        future.add_done_callback(functools.partial(self._cert_is_invalid_done))
        return future  # for testing