Esempio n. 1
0
    def __init__(self, conf: Dict) -> None:
        self.logger = configure_logging(
            config=conf.get('logging')).getChild(__name__)
        self.op = None

        # OIDC provider configuration
        for section in ['op', 'webserver', 'http_params', 'jinja_env']:
            setattr(self, section, conf.get(section, {}))

        # set OP session key
        _key_args = self.op['server_info'].get('session_key')
        if _key_args is not None:
            self.session_key = init_key(**_key_args)
            # self.op['server_info']['password'] = self.session_key
            self.logger.debug("Set server password to %s", self.session_key)

        # templates and Jinja environment
        self.template_dir = os.path.abspath(
            conf.get('template_dir', 'templates'))

        # server info
        self.domain = conf.get("domain")
        self.port = conf.get("port")
        for param in ["server_name", "base_url"]:
            _pre = conf.get(param)
            if _pre:
                if '{domain}' in _pre:
                    setattr(self, param,
                            _pre.format(domain=self.domain, port=self.port))
                else:
                    setattr(self, param, _pre)
Esempio n. 2
0
    def __init__(
        self,
        conf: Dict,
        entity_conf: Optional[List[dict]] = None,
        base_path: str = "",
        file_attributes: Optional[List[str]] = None,
        domain: Optional[str] = "",
        port: Optional[int] = 0,
    ):
        Base.__init__(self, conf, base_path, file_attributes)

        log_conf = conf.get("logging")
        if log_conf:
            self.logger = configure_logging(config=log_conf).getChild(__name__)
        else:
            self.logger = logging.getLogger("oidcop")

        self.webserver = conf.get("webserver", {})

        if not domain:
            domain = conf.get("domain", "127.0.0.1")

        if not port:
            port = conf.get("port", 80)

        set_domain_and_port(conf, self.uris, domain=domain, port=port)

        if entity_conf:
            for econf in entity_conf:
                _path = econf.get("path")
                _cnf = conf
                if _path:
                    for step in _path:
                        _cnf = _cnf[step]
                _attr = econf["attr"]
                _cls = econf["class"]
                setattr(
                    self,
                    _attr,
                    _cls(
                        _cnf,
                        base_path=base_path,
                        file_attributes=file_attributes,
                        domain=domain,
                        port=port,
                    ),
                )
Esempio n. 3
0
    def __init__(self, conf: Dict) -> None:
        self.logger = configure_logging(
            config=conf.get('logging')).getChild(__name__)
        self.op = None

        # OIDC provider configuration
        for section in ['op', 'webserver', 'http_params', 'jinja_env']:
            setattr(self, section, conf.get(section, {}))

        # set OP session key
        _key_args = self.op['server_info'].get('session_key')
        if _key_args is not None:
            self.session_key = init_key(**_key_args)
            # self.op['server_info']['password'] = self.session_key
            self.logger.debug("Set server password to %s", self.session_key)

        # templates and Jinja environment
        self.template_dir = os.path.abspath(
            conf.get('template_dir', 'templates'))
Esempio n. 4
0
    def __init__(self, conf: Dict) -> None:
        self.logger = configure_logging(settings.LOGGING)

        # OIDC provider configuration
        self.conf = conf
        self.op = conf.get('op')

        # TODO: here manage static clients without dyn registration enabled
        # self.oidc_clients = conf.get('oidc_clients', {})

        # session key
        self.session_jwk = conf.get('session_jwk')
        if self.session_jwk is not None:
            self.logger.debug("Reading session signer from %s",
                              self.session_jwk)
            try:
                with open(self.session_jwk) as jwk_file:
                    jwk_dict = json.loads(jwk_file.read())
                    self.session_key = key_from_jwk_dict(jwk_dict).k
            except Exception:
                self.logger.critical("Failed reading session signer from %s",
                                     self.session_jwk)
                sys.exit(-1)
        else:
            self.logger.debug("Generating random session signer")
            self.session_key = SYMKey(key=rnd_token(32)).k

        # set OP session key
        if self.op is not None:
            if self.op['server_info'].get('password') is None:
                key = self.session_key
                self.op['server_info']['password'] = key
                self.logger.debug("Set server password to %s", key)

        # templates environment
        self.template_dir = os.path.abspath(
            conf.get('template_dir', 'templates'))
Esempio n. 5
0
    def __init__(self, conf: Dict) -> None:
        self.logger = configure_logging(
            config=conf.get('logging')).getChild(__name__)

        # OIDC provider configuration
        self.op = conf.get('op')
        self.webserver = conf.get('webserver')
        # self.oidc_clients = conf.get('oidc_clients', {})

        # session key
        self.session_jwk = conf.get('session_jwk')
        if self.session_jwk is not None:
            self.logger.debug("Reading session signer from %s",
                              self.session_jwk)
            try:
                with open(self.session_jwk) as jwk_file:
                    jwk_dict = json.loads(jwk_file.read())
                    self.session_key = key_from_jwk_dict(jwk_dict).k
            except Exception:
                self.logger.critical("Failed reading session signer from %s",
                                     self.session_jwk)
                sys.exit(-1)
        else:
            self.logger.debug("Generating random session signer")
            self.session_key = SYMKey(key=rnd_token(32)).k

        # set OP session key
        if self.op is not None:
            if self.op['server_info'].get('password') is None:
                key = self.session_key
                self.op['server_info']['password'] = key
                self.logger.debug("Set server password to %s", key)

        # templates and Jinja environment
        self.template_dir = os.path.abspath(
            conf.get('template_dir', 'templates'))
        self.jinja_env = conf.get('jinja_env', {})
Esempio n. 6
0
def test_loggin_conf_dict():
    logger = configure_logging(config=CONF)
    assert logger
Esempio n. 7
0
def test_loggin_conf_default():
    logger = configure_logging()
    assert logger
Esempio n. 8
0
def test_loggin_conf_file():
    logger = configure_logging(filename=full_path("logging.yaml"))
    assert logger
Esempio n. 9
0
}

if __name__ == '__main__':
    pass

    parser = argparse.ArgumentParser()
    parser.add_argument('-k', dest='insecure', action='store_true')
    parser.add_argument('-t', dest='trusted_roots_file')
    parser.add_argument('-e', dest='entity_type')
    parser.add_argument('-o', dest='opponent_entity_type')
    parser.add_argument('-l', dest='logging', action='store_true')
    parser.add_argument(dest="url")
    args = parser.parse_args()

    if args.logging:
        logger = configure_logging(config=LOGGING).getChild(__name__)

    trusted_roots = json.loads(open(args.trusted_roots_file).read())

    # Creates an entity that can do the collecting of information
    federation_entity = FederationEntity(
        'issuer',
        trusted_roots=trusted_roots,
        entity_type=args.entity_type,
        opponent_entity_type=args.opponent_entity_type)

    if args.insecure:
        federation_entity.collector.insecure = args.insecure

    jws = federation_entity.get_configuration_information(args.url)
    metadata = verify_self_signed_signature(jws)