-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor KeyManager #204
Refactor KeyManager #204
Conversation
@@ -31,41 +38,81 @@ impl KeyManager for LocalKeyManager { | |||
curve: Curve, | |||
key_alias: Option<String>, | |||
) -> Result<String, KeyManagerError> { | |||
let key_alias = self.key_store.generate_new(curve, key_alias)?; | |||
let private_key = Arc::new(match curve { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI #205 (not necessary for this PR, just raising awareness)
#[error(transparent)] | ||
KeyStoreError(#[from] KeyStoreError), | ||
#[error("{0}")] | ||
InternalKeyStoreError(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts?
InternalKeyStoreError(String), | |
KeyStoreError(String), |
fn import(&self, private_key: Arc<dyn PrivateKey>) -> Result<String, KeyManagerError> { | ||
let key_alias = private_key.alias()?; | ||
self.import_with_alias(private_key, &key_alias)?; | ||
Ok(key_alias) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is clever 👏
Alright a handful of things...
It's a good point... the way I think about it is, the key alias is akin to a primary key in a db, so it's self referential with respect to a key. It's slightly confusing though because we enable callers of key manager methods to override the key alias, so it's a matter which is conceptualized at the key manager level, but at the same time we implement the
Yeah that should be an error. So the requirement is: key's cannot be imported which have a key alias which pre-exist in the key manager. Created #207 @diehuxx feel free to go ahead and do that here or not and we can follow up, your call. |
How is a portable did created without a key exporter? |
It can't. But, TBD. This is a hot topic, so perhaps I'll open a ticket to discuss the full merits. I know this has been discussed at length a while back, but it's appropriate to take a bit of time to reopen the matter with the rust initiative. |
1a125b9
to
040cd90
Compare
Partially addresses #158
Context
The
KeyManager
andKeyStore
traits are fuzzy abstractions -- the conceptual boundary between a "store" and a "manager" is not clear to me.KeyManager
currently seems to be a wrapper aroundKeyStore
with little-to-no added functionality. Also, the traits themselves have methodsexport_private_keys()
andimport_private_keys()
which ought not to be coupled to the notion of "management" which entails storing private keys, signing, and getting public keys. See #158 for more.Design
KeyStore
trait entirely. Move logic from structInMemoryKeyStore
intoLocalKeyManager
.KeyManager
to just three methods:generate_private_key()
,sign()
, andget_public_key()
.KeyImporter
with one required methodimport_with_alias()
and one provided methodimport()
which generates its own alias.This PR does NOT add the
KeyExporter
trait described in #158 because I do not see an immediate use case inweb5-rs
. Exporting private keys is risky stuff. Until we have a clear need for a standard interface for exporting, we ought to omit it.Open questions
.alias()
method in theKey
trait? Is it a unique digest? Whatever it is, we should probably rename the method.KeyImporter
when a key alias is overwritten with a new private key? Should that be an error? Is it up to each individualimpl
ofKeyImporter
? I lean towards the former.