Skip to content

http_sig_examples: generate the content-digest dynamically for test messages #2

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

Closed

Conversation

bobby-stripe
Copy link

related to: httpwg/http-extensions#2049

This change ensures that the content digest and content length headers are always derived from the body.

The test cases in the file continue to verify, and the 1 changed checksum is verifiable with:

$ echo -n '{"message": "good dog"}' | sha512sum | cut -d ' ' -f 1 | xxd -r -p | base64
mEWXIS7MaLRuGgxOBdODa3xqM1XdEvxoYhvlCFJ41QJgJc4GTsPp29l5oGX69wWdXymyU0rjJuahq4l5aGgfLQ==

cc @jricher

…essages

related to: httpwg/http-extensions#2049

I'm not sure what the current digest is, but it doesn't match the 23-byte HTTP body of that message.
We can verify the expected/new digest with:

$ echo -n '{"message": "good dog"}' | sha512sum | cut -d ' ' -f 1 | xxd -r -p | base64
mEWXIS7MaLRuGgxOBdODa3xqM1XdEvxoYhvlCFJ41QJgJc4GTsPp29l5oGX69wWdXymyU0rjJuahq4l5aGgfLQ==
Copy link
Collaborator

@jricher jricher left a comment

Choose a reason for hiding this comment

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

Thanks for this! This approach does get the job done, but I think it might make more sense to calculate the body hash after the message is parsed into components, or as part of the component processing step. This code will be helpful in pulling that together, regardless of which direction it goes. Thank you again!

exampleRequestMessage = b"""POST /foo?param=Value&Pet=dog HTTP/1.1
def addContentDigest(message, body):
b64Digest = base64.b64encode(SHA512.new(body).digest()).decode('utf-8')
contentDigest = "sha-512=:%s:" % b64Digest
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency with the rest of the script, this should use the http_sfv library primitives to create the value instead of string substitution.

@bobby-stripe
Copy link
Author

the reason I did it this way (And I should have added this in the PR description) was to ensure that the line wrapped test messages that I think get copied over from here into the spec had the right Content-Digest on them.

I think thats a great current feature of the spec -- where you can literally copy/paste the example out of the spec, slap on the signature-input and signature headers (also copy/pasted out of the spec), and pass it into a a 'verify' function. Are you planning on keeping things that way @jricher or will people implementing the spec also have to generate/add a Content-Digest to get the sigs to pass?

@jricher
Copy link
Collaborator

jricher commented Mar 30, 2022

@bobby-stripe oh the examples will remain complete still, they'll just be stitched together. That already happens with several of the examples that have generated Signature and Signature-Input headers. If you run the scripts you'll see that it spits out these lines separately with several different kinds of wrapping.

@jricher jricher closed this Mar 30, 2022
@jricher
Copy link
Collaborator

jricher commented Mar 30, 2022

One of the other considerations I had here is that we're planning to add this functionality to bspk/httpsig-org (https://httpsig.org) as well, and so modularizing the generator in a way that works with the rest of the component parsing system was a priority for me.

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