Repository navigation
tls: kTLS reads each traffic secret where BoringSSL wrote its key-log line, and the JVM's HMAC leaves no copy of it (#45) - #56
Merged
Conversation
… line, and the JVM's HMAC leaves no copy of it (#45) The keylog callback made Strings of the line, its hex and that trimmed, which stay on the heap until collected and overwritten, after the ByteArray Ktls zeroes. It now compares the labels and decodes the hex from the line's own bytes, allocating nothing but the secret's array. BoringSsl.cString leaves the shared API with its only common caller; each target keeps it for error strings and cipher names. On the JVM, hmacSha256 went through Mac and SecretKeySpec, which keep the key and both HMAC pads on the heap. It now calls BoringSSL's HMAC as the native target does, on the arrays themselves through a critical downcall, as SSL_write from a heap array already does.
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.
Closes #45.
The issue lists three ways a traffic secret outlives the zeroing in
Ktls.kt. Two are real, and this fixes them.Strings of the key-log line.
onKeylogmade aStringof BoringSSL's line, then a substring of its hex and a trimmed copy of that, all immutable and left on the heap until collected and overwritten. It now compares the two labels and decodes the hex from the line's own bytes, as MDA2AV/ioxide#561 does, so the secret'sByteArrayis all it allocates.BoringSsl.cStringleaves the shared API with its only common caller; each target keeps it private, for error strings and cipher names.The JVM's HMAC.
hmacSha256went throughMacandSecretKeySpec. It now calls BoringSSL'sHMAC, as the native target does, on the arrays themselves through a critical downcall, asSSL_writefrom a heap array already does. So nothing copies the key. I checked both with a heap dump taken after the caller zeroed a random key, 3 runs each:Mac+SecretKeySpec: the key once (SecretKeySpec's copy), pluskey^ipadandkey^opad, the HMAC pads, which give the key back.HMAC: none of the three.Zeroing before
free: not real, left as is. In a release build from this branch,Ktls.programstill zeroes the key, the nonce and the secret (threememsetcalls) and the crypto info (an out-of-linezeroMemorycall) before eachfree.Tests.
KtlsSecretTest(common): a key-log line decodes to its secret in either case, with or without a newline, and a last word that isn't whole hex gives none.hmacSha256gives RFC 4231 test cases 1 and 2, so the JVM's new path is checked too.KeylogAllocationTest(JVM): decoding allocates nothing but the secret's array. With theStringparse back, it fails at 528 bytes.