Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [SIW-402] Resolve trust chain #34

Merged
merged 12 commits into from
Sep 13, 2023
Merged

Conversation

balanza
Copy link
Contributor

@balanza balanza commented Sep 8, 2023

List of Changes

  • introduced trust folder for utilities related to the trust model
  • Added/refined types for federaration entities
  • Implemented trust chain verification
  • added utility to fetch and parse Entity Configuration of federation entities
  • added trust chain verification on example app

Motivation and Context

Documents shared with other parties (credentials, attestations, authz requests, etc) are signed and trusted according to https://italia.github.io/eudi-wallet-it-docs/v0.4.1/en/trust.html. Such documents contain a trust_chain field, which is intended to provide a static representation of the federation trust chain that connects the Leaf entity (i.e. the entity whose trustworthiness is being checked) to the known Trust Anchor entity,

The trust_chain is a list of signed token in the form:

[
  leaf entity configuration token,
  leaf entity statement token,
  intermediate1 entity statement token,
  ...
  intermediateN entity statement token,
  (optional) trust anchor entity configuration token,
]

Each token MUST be signed using one of the keys declared in the token next to it in the chain. The last token's signature will be checked against the known Trust Anchor's keys. Optionally, Trust Anchor entity configuration can be added as last element of the chain.

This PR proposes the verifyTrustChain function to be used as

import { getEntityConfiguration, verifyTrustChain } from "@pagopa/io-react-native-wallet";

const trustAnchorEC = await getEntityConfiguration("https://trustanchor.example");
const document = // the document received from the issuer/relying party, whose trust must be verified

const chain = await verifyTrustChain(trustAnchor, document.header.trust_chain);

How Has This Been Tested?

Screenshots (if appropriate):

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@balanza balanza requested a review from a team as a code owner September 8, 2023 11:20
Comment on lines -53 to -61
// FIXME: SIW-422 require federation_metadata field
// Actual RP implementation does not comply with the spec
/* federation_entity: z.object({
organization_name: z.string(),
homepage_uri: z.string(),
policy_uri: z.string(),
logo_uri: z.string(),
contacts: z.array(z.string()),
}), */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for rework but federation_entity has been added!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 98ca656

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I still don't see the update here

@@ -80,7 +90,7 @@ export default async () => {
).then((t) => RP.getRequestObject(t, authRequestUrl, entity));

// Attest Relying Party trust
// TODO [SIW-354]
await verifyTrustChain(trustAnchorEntity, requestObj.header.trust_chain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about adding this check also into the SDK function (like getEntityConfiguration())making sure that the caller is not responsible for doing the checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting point. That is true for every trustable document we have (including PID, WIA, RequestObject, etc).

I think it's good, anyway I'd do it in another PR as it involves a sensible refactor of classes because:

  • we must provide Trust Anchor data
  • we must model better error to avoid to hide informations on error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! Thanks you

src/trust/chain.ts Show resolved Hide resolved
Comment on lines +69 to +75
const selectTokenShape = (elementIndex: number) =>
elementIndex === 0
? FirstElementShape
: elementIndex === chain.length - 1
? LastElementShape
: MiddleElementShape;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 42 to 49
// Actual RP implementation does not comply with the spec
/* federation_entity: z.object({
organization_name: z.string(),
homepage_uri: z.string(),
policy_uri: z.string(),
logo_uri: z.string(),
contacts: z.array(z.string()),
}), */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RP added federation_entity. You can uncomment this part

grausof
grausof previously approved these changes Sep 12, 2023
Copy link
Contributor

@grausof grausof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix test since code review fail!

@balanza balanza dismissed grausof’s stale review September 12, 2023 14:16

Please check again, I pushed something new

@grausof
Copy link
Contributor

grausof commented Sep 12, 2023

It is necessary to add (certainly with a separate PR) fast renewal for entity configurations.

@balanza balanza added this pull request to the merge queue Sep 13, 2023
Copy link
Contributor

@grausof grausof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Merged via the queue into master with commit d73b3a3 Sep 13, 2023
3 checks passed
@balanza balanza deleted the SIW-402--resolve-trust-chain branch September 13, 2023 15:21
@balanza balanza mentioned this pull request Sep 14, 2023
2 tasks
github-merge-queue bot pushed a commit that referenced this pull request Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants