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

docs: 466/hash-verification #512

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

docs: 466/hash-verification #512

wants to merge 10 commits into from

Conversation

hajjimo
Copy link
Contributor

@hajjimo hajjimo commented Oct 21, 2024

Changes proposed in this pull request

Context

Copy link

changeset-bot bot commented Oct 21, 2024

⚠️ No Changeset found

Latest commit: 0040ace

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Oct 21, 2024

Deploy Preview for openpayments-preview ready!

Name Link
🔨 Latest commit 0040ace
🔍 Latest deploy log https://app.netlify.com/sites/openpayments-preview/deploys/67618585bccfed0008c066b6
😎 Deploy Preview https://deploy-preview-512--openpayments-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


import { CodeBlock, LinkOut } from '@interledger/docs-design-system'

Once a resource owner (RO) authorizes a client software, the authorization server (AS) will redeirect the RO's [identify provider (IdP)](/introduction/idp/) to the finish URI. In order to secure this communication and verify that the redirect indeed emanated from the AS, the AS will provide a hash parameter in the request to the client's callback URI. The client **_must_** verify this hash.
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Typo "redeirect"
  • Change "identify provider" to identity provider


</CodeBlock>

For more information refer to the <LinkOut href='https://datatracker.ietf.org/doc/html/draft-ietf-gnap-core-protocol-20#name-calculating-the-interaction'> "Calculating the interaction hash"</LinkOut> section of the GNAP specification.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove the quotation marks around the link name?

@hajjimo hajjimo linked an issue Nov 4, 2024 that may be closed by this pull request
@mkurapov mkurapov self-requested a review November 5, 2024 14:21
@hajjimo hajjimo requested review from raducristianpopa and removed request for sabineschaller November 7, 2024 08:13

## Hashing method

The hash base is generated by concatentating the following values in sequence using a single newline (0x0A) character to separate them:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The hash base is generated by concatentating the following values in sequence using a single newline (0x0A) character to separate them:
The hash base is generated by concatentating the following values in sequence using a single newline (\n) character to separate them:

The hash base is generated by concatentating the following values in sequence using a single newline (0x0A) character to separate them:

1. `nonce` value sent by the client in the initial request.
2. `nonce` value sent by the AS from the interaction finish response.
Copy link
Member

Choose a reason for hiding this comment

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

The interact nonce is returned after making the initial grant request (interaction instructions):

{
  "interact": {
    "redirect": "https://auth.rafiki.money/4CF492MLVMSW9MKMXKHQ",
    "finish": "4105340a-05eb-4290-8739-f9e2b463bfa7" // <- nonce
  },
  "continue": {
    "access_token": {
      "value": "33OMUKMKSKU80UPRY5NM"
    },
    "uri": "https://auth.rafiki.money/continue/4CF492MLVMSW9MKMXKHQ",
    "wait": 30
  }
}

Comment on lines 31 to 33
The ASCII encoding of this string is hashed with the algorithm specified in the `hash_method` parameter under the `finish` key of the interaction finish request. The byte array from the hash function is then encoded using URL-Safe Base64 with no padding. The resultant string is the hash value.

Unless specified by the client in the initial request, the `hash_method` will default to `sha-256`. If the client specifies the `hash_method`, the `hash_method` **_must_** be one of the hash name strings defined in the <LinkOut href='https://www.iana.org/assignments/named-information/named-information.xhtml#hash-alg'>IANA Named Information Hash Algorithm Registry</LinkOut>.
Copy link
Member

Choose a reason for hiding this comment

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

@mkurapov are we planning to support other hashing methods as well? If not I think we should only mention sha-256.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so, we can just mention sha-256


</CodeBlock>

The ASCII encoding of this string is hashed with the algorithm specified in the `hash_method` parameter under the `finish` key of the interaction finish request. The byte array from the hash function is then encoded using URL-Safe Base64 with no padding. The resultant string is the hash value.
Copy link
Member

Choose a reason for hiding this comment

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

In Rafiki we are doing only doing base64 encoding not base64url.

CC @mkurapov

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, base64 is correct

- edit hash verification page for changes suggested by Radu
- replace custom Disclosure components with details component
- remove Disclosure references from Import statements

import { CodeBlock, LinkOut } from '@interledger/docs-design-system'

Once a resource owner (RO) authorizes a client software, the authorization server (AS) will redirect the RO's [identity provider (IdP)](/introduction/idp/) to the finish URI. In order to secure this communication and verify that the redirect indeed emanated from the AS, the AS will provide a hash parameter in the request to the client's callback URI. The client **_must_** verify this hash.
Copy link
Contributor

Choose a reason for hiding this comment

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

the authorization server (AS) will redirect

even though its probably the most common use case, the AS will redirect only if the client provided an interact.finish object.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to add a small section about how the client actually would do verification: by generating the hash using the components below, and comparing it to the provided value in the final redirect


The ASCII encoding of this string is hashed with the algorithm specified in the `hash_method` parameter under the `finish` key of the interaction finish request. The byte array from the hash function is then encoded using Base64 with no padding. The resultant string is the hash value.

Unless specified by the client in the initial request, the `hash_method` will default to `sha-256`. If the client specifies the `hash_method`, the `hash_method` **_must_** be one of the hash name strings defined in the <LinkOut href='https://www.iana.org/assignments/named-information/named-information.xhtml#hash-alg'>IANA Named Information Hash Algorithm Registry</LinkOut>.
Copy link
Contributor

Choose a reason for hiding this comment

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

We can say that Open Payments uses sha-256 only (even though GNAP is more flexible)

Comment on lines 20 to 22
:::tip[Reference implementation]
Rafiki provides a reference <LinkOut href='https://github.com/interledger/rafiki/tree/main/packages/auth'>authorization service</LinkOut> implementation that includes support for integration with an IdP.
:::
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's link to the Rafiki docs?

@mkurapov mkurapov added the type: documentation Improvements or additions to documentation label Dec 3, 2024
@mkurapov mkurapov self-requested a review December 10, 2024 14:42
Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

hash verification doc looks good. I'm wondering if you need to merge in main given we have the other file changes

Comment on lines +43 to +45
## Verifying hash

When the client receives a redirect from the AS, the AS will include the hash parameter in the response. The client must calculate this exact value by concatenating the fields referenced above and then applying the `sha-256` hashing algorithm. If the hash value matches the parameter sent by the AS, then the client can be certain the redirect emanated from the AS.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you think its valuable, we can also add a JS example:

function verifyHash(
  clientNonce,
  interactNonce,
  interactRef,
  authServerUrl,
  receivedHash
) {
  const data = `${clientNonce}\n${interactNonce}\n${interactRef}\n${authServerUrl}/`
  const hash = createHash('sha-256').update(data).digest('base64')

  return hash === receivedHash
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add hash verification documentation
4 participants