pyeudiw.federation package

Subpackages

Submodules

pyeudiw.federation.exceptions module

exception pyeudiw.federation.exceptions.InvalidChainError[source]

Bases: Exception

exception pyeudiw.federation.exceptions.InvalidEntityConfiguration[source]

Bases: Exception

exception pyeudiw.federation.exceptions.InvalidEntityHeader[source]

Bases: Exception

exception pyeudiw.federation.exceptions.InvalidEntityStatement[source]

Bases: Exception

exception pyeudiw.federation.exceptions.InvalidEntityStatementPayload[source]

Bases: Exception

exception pyeudiw.federation.exceptions.InvalidRequiredTrustMark[source]

Bases: Exception

exception pyeudiw.federation.exceptions.InvalidTrustchain[source]

Bases: Exception

exception pyeudiw.federation.exceptions.KeyValidationError[source]

Bases: Exception

exception pyeudiw.federation.exceptions.MetadataDiscoveryException[source]

Bases: Exception

exception pyeudiw.federation.exceptions.MissingAuthorityHintsClaim[source]

Bases: Exception

exception pyeudiw.federation.exceptions.MissingJwksClaim[source]

Bases: Exception

exception pyeudiw.federation.exceptions.MissingTrustAnchorPublicKey[source]

Bases: Exception

exception pyeudiw.federation.exceptions.MissingTrustMark[source]

Bases: Exception

exception pyeudiw.federation.exceptions.NotDescendant[source]

Bases: Exception

exception pyeudiw.federation.exceptions.PolicyError[source]

Bases: Exception

exception pyeudiw.federation.exceptions.ProtocolMetadataNotFound[source]

Bases: Exception

exception pyeudiw.federation.exceptions.TimeValidationError[source]

Bases: Exception

exception pyeudiw.federation.exceptions.TrustAnchorNeeded[source]

Bases: Exception

exception pyeudiw.federation.exceptions.TrustChainHttpError[source]

Bases: HttpError

exception pyeudiw.federation.exceptions.TrustchainMissingMetadata[source]

Bases: Exception

exception pyeudiw.federation.exceptions.UnknownKid[source]

Bases: Exception

pyeudiw.federation.policy module

class pyeudiw.federation.policy.TrustChainPolicy[source]

Bases: object

apply_policy(metadata: dict, policy: dict) dict[source]

Apply a metadata policy on metadata.

Parameters:
  • metadata – Metadata statements

  • policy – A dictionary with metadata and metadata_policy as keys

Returns:

A metadata statement that adheres to a metadata policy

gather_policies(chain, entity_type)[source]

Gather and combine all the metadata policies that are defined in the trust chain :param chain: A list of Entity Statements :return: The combined metadata policy

pyeudiw.federation.policy.combine(superior: dict, sub: dict) dict[source]
Parameters:
  • rule – Dictionary with two keys metadata_policy and metadata

  • sub – Dictionary with two keys metadata_policy and metadata

Returns:

pyeudiw.federation.policy.combine_add(s1, s2)[source]
pyeudiw.federation.policy.combine_claim_policy(superior, child)[source]

Combine policy rules. Applying the child policy can only make the combined policy more restrictive.

Parameters:
  • superior – Superior policy

  • child – Intermediates policy

pyeudiw.federation.policy.combine_one_of(s1, s2)[source]
pyeudiw.federation.policy.combine_subset_of(s1, s2)[source]
pyeudiw.federation.policy.combine_superset_of(s1, s2)[source]
pyeudiw.federation.policy.do_default(superior, child, policy)[source]
pyeudiw.federation.policy.do_essential(superior, child, policy)[source]
pyeudiw.federation.policy.do_sub_one_super_add(superior, child, policy)[source]
pyeudiw.federation.policy.do_value(superior, child, policy)[source]
pyeudiw.federation.policy.gather_policies(chain, entity_type)[source]

Gather and combine all the metadata policies that are defined in the trust chain :param chain: A list of Entity Statements :return: The combined metadata policy

pyeudiw.federation.policy.union(val1, val2)[source]

pyeudiw.federation.statements module

class pyeudiw.federation.statements.EntityStatement(jwt: str, httpc_params: dict, filter_by_allowed_trust_marks: list[str] = [], trust_anchor_entity_conf: EntityStatement | None = None, trust_mark_issuers_entity_confs: list[EntityStatement] = [])[source]

Bases: object

The self issued/signed statement of a federation entity

get_superiors(authority_hints: list[str] = [], max_authority_hints: int = 0, superiors_hints: list[dict] = []) dict[source]

get superiors entity configurations

Parameters:
  • authority_hints (list[str]) – the authority hint list

  • max_authority_hints (int) – the number of max authority hint

  • superiors_hints (list[dict]) – the list of superior hints

Returns:

a dict with the superior’s entity configurations

Return type:

dict

update_trust_anchor_conf(trust_anchor_entity_conf: EntityStatement) None[source]

Updates the internal Trust Anchor conf.

Parameters:

trust_anchor_entity_conf (EntityStatement) – the trust anchor entity conf

validate_by_allowed_trust_marks() bool[source]

validate the entity configuration ony if marked by a well known trust mark, issued by a trusted issuer

validate_by_itself() bool[source]

validates the entity configuration by it self

validate_by_superior_statement(jwt: str, ec: EntityStatement) str[source]

validates self with the jwks contained in statement of the superior :param jwt: the statement issued by a superior in form of JWT :type jwt: str :param ec: is a superior entity configuration :type ec: EntityStatement

Returns:

the entity configuration subject if is valid

Return type:

str

validate_by_superiors(superiors_entity_configurations: dict = {}) dict[source]

validates the entity configuration with the entity statements issued by its superiors this methods create self.verified_superiors and failed ones and self.verified_by_superiors and failed ones

Parameters:

superiors_entity_configurations (dict) – an object containing the entity configurations of superiors

Returns:

an object containing the superior validations

Return type:

dict

validate_descendant_statement(jwt: str) bool[source]

jwt is a descendant entity statement issued by self

Parameters:

jwt (str) – the JWT to validate by

Returns:

True if is valid or False otherwise

Return type:

bool

class pyeudiw.federation.statements.TrustMark(jwt: str, httpc_params: dict)[source]

Bases: object

The class representing a Trust Mark

validate_by(ec: dict) bool[source]

Validates Trust Marks by an Entity Configuration

Parameters:

ec (dict) – the entity configuration to validate by

Returns:

True if is valid otherwise False

Return type:

bool

validate_by_its_issuer() bool[source]

Validates Trust Marks by it’s issuer

Returns:

True if is valid otherwise False

Return type:

bool

pyeudiw.federation.statements.get_entity_configurations(subjects: list[str] | str, httpc_params: dict, http_async: bool = False) list[bytes][source]

Fetches an entity configuration from the specified subjects.

Parameters:
  • subjects (list[str] | str) – The url or a list of url where perform the GET HTTP calls

  • httpc_params (dict) – parameters to perform http requests.

  • http_async (bool) – if is set to True the operation will be performed in async (deafault True)

Returns:

A list of entity statements.

Return type:

list[Response]

pyeudiw.federation.statements.get_entity_statements(urls: list[str] | str, httpc_params: dict, http_async: bool = True) list[bytes][source]

Fetches an entity statement from the specified urls.

Parameters:
  • urls (list[str] | str) – The url or a list of url where perform the GET HTTP calls

  • httpc_params (dict) – parameters to perform http requests.

  • http_async (bool) – if is set to True the operation will be performed in async (deafault True)

Returns:

A list of entity statements.

Return type:

list[Response]

pyeudiw.federation.statements.get_federation_jwks(jwt_payload: dict) list[dict][source]

Returns the list of JWKS inside a JWT payload.

Parameters:

jwt_payload (dict) – the jwt payload from where extract the JWKs.

Returns:

A list of entity jwk’s keys.

Return type:

list[dict]

pyeudiw.federation.trust_chain_builder module

class pyeudiw.federation.trust_chain_builder.TrustChainBuilder(subject: str, trust_anchor: str, httpc_params: dict, trust_anchor_configuration: EntityStatement | str | None = None, max_authority_hints: int = 10, subject_configuration: EntityStatement | None = None, required_trust_marks: list[dict] = [], **kwargs)[source]

Bases: object

A trust walker that fetches statements and evaluate the evaluables

apply_metadata_policy() dict[source]

filters the trust path from subject to trust anchor apply the metadata policies along the path.

Returns:

the final metadata with policy applied

Return type:

dict

discovery() bool[source]

discovers the chain of verified statements from the lower up to the trust anchor and updates the internal representation of chain.

Returns:

the validity status of the updated chain

Return type:

bool

property exp_datetime: datetime

The exp filed converted in datetime format

get_subject_configuration() None[source]

Download and updates the internal field subject_configuration with the entity statement of leaf.

Return type:

None

get_trust_anchor_configuration() None[source]

Download and updates the internal field trust_anchor_configuration with the entity statement of trust anchor.

get_trust_chain() list[str][source]

Retrieves the leaf and the Trust Anchor entity configurations.

Returns:

the list containing the ECs

Return type:

list[str]

serialize() str[source]

Serializes the chain in JSON format.

Returns:

the serialized chain in JSON format

Return type:

str

start()[source]

Retrieves the subject (leaf) configuration and starts chain discovery.

Returns:

the list containing the ECs

Return type:

list[str]

pyeudiw.federation.trust_chain_validator module

class pyeudiw.federation.trust_chain_validator.StaticTrustChainValidator(static_trust_chain: list[str], trust_anchor_jwks: list[dict[str, Any]], httpc_params: dict, **kwargs)[source]

Bases: object

Helper class for Static Trust Chain validation

property entity_id: str

Get the chain’s entity_id.

property final_metadata: dict

Apply the metadata and returns the final metadata.

property is_expired: int

Get the status of chain expiration.

property is_valid: bool

Get the validity of chain.

set_exp(exp: int) None[source]

Updates the self.exp field if the exp parameter is more recent than the previous one.

Parameters:

exp (int) – an integer that represent the timestemp to check

property trust_chain: list[str]

Get the list of the jwt that compones the trust chain.

update() bool[source]

Updates the statement retrieving and the exp filed and determines the validity of it.

Returns:

True if the updated chain is valid, False otherwise.

Return type:

bool

validate() bool[source]

Validates the static chain checking the validity in all jwt inside the field trust_chain.

Returns:

True if static chain is valid and False otherwise

Return type:

bool

pyeudiw.federation.utils module

pyeudiw.federation.utils.is_es(payload: dict) None[source]

Determines if payload dict is a Subordinate Entity Statement

Parameters:

payload (dict) – the object to determine if is a Subordinate Entity Statement

Module contents