Repository navigation
tpm2: fix selector checks in union accessors - #451
Merged
Merged
Conversation
ACTData, KDF1SP80056A, KDF2, KDF1SP800108 and TPMUAsymScheme.ECDH compared the union selector against the wrong constant, so they returned an error for the member they are named after (and could panic on the type assertion when the selector matched the wrong constant). Also fix the error messages of KDF2, ECDSA and ECDAA, which named another member. Fixes google#389
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.
Fixes #389.
TPMUAsymScheme.ECDH()compared the selector againstTPMAlgRSASSA. The same copy-paste mistake is in four more union accessors intpm2/structures.go, so this fixes them together:TPMUCapabilities.ACTData()checkedTPMCapAuthPoliciesinstead ofTPMCapACTTPMUKDFScheme.KDF1SP80056A(),KDF2()andKDF1SP800108()checkedTPMAlgMGF1TPMUAsymScheme.ECDH()checkedTPMAlgRSASSAEach of them returned an error for the member it is named after, and panicked on the type assertion when the selector was the wrong constant (for example
KDF2()on an MGF1 scheme). The error messages ofKDF2(),ECDSA()andECDAA()also named another member (mgf1,rsassa); those are fixed too.OAEP()is not touched.TestUnionAccessorsin the newtpm2/structures_test.gobuilds each union with its own selector and calls the accessor; all five cases fail onmain, and theWrongMembercase panics there.go test ./...,go vet ./tpm2/andgofmtpass.