feat(credentials): add CCache.Marshal and v4 builders - #94
Open
hstern wants to merge 3 commits into
Open
Conversation
Add CCache.Marshal (the inverse of Unmarshal) plus NewV4CCache, AddCredential, SetDefaultPrincipal and NewPrincipal helpers, with a byte-exact round-trip test against the existing ccache test vector. Revives jcmturner/gokrb5#423 by @kula, ported to the go-krb5/krb5 tree as new files so no existing code changes. Signed-off-by: Henry Stern <henry@stern.ca>
The version-3 keyblock encodes the key type as two 16-bit integers (matching parseCredential), not a 16-bit value followed by a 32-bit one. Without this, Marshal was not a true inverse of Unmarshal for v3 caches. Add TestMarshalRoundTripV3, which builds a v3 cache and asserts its bytes survive an Unmarshal/Marshal round trip with the key type intact. Signed-off-by: Henry Stern <henry@stern.ca>
writeCredential wrote TicketFlags.Bytes verbatim, but parseCredential reads a fixed 4 bytes. A caller-built Credential with unset flags (nil Bytes) emitted zero bytes, shifting every following field by four so the parser read a garbage authorization-data count and panicked in readAuthDataEntry on Unmarshal. Always emit 4 bytes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Adds
CCache.Marshal()— the inverse ofUnmarshal()— plus v4 constructionhelpers (
NewV4CCache,AddCredential,SetDefaultPrincipal,NewPrincipal).Lands as two new files (
credentials/ccache_marshal.go,ccache_marshal_test.go);no existing files are changed.
Why
The library can read credential caches but not write them; marshalling is needed
to issue/persist ccaches programmatically.
Relationship to jcmturner/gokrb5#423
This revives @kula's stalled #423 (original maintainer inactive ~3 years), ported
to the current go-krb5/krb5 tree. It is not a verbatim port — it includes two
changes from the original:
a 16-bit value followed by a 32-bit value, but
parseCredentialreads it astwo 16-bit integers. As written,
Marshalwas therefore not a true inverseof
Unmarshalfor v3 caches. This PR writes two 16-bit integers to match theparser.
formatting, and splitting
writeCredentialinto smaller helpers).Test
TestMarshalRoundTripdecodes the existingtestdata.CCACHE_TEST(v4) vector,Unmarshals it,Marshals it back, and asserts the bytes are identical — abyte-exact round trip.
TestMarshalRoundTripV3builds a v3 cache and asserts its bytes survive anUnmarshal/Marshalround trip with the key type intact (there is no v3 testvector upstream, so this is built in memory). This guards the v3 keyblock fix
above.