Repository navigation
fix: reject an unsupported -hash algorithm instead of printing empty brackets - #1049
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
…brackets
`-hash tacos` is not a hash algorithm, but the text writer only fills in the
value for md5, sha1 and sha256 and still emits its brackets, so the host line
looks like it is missing a fingerprint:
$ tlsx -u 127.0.0.1 -p 18443 -silent -hash tacos
127.0.0.1:18443 []
It also mangles a partially valid list, and an uppercase name is silently
dropped even though it means the same algorithm:
$ tlsx -u 127.0.0.1 -p 18443 -silent -hash md5,tacos
127.0.0.1:18443 [55fc8bad27f4c5425c57e2057744b17f] []
$ tlsx -u 127.0.0.1 -p 18443 -silent -hash md5,,sha1
127.0.0.1:18443 [55fc8bad27f4c5425c57e2057744b17f] [] [c8fe018e782788bc15150a72b8a7070a88d9d5b0]
$ tlsx -u 127.0.0.1 -p 18443 -silent -hash MD5
127.0.0.1:18443 []
Every other enumerated flag rejects a bad value up front instead: `-ct tacos`
answers "invalid value \"tacos\" for flag -ct: allowed values are all,
insecure, secure, weak", `-sm tacos` fails with "scan mode tacos not supported
(supported: ctls, ztls, openssl, auto)" and `-tg ""` with "tls-groups requires
at least one group (...)".
Validate -hash the same way, reusing the existing validate*Flag pattern, so the
run stops before the scan:
$ tlsx -u 127.0.0.1 -p 18443 -silent -hash tacos
FTL cause="hash: unsupported algorithm \"tacos\" (supported: md5,sha1,sha256)" chain="could not read flags"
The check runs after the -config file is merged, so a bad value coming from a
config file is caught too. Valid values are untouched: `-hash md5`,
`-hash sha256` and `-hash md5,sha1,sha256` print exactly what they did before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-hash tacosis not a hash algorithm, but the text writer only fills in a value formd5,sha1andsha256while still emitting the brackets, so the host line looks like it is missing a fingerprint:It also mangles a partially valid list, and an uppercase name is silently dropped even though it names the same algorithm:
Cause
pkg/output/output.gowalks the requested list and only assignsvaluefor the three known names, then prints it unconditionally:Fix
Every other enumerated flag already rejects a bad value before scanning —
-ct tacosanswersinvalid value "tacos" for flag -ct: allowed values are all, insecure, secure, weak,-sm tacosfails withscan mode tacos not supported (supported: ctls, ztls, openssl, auto), and-tg ""withtls-groups requires at least one group (...).-hashnow does the same, using the samevalidate*Flaghelper pattern that-tls-groupsintroduced next to it:The check runs after the
-configfile is merged, so a bad value supplied there is caught as well:Valid values are unchanged —
-hash md5,-hash sha1,-hash sha256and-hash md5,sha1,sha256print exactly what they printed before, and the JSON output still carriesfingerprint_hash.Tests
TestValidateHashFlagincmd/tlsx/main_test.go, followingTestValidateTLSGroupsFlagin the same file: the four accepted forms plustacos,MD5,sha512,md5,tacos,md5,,sha1andmd5,rejected.go test ./...is green andgolangci-lint run ./cmd/...reports0 issues.Summary by CodeRabbit
md5,sha1, andsha256.