Various road-blocks for implementing a custom KeyStore type
As discussed on IRC earlier today, various downstream consumers of Arti will want to manage their own keys, rather than letting the ArtiNativeKeystore write them to disk.
@gabi-250 suggested to avoid this one could implement a custom struct implementing the Keystore trait. For Gosling, this would be an in-memory only keystore (as key management is left to the library consumer to deal with), whereas for cwtch this could be some translation layer directly to their encrypted sqlite database.
So far I have run into at least these known problems:
- Keystore deals with
dyn EncodableKey; this type is notSend + Syncso they must therefore be encoded/converted somehow in order to be stored in aKeystore(which must beSend + Sync).EncodableKeyprovidesas_ssh_key_data()which isSend + Syncso we can therefore convert them toSshKeyDataobjects for storage. However there seems to be no way to convertSshKeyDataback toEncodableKey.KeyTypehasparse_ssh_format_erased(), but this function ispub(crate)so inaccessible to downstream consumers. Downstream needs one of:- Make
dyn EncodableKeyobjectsSend + Syncso they can just be stored directly - Make the
SshKeyData->EncodableKeymachinery public
- Make
- The Keystore trait has logically non-const methods (
insert,remove) which take immutable&selfreferences. For my memory-backedEphemeralKeystoreI will need mutable reference for these methods to modify the backingHashMap<(ArtiPath, KeyType), Whatever>-
EDIT: the answer to this lies in KeyMgr, the Keystore does indeed need to be atomic + cross process so an
Arc<Mutex<>>internal wrapper is likely the answer here for my use case.
-
EDIT: the answer to this lies in KeyMgr, the Keystore does indeed need to be atomic + cross process so an
- I'm not sure how this is possible, but it seems
KeyMgrBuilder::build()returns aStdResult<KeyMgr, KeyMgrBuilderError>, butKeyMgrBuilderErrordoes not seem to exist anywhere in the source? Guess I'll just ignore the possibility ofbuild()failing for now or just return a generic error in this case? that builder proc-macro is looking a bit sus👀
Please let me know if the problem is just that I'm holding it wrong
/cc @dan
Edited by morgan