Repository navigation
fix(helper): adopt keystore updates only after the write succeeds - #525
Merged
Merged
Conversation
storePrivateKeyEntry and storeAuthorityEntry changed the live in-memory KeyStore before flushing it. If the flush failed, the change stayed in memory and the next successful write persisted it, and an entry that couldn't be serialized made every later write fail. Route every update through one path that copies the live store, applies the change to the copy, writes it and only then adopts it, the same way replaceAuthorityEntries already did. Files are still written in place. Add JKS and PKCS12 tests that inject write and serialization failures and check that the live store, other trust domains and the private key survive and that the next update works. Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
Two overlapping updates could write one candidate to the file and keep the other as the live store. Hold the instance lock for the whole copy, write and assignment. Signed-off-by: Srinivas Chippagiri <cvas22@gmail.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.
Part of #490
#492 already stages the trust bundle replacement in a copy and adopts it after the flush, but
storePrivateKeyEntryandstoreAuthorityEntrystill changed the live KeyStore first. If the write failed, the change stayed in memory and the next successful write persisted it. An entry that can't be serialized was worse, it stayed in the live store and made every later write fail.I moved all three methods onto one
updatepath: copy the live store, apply the change to the copy, flush it, and only then swap it in. Files are still written in place like before, so the temp file and rename question from #520 stays out of this, and an I/O error or crash mid-write is still open under #490.Tests run on JKS and PKCS12. They break the write by swapping the file for a directory, or break serialization with a cert that can't be encoded, then check the live store kept its entries, the other trust domains and the private key are still there, and the next update goes through. Also updated the README note and the changelog.