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

fix: use url-safe b64 encoding in deep links #580

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

genaris
Copy link
Contributor

@genaris genaris commented Jul 11, 2024

I'm not sure if it already works well in your BC Wallet, but in our app we are using Credo to parse the DIDComm out-of-band invitation and it was failing, since it expects to have only base64url characters. This comes from Aries RFC 0268, which talks about "base64url-encoded invitation". This Base 64 encoding with an URL and filename safe alphabet is defined in https://datatracker.ietf.org/doc/html/rfc4648#section-5.

So I fixed it by simply using urlsafe_b64encode instead of regular b64encode for _url or c_i parameter.

I didn't test it in BC Wallet, but if it is using Credo as well I don't see why it wouldn't work 🤔 .

@genaris genaris force-pushed the fix/base64url-deeplinks branch from 8ab0d7a to 14f9ac7 Compare July 11, 2024 21:32
Copy link
Contributor

@loneil loneil left a comment

Choose a reason for hiding this comment

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

Ah yes good call. Wasn't failing for the BC gov cases (on local dev or our deployed environments) but I think should definitely be the url-safe format for all uses.

Tried locally with these changes and it's good for me. Note about string format flake failure in code comment below.

Comment on lines 165 to 174
if settings.USE_URL_DEEP_LINK:
suffix = (
f'_url={base64.b64encode(url_to_message.encode("utf-8")).decode("utf-8")}'
f'_url={base64.urlsafe_b64encode(
url_to_message.encode("utf-8")).decode("utf-8")}'
)
else:
suffix = f'c_i={base64.b64encode(formated_msg.encode("utf-8")).decode("utf-8")}'
suffix = (
f'c_i={base64.urlsafe_b64encode(
formated_msg.encode("utf-8")).decode("utf-8")}'
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The flake8 unterminated string literal error here also crops as a runtime on my docker setup

image

I'm kind of confused as I thought parenthesis with multi-line like this should work... maybe it's the { group breaking across multiple lines.

I made it work locally with triple quote

    # BC Wallet deep link
    if settings.USE_URL_DEEP_LINK:
        suffix = f"""_url={base64.urlsafe_b64encode
                           (url_to_message.encode("utf-8")).decode("utf-8")}"""
        suffix = f"""c_i={base64.urlsafe_b64encode(
                formated_msg.encode("utf-8")).decode("utf-8")}"""

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip! I think it is OK now.

Copy link
Contributor

@loneil loneil left a comment

Choose a reason for hiding this comment

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

👍

@loneil loneil merged commit 14ce368 into openwallet-foundation:main Jul 12, 2024
3 checks passed
@genaris genaris deleted the fix/base64url-deeplinks branch July 12, 2024 17:46
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.

2 participants