Draft: Add key listing functionality, replace placeholder subcredentials with values from keystore
I'm opening this MR to get some early feedback on these APIs. The code is a bit rough around the edges, and it's missing some tests.
This adds some new keymgr APIs for listing keys (Keystore::list()), and for searching for keys that match a given pattern (KeyMgr::list_matching()).
Some important points to note:
-
Note that the
KeyMgrAPIs don't support looking keys up byArtiPath/CTorPath. To retrieve a key you currently need:- a
dyn KeySpecifierthat identifies the key1 - to know the concrete type of key you are retrieving (specified via the
Ktype parameter)
- a
-
To use
KeyMgr::list_matching(), you need to specify aKeyPathPatternSet, which contains 2 patterns: one for matchingArtiPaths, and one forCTorPaths.KeyMgr::list_matching()will return all theArtiPaths/CTorPaths that match the specified patterns (if multiple keystores are configured, you will potentially get results from multiple backends). The caller is responsible for parsing the resultingArtiPaths/CTorPaths and constructing thedyn KeySpecifiers that can then be used to look up keys. -
I've decided against making
ArtiPathitself optionally contain wildcards because:- Making
ArtiPathoptionally contain wildcards means changing all keymgr APIs to return/accept multiple keys rather than just one (e.g.get()will returnVec<K>rather than justK, etc.). However, most of the time you want to retrieve/remove/insert a single key, so changing the API this way would make theKeyMgroverall less ergonomic - Even if we provide a separate
get_matchingAPIs for batch retrieval, it still wouldn't work very well, because the wildcards would allow you to select multiple keys, of potentially different types, and the type system doesn't allow us to return an arbitrary number of keys of arbitrary types (KeyMgr::getwants to know the typeKof the key being retrieved). That being said, we can provide aremove_matchingAPI.
- Making
-
the
list_matchingAPI returns the capture groups of the pattern being matched. These are needed for parsingArtiPaths/CTorPaths asHsSvcKeySpecifiers. The resultingTryFroms forHsSvcKeySpecifierare pretty ugly -- maybe we need a fundamentally different approach here?
I've also tried to address the TODO HSS BLOCKER in ipt_establish.rs using these new APIs. See d45630d4
-
KeySpecifierreally just specifies theArtiPathand/orCTorPathof the key, so technically we could adapt these APIs to work withArtiPath/CTorPaths, but that would involve rethinking some of the ArtiNativeKeystore logic, as it currently quite strongly assumesKeySpecifier::arti_path()will return a valid path. We could, for example, implementKeySpecifierforArtiPathandCTorPath, and make bothKeySpecifier::arti_path()andKeySpecifier::ctor_path()return aResult/Option. But then we will need to giveKeyMgrsome sort of way of deciding whether the requesteddyn KeySpecifiercan be used with any of itsdyn Keystores (e.g. if we implKeySpecifier for CTorPath, we can't use this specifier withArtiNativeKeyStoreas itsarti_pathimpl will return anErr)↩