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

HTTP Digest authentication support #131

Merged
merged 66 commits into from
Jun 19, 2024
Merged

Conversation

jameshilliard
Copy link
Contributor

This is basically just #111 cherry-picked with merge conflicts fixed and POST Digest Authentication fixed.

@codecov-io
Copy link

codecov-io commented Aug 1, 2016

Codecov Report

Merging #131 into master will decrease coverage by 0.93%.
The diff coverage is 88.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
- Coverage   98.86%   97.92%   -0.94%     
==========================================
  Files          26       26              
  Lines        2285     2510     +225     
  Branches      165      183      +18     
==========================================
+ Hits         2259     2458     +199     
- Misses         14       32      +18     
- Partials       12       20       +8
Impacted Files Coverage Δ
src/treq/test/test_treq_integration.py 96.56% <100%> (+1.27%) ⬆️
src/treq/test/test_auth.py 100% <100%> (ø) ⬆️
src/treq/auth.py 84.65% <82.46%> (-15.35%) ⬇️
src/treq/client.py 98.47% <0%> (+0.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d45c82...e0d7208. Read the comment docs.

treq/auth.py Outdated
return hashlib.sha1(x).hexdigest()


def build_digest_authentication_header(agent, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be public, if it needs to share data with the agent it should probably just be a private method on the agent.

@dreid
Copy link
Contributor

dreid commented Sep 9, 2016

The tests fail on Python 3, looks like you're trying to use a str as the header instead of a bytes.

…equestDigestAuthenticationAgent without kwargs
@jameshilliard
Copy link
Contributor Author

@dreid How would I got about fixing the issue with the header being a str instead of bytes? I'm having trouble debugging that.

treq/auth.py Outdated
# We support only "auth" QoP as defined in rfc-2617 or rfc-2069
raise UnknownQopForDigestAuth(digest_authentication_params['qop'])
digest_authentication_header = self._build_digest_authentication_header(
self,
Copy link
Contributor

Choose a reason for hiding this comment

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

This self (and the agent argument in _build_digest_authentication_header are redundant.

@dreid
Copy link
Contributor

dreid commented Sep 11, 2016

@jameshilliard

How would I got about fixing the issue with the header being a str instead of bytes? I'm having trouble debugging that.

Start by using byte strings (b"") everywhere internally.

@jameshilliard
Copy link
Contributor Author

@dreid I think I've got everything converted to using byte strings, now I'm getting 401 errors instead(I verified against a production server to confirm it's not just the tests that are failing) for python 3. Any idea what might be causing authentication to fail?

@jameshilliard
Copy link
Contributor Author

Sorry, I still have a few concerns about security here that I want to make sure are addressed in a comment or something.

I refactored the header builder based on the latest version in requests so it shouldn't be any worse than that version and appears to be unlikely to be a viable attack vector in practice here in general.

And we should really avoid adding new magic byte sequences without an accompanying Enum somewhere so that callers can type-check their invocations.

I changed algorithm to use an Enum.

@jameshilliard
Copy link
Contributor Author

@glyph Merge conflicts fixed.

@glyph
Copy link
Member

glyph commented May 2, 2023

Thanks for updating this @jameshilliard !

@jameshilliard
Copy link
Contributor Author

@glyph Is this good to merge now?

Copy link
Member

@glyph glyph left a comment

Choose a reason for hiding this comment

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

I think we are (finally? after the better part of a decade? 😮‍💨) good to land this, modulo that one public name.

src/treq/auth.py Outdated Show resolved Hide resolved
src/treq/auth.py Outdated Show resolved Hide resolved
@glyph
Copy link
Member

glyph commented Jun 19, 2024

I think I'm going to accept a bit of a coverage hit here but I want to make sure I get an accurate sense of what the coverage hit is, so I'm going to attempt to re-run the tests on trunk (which involves a fake empty commit and a force push because you can't re-run workflow jobs after 30 days).

@glyph
Copy link
Member

glyph commented Jun 19, 2024

OK I am not sure what codecov thinks the base commit is but I'm not going to spend any more time on this. Allons y

@glyph glyph merged commit 22a776d into twisted:trunk Jun 19, 2024
16 checks passed
@glyph
Copy link
Member

glyph commented Jun 19, 2024

Oh. The repo was deactivated. Well, coverage will have to come later.

@glyph
Copy link
Member

glyph commented Jun 19, 2024

(It's reactivated now.)

@jameshilliard jameshilliard deleted the HTTPDigestAuth branch June 19, 2024 00:53
twm added a commit that referenced this pull request Jul 1, 2024
This reverts commit 22a776d, reversing
changes made to c9f0bae.

Per 2024-06-28 discussion in #twisted on libera.chat and post-merge
review comments on GitHub [1], this implementation doesn't look spec
compliant.

[1]: 22a776d#diff-14b7fa3002098fc55f2cdf2bf01a0039eb02598ae1e852170183d5935f4ef4d0R369
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.

6 participants