8000 add basic support for dgst hmac in tool by samuel40791765 · Pull Request #1755 · aws/aws-lc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add basic support for dgst hmac in tool #1755

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

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

samuel40791765
Copy link
Contributor
@samuel40791765 samuel40791765 commented Aug 9, 2024

Issues:

Resolves CryptoAlg-2602

Description of changes:

OpenSSL's hmac command line tool uses dgst with a -hmac option. Supporting the entire functionality of dgst will take a bit more work, but we can support -hmac with the default SHA256 for the time being.

Call-outs:

Rearranged some of the header file function calls to make things cleaner

Testing:

Basic functionality tests against single and multiple /tmp files.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@samuel40791765 samuel40791765 force-pushed the tool-hmac branch 3 times, most recently from 5d8c8e4 to cd43457 Compare August 12, 2024 22:57
@samuel40791765 samuel40791765 marked this pull request as ready for review August 12, 2024 23:01
@samuel40791765 samuel40791765 requested a review from a team as a code owner August 12, 2024 23:01
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 5.78512% with 114 lines in your changes missing coverage. Please review.

Project coverage is 78.32%. Comparing base (94f021b) to head (bebd895).
Report is 1 commits behind head on main.

Files Patch % Lines
tool-openssl/dgst.cc 0.00% 68 Missing ⚠️
tool-openssl/dgst_test.cc 13.20% 46 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1755      +/-   ##
==========================================
- Coverage   78.46%   78.32%   -0.14%     
==========================================
  Files         580      582       +2     
  Lines       96779    96906     +127     
  Branches    13865    13884      +19     
==========================================
- Hits        75936    75902      -34     
- Misses      20226    20381     +155     
- Partials      617      623       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 93 to 94
awslc_hash = trim(awslc_hash);
openssl_hash = trim(openssl_hash);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's with the trims? Do we have differing whitespace?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also how does this work if there are two files getting hashed? Is this only comparing the output of one of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was due to different OpenSSL versions having different outputs, but now that you mention it I don't think it applies here. Will change.
Also a reminder that I forgot to add these tests to the test script.

for (;;) {
size_t n;
if (!ReadFromFD(fd, &n, buf.get(), kBufSize)) {
fprintf(stderr, "%s: No such file or directory\n", filename.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

NP: There was an error reading from the file, which doesn't necessarily mean that there's "no such file". (Could you even read from a directory?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh this was to align with OpenSSL's error messaging, I don't really enjoy it either.. I'm conflicted on compatibility everywhere or better error messages in general.
I can change this to my original error message which also prints the errno. It's not really a 1 way door and we can change to align if we get complaints.

}

// Print HMAC output.
fprintf(stdout, "HMAC-%s(%s)= ", EVP_MD_get0_name(digest),
Copy link
Contributor

Choose a reason for hiding this comment

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

NP: This would display the full path. Is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's expected. OpenSSL's output example:

aws-lc on  main [?] via △ v3.20.0 via  v1.21.3 
❯ openssl dgst $PWD/../bio_test
SHA256(/Users/sachiang/Documents/repo/aws-lc/../bio_test)= 28176a1f8de724adeb381febacf90595715b55a15294c14c24a3e5f96ced04dc

fprintf(stderr, "Unknown option '%s'.\n", option.c_str());
return false;
}
} else {
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 this else block is only hit when arg.empty() -- I'm not sure the error message below this applies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention was to hit this if arg[0] != '-'. But true, that it doesn't really apply if arg.empty(). Will reconfigure this.

@@ -39,10 +39,7 @@ declare -A openssl_branches=(
export AWSLC_TOOL_PATH="${BUILD_ROOT}/tool-openssl/openssl"
for branch in "${!openssl_branches[@]}"; do
export OPENSSL_TOOL_PATH="${install_dir}/openssl-${branch}/bin/openssl"
LD_LIBRARY_PATH="${install_dir}/openssl-${branch}/${openssl_branches[$branch]}"
for test in X509ComparisonTest RSAComparisonTest MD5ComparisonTest; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, this is much simpler to add more tests in the future automatically.

@samuel40791765 samuel40791765 merged commit 9178c62 into aws:main Aug 13, 2024
104 of 106 checks passed
@samuel40791765 samuel40791765 deleted the tool-hmac branch August 13, 2024 23:03
samuel40791765 added a commit to samuel40791765/aws-lc that referenced this pull request 8000 Aug 14, 2024
OpenSSL's hmac command line tool uses `dgst` with a `-hmac` option.
Supporting the entire functionality of `dgst` will take a bit more work,
but we can support `-hmac` with the default `SHA256` for the time being.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.

(cherry picked from commit 9178c62)
samuel40791765 added a commit that referenced this pull request Aug 15, 2024
OpenSSL's hmac command line tool uses `dgst` with a `-hmac` option.
Supporting the entire functionality of `dgst` will take a bit more work,
but we can support `-hmac` with the default `SHA256` for the time being.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.

(cherry picked from commit 9178c62)
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.

4 participants
0