src/fedoidcmsg/operator.py
def _unpack(self, ms_dict, keyjar, cls, jwt_ms=None, liss=None):
        """
        
        :param ms_dict: Metadata statement as a dictionary
        :param keyjar: A keyjar with the necessary FO keys
        :param cls: What class to map the metadata into
        :param jwt_ms: Metadata statement as a JWS 
        :param liss: List of FO issuer IDs
        :return: ParseInfo instance
        """
        if liss is None:
            liss = []

        _pr = ParseInfo()
        _pr.input = ms_dict
        ms_flag = False
        if 'metadata_statements' in ms_dict:
            ms_flag = True
            for iss, _ms in ms_dict['metadata_statements'].items():
                if liss and iss not in liss:
                    continue
                _pr = self._ums(_pr, _ms, keyjar)

        if 'metadata_statement_uris' in ms_dict:
            ms_flag = True
            if self.httpcli:
                for iss, url in ms_dict['metadata_statement_uris'].items():
                    if liss and iss not in liss:
                        continue
                    rsp = self.httpcli(method='GET', url=url,
                                       verify=self.verify_ssl)
                    if rsp.status_code == 200:
                        _pr = self._ums(_pr, rsp.text, keyjar)
                    else:
                        raise ParseError(
                            'Could not fetch jws from {}'.format(url))

        for _ms in _pr.parsed_statement:
            if _ms:  # can be None
                loaded = False
                try:
                    keyjar.import_jwks_as_json(_ms['signing_keys'],
                                               ms_dict['iss'])
                except KeyError:
                    pass
                except TypeError:
                    try:
                        keyjar.import_jwks(_ms['signing_keys'], ms_dict['iss'])
                    except Exception as err:
                        logger.error(err)
                        raise
                    else:
                        loaded = True
                else:
                    loaded = True

                if loaded:
                    logger.debug(
                        'Loaded signing keys belonging to {} into the '
                        'keyjar'.format(ms_dict['iss']))

        if ms_flag is True and not _pr.parsed_statement:
            return _pr

        if jwt_ms:
            logger.debug("verifying signed JWT: {}".format(jwt_ms))
            try:
                _pr.result = cls().from_jwt(jwt_ms, keyjar=keyjar)
            except MissingSigningKey:
                if 'signing_keys' in ms_dict:
                    try:
                        _pr.result = self.self_signed(ms_dict, jwt_ms, cls)
                    except MissingSigningKey as err:
                        logger.error('Encountered: {}'.format(err))
                        _pr.error[jwt_ms] = err
            except (JWSException, BadSignature, KeyError) as err:
                logger.error('Encountered: {}'.format(err))
                _pr.error[jwt_ms] = err
        else:
            _pr.result = ms_dict

        if _pr.result and _pr.parsed_statement:
            _prr = _pr.result

            _res = {}
            for x in _pr.parsed_statement:
                if x:
                    _res[get_fo(x)] = x

            _msg = Message(**_res)
            logger.debug('Resulting metadata statement: {}'.format(_msg))
            _pr.result['metadata_statements'] = _msg
        return _pr
def _unpack(self, ms_dict, keyjar, cls, jwt_ms=None, liss=None):
        """
        
        :param ms_dict: Metadata statement as a dictionary
        :param keyjar: A keyjar with the necessary FO keys
        :param cls: What class to map the metadata into
        :param jwt_ms: Metadata statement as a JWS 
        :param liss: List of FO issuer IDs
        :return: ParseInfo instance
        """
        if liss is None:
            liss = []

        _pr = ParseInfo()
        _pr.input = ms_dict
        ms_flag = False
        if 'metadata_statements' in ms_dict:
            ms_flag = True
            for iss, _ms in ms_dict['metadata_statements'].items():
                if liss and iss not in liss:
                    continue
                _pr = self._ums(_pr, _ms, keyjar)

        if 'metadata_statement_uris' in ms_dict:
            ms_flag = True
            if self.httpcli:
                for iss, url in ms_dict['metadata_statement_uris'].items():
                    if liss and iss not in liss:
                        continue
                    rsp = self.httpcli(method='GET', url=url,
                                       verify=self.verify_ssl)
                    if rsp.status_code == 200:
                        _pr = self._ums(_pr, rsp.text, keyjar)
                    else:
                        raise ParseError(
                            'Could not fetch jws from {}'.format(url))

        for _ms in _pr.parsed_statement:
            if _ms:  # can be None
                loaded = False
                try:
                    keyjar.import_jwks_as_json(_ms['signing_keys'],
                                               ms_dict['iss'])
                except KeyError:
                    pass
                except TypeError:
                    try:
                        keyjar.import_jwks(_ms['signing_keys'], ms_dict['iss'])
                    except Exception as err:
                        logger.error(err)
                        raise
                    else:
                        loaded = True
                else:
                    loaded = True

                if loaded:
                    logger.debug(
                        'Loaded signing keys belonging to {} into the '
                        'keyjar'.format(ms_dict['iss']))

        if ms_flag is True and not _pr.parsed_statement:
            return _pr

        if jwt_ms:
            logger.debug("verifying signed JWT: {}".format(jwt_ms))
            try:
                _pr.result = cls().from_jwt(jwt_ms, keyjar=keyjar)
            except MissingSigningKey:
                if 'signing_keys' in ms_dict:
                    try:
                        _pr.result = self.self_signed(ms_dict, jwt_ms, cls)
                    except MissingSigningKey as err:
                        logger.error('Encountered: {}'.format(err))
                        _pr.error[jwt_ms] = err
            except (JWSException, BadSignature, KeyError) as err:
                logger.error('Encountered: {}'.format(err))
                _pr.error[jwt_ms] = err
        else:
            _pr.result = ms_dict

        if _pr.result and _pr.parsed_statement:
            _prr = _pr.result

            _res = {}
            for x in _pr.parsed_statement:
                if x:
                    _res[get_fo(x)] = x

            _msg = Message(**_res)
            logger.debug('Resulting metadata statement: {}'.format(_msg))
            _pr.result['metadata_statements'] = _msg
        return _pr
def _unpack ( self , ms_dict , keyjar , cls , jwt_ms = None , liss = None ) : if liss is None : liss = [ ] _pr = ParseInfo ( ) _pr . input = ms_dict ms_flag = False if 'metadata_statements' in ms_dict : ms_flag = True for iss , _ms in ms_dict [ 'metadata_statements' ] . items ( ) : if liss and iss not in liss : continue _pr = self . _ums ( _pr , _ms , keyjar ) if 'metadata_statement_uris' in ms_dict : ms_flag = True if self . httpcli : for iss , url in ms_dict [ 'metadata_statement_uris' ] . items ( ) : if liss and iss not in liss : continue rsp = self . httpcli ( method = 'GET' , url = url , verify = self . verify_ssl ) if rsp . status_code == 200 : _pr = self . _ums ( _pr , rsp . text , keyjar ) else : raise ParseError ( 'Could not fetch jws from {}' . format ( url ) ) for _ms in _pr . parsed_statement : if _ms : # can be None loaded = False try : keyjar . import_jwks_as_json ( _ms [ 'signing_keys' ] , ms_dict [ 'iss' ] ) except KeyError : pass except TypeError : try : keyjar . import_jwks ( _ms [ 'signing_keys' ] , ms_dict [ 'iss' ] ) except Exception as err : logger . error ( err ) raise else : loaded = True else : loaded = True if loaded : logger . debug ( 'Loaded signing keys belonging to {} into the ' 'keyjar' . format ( ms_dict [ 'iss' ] ) ) if ms_flag is True and not _pr . parsed_statement : return _pr if jwt_ms : logger . debug ( "verifying signed JWT: {}" . format ( jwt_ms ) ) try : _pr . result = cls ( ) . from_jwt ( jwt_ms , keyjar = keyjar ) except MissingSigningKey : if 'signing_keys' in ms_dict : try : _pr . result = self . self_signed ( ms_dict , jwt_ms , cls ) except MissingSigningKey as err : logger . error ( 'Encountered: {}' . format ( err ) ) _pr . error [ jwt_ms ] = err except ( JWSException , BadSignature , KeyError ) as err : logger . error ( 'Encountered: {}' . format ( err ) ) _pr . error [ jwt_ms ] = err else : _pr . result = ms_dict if _pr . result and _pr . parsed_statement : _prr = _pr . result _res = { } for x in _pr . parsed_statement : if x : _res [ get_fo ( x ) ] = x _msg = Message ( * * _res ) logger . debug ( 'Resulting metadata statement: {}' . format ( _msg ) ) _pr . result [ 'metadata_statements' ] = _msg return _pr
:param ms_dict: Metadata statement as a dictionary
        :param keyjar: A keyjar with the necessary FO keys
        :param cls: What class to map the metadata into
        :param jwt_ms: Metadata statement as a JWS 
        :param liss: List of FO issuer IDs
        :return: ParseInfo instance
: param ms_dict : Metadata statement as a dictionary : param keyjar : A keyjar with the necessary FO keys : param cls : What class to map the metadata into : param jwt_ms : Metadata statement as a JWS : param liss : List of FO issuer IDs : return : ParseInfo instance