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
KeyMgr
APIs don't support looking keys up byArtiPath
/CTorPath
. To retrieve a key you currently need:- a
dyn KeySpecifier
that identifies the key1 - to know the concrete type of key you are retrieving (specified via the
K
type parameter)
- a
-
To use
KeyMgr::list_matching()
, you need to specify aKeyPathPatternSet
, which contains 2 patterns: one for matchingArtiPath
s, and one forCTorPath
s.KeyMgr::list_matching()
will return all theArtiPath
s/CTorPath
s 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 resultingArtiPath
s/CTorPath
s and constructing thedyn KeySpecifier
s that can then be used to look up keys. -
I've decided against making
ArtiPath
itself optionally contain wildcards because:- Making
ArtiPath
optionally 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 theKeyMgr
overall less ergonomic - Even if we provide a separate
get_matching
APIs 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::get
wants to know the typeK
of the key being retrieved). That being said, we can provide aremove_matching
API.
- Making
-
the
list_matching
API returns the capture groups of the pattern being matched. These are needed for parsingArtiPath
s/CTorPath
s asHsSvcKeySpecifier
s. The resultingTryFrom
s forHsSvcKeySpecifier
are 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
-
KeySpecifier
really just specifies theArtiPath
and/orCTorPath
of 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, implementKeySpecifier
forArtiPath
andCTorPath
, and make bothKeySpecifier::arti_path()
andKeySpecifier::ctor_path()
return aResult
/Option
. But then we will need to giveKeyMgr
some sort of way of deciding whether the requesteddyn KeySpecifier
can be used with any of itsdyn Keystore
s (e.g. if we implKeySpecifier for CTorPath
, we can't use this specifier withArtiNativeKeyStore
as itsarti_path
impl will return anErr
)↩