Bug 49450 - KeyStoreResolver always exhausted after first use
Summary: KeyStoreResolver always exhausted after first use
Alias: None
Product: Security - Now in JIRA
Classification: Unclassified
Component: Encryption (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: XML Security Developers Mailing List
Depends on: 49447
  Show dependency tree
Reported: 2010-06-16 15:33 UTC by Clement Pellerin
Modified: 2010-06-17 09:27 UTC (History)
0 users

proposed source code patch with junit (5.45 KB, patch)
2010-06-16 15:35 UTC, Clement Pellerin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Clement Pellerin 2010-06-16 15:33:04 UTC
The KeyStoreResolver creates an iterator once and always returns the same iterator afterwards. After the iterator is traversed once, it will always appear empty. Even if the implementation would be changed to reset the alias enumeration to the beginning, the single iterator instance approach will never be thread-safe.

To reproduce, run the KeyStoreResolverTest in attachment.

The solution is to return a new iterator instance each time.
This patch is built on top of the patch found in Bug 49447.
This patch also fixes a bug with the NoSuchElementException that was introduced in the patch attached to 49447.
Comment 1 Clement Pellerin 2010-06-16 15:35:20 UTC
Created attachment 25600 [details]
proposed source code patch with junit
Comment 2 coheigea 2010-06-17 09:27:38 UTC
Patch applied, thanks. I modified it slightly so that the KeyStoreResolver checks the KeyStore in the constructor, and throws a StorageResolverException if there is a problem. This is for backwards compatiblity reasons.