Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

fix: correctly encode bytes for V2 signature - #382

Merged
tritone merged 3 commits into
googleapis:masterfrom
tritone:signed-url-fix
Feb 17, 2021
Merged

fix: correctly encode bytes for V2 signature#382
tritone merged 3 commits into
googleapis:masterfrom
tritone:signed-url-fix

Conversation

@tritone

Copy link
Copy Markdown
Contributor

V2 signature was passing a string to the sign_bytes function
instead of bytes. This works fine for most credentials (since
their sign_bytes implementations accept strings) but not for
impersonated credentials. V4 signature encodes the string before
calling sign_bytes, so I do the same here.

We should also look into clarifying the contract for the
sign_bytes interface in the auth library.

Fixes#373

V2 signature was passing a string to the sign_bytes function
instead of bytes. This works fine for most credentials (since
their sign_bytes implementations accept strings) but not for
impersonated credentials. V4 signature encodes the string before
calling sign_bytes, so I do the same here.
We should also look into clarifying the contract for the
sign_bytes interface in the auth library.
Fixesgoogleapis#373
@tritone
tritone requested review from a teamFebruary 17, 2021 03:30
@product-auto-labelproduct-auto-labelBot added the api: storage Issues related to the googleapis/python-storage API. label Feb 17, 2021
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Feb 17, 2021
"""
ensure_signed_credentials(credentials)
signature_bytes = credentials.sign_bytes(string_to_sign)
signature_bytes = credentials.sign_bytes(string_to_sign.encode("ascii"))

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@frankynfrankyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change LGTM.

Opnion: Issue here is that we have multiple sign versions and we focused on v4 more recently.

@tritone
tritone merged commit f44212b into googleapis:masterFeb 17, 2021
@tritone
tritone deleted the signed-url-fix branch February 17, 2021 19:01
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
* fix: correctly encode bytes for V2 signature
V2 signature was passing a string to the sign_bytes function
instead of bytes. This works fine for most credentials (since
their sign_bytes implementations accept strings) but not for
impersonated credentials. V4 signature encodes the string before
calling sign_bytes, so I do the same here.
We should also look into clarifying the contract for the
sign_bytes interface in the auth library.
Fixesgoogleapis#373
* fix py2 failure
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
* fix: correctly encode bytes for V2 signature
V2 signature was passing a string to the sign_bytes function
instead of bytes. This works fine for most credentials (since
their sign_bytes implementations accept strings) but not for
impersonated credentials. V4 signature encodes the string before
calling sign_bytes, so I do the same here.
We should also look into clarifying the contract for the
sign_bytes interface in the auth library.
Fixesgoogleapis#373
* fix py2 failure
@release-pleaserelease-pleaseBot mentioned this pull request Jan 12, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storageIssues related to the googleapis/python-storage API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

It's impossible to generate a signed url (v2) with impersonated Credentials

2 participants

@tritone@frankyn