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

MOSIP fixes #75

Closed
wants to merge 15 commits into from
Closed

Conversation

sanderPostma
Copy link
Contributor

include presentationSubmission in auth response
include nonce in AuthorizationResponsePayload

@sanderPostma sanderPostma changed the base branch from develop to fix/idtoken_vptoken-andv18-fixes February 28, 2024 15:37
@@ -120,7 +120,9 @@ export class AuthorizationResponse {
presentationDefinitions,
presentations: wrappedPresentations,
verificationCallback: verifyOpts.verification.presentationVerificationCallback,
opts: { ...responseOpts.presentationExchange, hasher: verifyOpts.hasher },
opts: { ...responseOpts.presentationExchange,
presentationSubmission: (responseOpts.presentationExchange.presentationSubmission ?? authorizationResponsePayload.presentation_submission),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

assertValidVerifiablePresentations has this check

} else if (args.presentationDefinitions && !args.opts.presentationSubmission) {
  throw new Error(`No presentation submission present. Please use presentationSubmission opt argument!`);
}

So we need opts.presentationSubmission


const responsePayload: AuthorizationResponsePayload = {
...(responseOpts.accessToken && { access_token: responseOpts.accessToken }),
...(responseOpts.tokenType && { token_type: responseOpts.tokenType }),
...(responseOpts.refreshToken && { refresh_token: responseOpts.refreshToken }),
...(payload?.nonce && { nonce: payload.nonce}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In AuthenticationResponse verify():

    const nonce = merged.nonce ?? verifiedIdToken?.payload.nonce ?? oid4vp.nonce;
    ...
    } else if (oid4vp.presentationDefinitions.length > 0 && !nonce) {
      throw Error('Nonce is required when using OID4VP');
    }

In my case, if I don't return the nonce it will run into "Nonce is required when using OID4VP"

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that is according to spec

Copy link
Contributor

Choose a reason for hiding this comment

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

So this PR is wrong

@sanderPostma sanderPostma marked this pull request as ready for review February 28, 2024 15:51
Copy link
Contributor

@nklomp nklomp left a comment

Choose a reason for hiding this comment

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

PR is wrong. if there is a vp token in the request, you are required to have a presentation submission


await assertValidVerifiablePresentations({
presentationDefinitions,
presentations: wrappedPresentations,
verificationCallback: verifyOpts.verification.presentationVerificationCallback,
opts: {
...responseOpts.presentationExchange,
presentationSubmission: responseOpts.presentationExchange?.presentationSubmission ?? authorizationResponsePayload.presentation_submission,
...(presentationSubmission ? { presentationSubmission: presentationSubmission } : {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong! If the above hasVpToken is true, there needs to be a submission. So either the logic to determine the hasVpToken is wrong, or something else is happening. This PR is wrong for sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found the submission in authorizationResponsePayload.presentation_submission not in presentationExchange. So this needs to be fixed elsewhere then.
So that that makes this PR is not to merge, just for diagnostics. I will revert the change in my branch as soon as presentationSubmission appears in presentationExchange

Copy link
Contributor

Choose a reason for hiding this comment

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

No you are likely simply misunderstanding how it works. Presentation Exchange is a service that provides the submission, but only when a vp_token is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have found the problem, in the SSI SDK version I am using with RSA support, presentationSubmission in OPSession is not loaded yet.
image

But this line still has to be in opts

          ...(presentationSubmission ? { presentationSubmission: presentationSubmission } : {}),

It's asserted in assertValidVerifiablePresentations

  } else if (args.presentationDefinitions && !args.opts.presentationSubmission) {
    throw new Error(`No presentation submission present. Please use presentationSubmission opt argument!`);
  } else if (args.presentationDefinitions && presentationsWithFormat) {

Copy link
Contributor

Choose a reason for hiding this comment

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

No that line should not be in opts

Copy link
Contributor

@nklomp nklomp Mar 6, 2024

Choose a reason for hiding this comment

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

Please reread from the top. Whenever a vp_token is requested by the RP a PE definition needs to be present. Then we require the PresentationExchange service to be present. That one can create the Presentation Submission using the definition from the RP and the VCs provided to it.
There is no situation where there is no submission or an empty submission when a vp_token is requested and thus a PE definition being present.

That is literally why those guards are in place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see now it has the ... before responseOpts.presentationExchange so it should be in opts already. So the problem was my OPSession which was from before October 13th and I patched before it up by getting it from elsewhere.
I reverted that code


const responsePayload: AuthorizationResponsePayload = {
...(responseOpts.accessToken && { access_token: responseOpts.accessToken }),
...(responseOpts.tokenType && { token_type: responseOpts.tokenType }),
...(responseOpts.refreshToken && { refresh_token: responseOpts.refreshToken }),
...(payload?.nonce && { nonce: payload.nonce }),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nonce should not endup in authorization response. That should be either in the id token or vp token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const oid4vp = await verifyPresentations(this, verifyOpts);
const nonce = merged.nonce ?? verifiedIdToken?.payload.nonce ?? oid4vp.nonce;

When I remove nonce from AuthorizationResponsePayload it will not be in merged.nonce, I don't have idToken so I will need to debug verifyPresentations .

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned it needs to end either in the id token and/or vp token depending om which token(s) are requested. Since this comes from the OID request object it should never end up in oauth2 response payload directly

Copy link
Contributor

Choose a reason for hiding this comment

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

So if there is no request object then there indeed is no nonce typically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted this. After retest with newer libraries this appears to be working again.

@sanderPostma sanderPostma changed the base branch from fix/idtoken_vptoken-andv18-fixes to develop March 6, 2024 16:38
@sanderPostma
Copy link
Contributor Author

Closing this PR, the left hand develop branch does not match what's actually in that branch atm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants