Commit Graph

23 Commits

Author SHA1 Message Date
Ian Jackson 8596d42372 tor-keymgr, tor-hsservice: deser for ArtiPathComponent and HsNickname 2023-08-23 15:35:30 +01:00
Ian Jackson 9df82bb948 tor-keymgr: Improve ArtiPathComponent a bit
And add a TODO about the error type.
2023-08-23 15:29:46 +01:00
Gabriela Moldovan c8999f230b
tor-keymgr: Re-export ssh-key.
The `KeypairData` type from [ssh-key] at some point leaked into the
keymgr API (via the `EncodableKey` trait). Instead of re-exporting just
`KeypairData`, let's re-export the entire `ssh_key` crate
(`EncodableKey` implementors would need additional types from `ssh_key`
to construct a `KeypairData` object anyway).

[ssh-key]: https://crates.io/crates/ssh-key
2023-08-16 10:44:14 +01:00
Gabriela Moldovan e89e76f974
keymgr: Remove KeyType::to_ssh_format.
This function isn't actually needed (it's not the responsibility of
`KeyType` to encode keys).

This commit also rewrites `ArtiNativeKeystore::insert` to use the new
`as_ssh_keypair_data` function instead of `to_ssh_format`.
2023-08-02 14:21:02 +01:00
Gabriela Moldovan e70be1353c
keymgr: Replace EncodableKey::to_bytes() with SSH-specific function.
The `EncodableKey::to_bytes` function didn't make much sense, because
not all keys have a canonical byte representation.

This commit replaces `EncodableKey::to_bytes` with
`EncodableKey::as_ssh_keypair_data`. In the future, `EncodableKey` will
grow functions for encoding keys in other storage formats too.

Closes #965
2023-08-02 14:13:18 +01:00
Nick Mathewson 1e96d1b95a Remove semver.md files now that 1.1.7 is out. 2023-08-01 12:55:52 -04:00
Gabriela Moldovan f96298a791
keymgr: Add KeyMgr::generate() for generating new keys. 2023-07-24 13:17:31 +01:00
Gabriela Moldovan 9c326ced81
keymgr: Add function for generating EncodableKeys. 2023-07-24 13:17:23 +01:00
Gabriela Moldovan e36e7db6e7
keymgr: Add a Keystore::contains accessor. 2023-07-24 13:17:05 +01:00
Gabriela Moldovan 98337afec9
Revert "keymgr: Require callers to be explicit about which keystore to get keys from."
This reverts commit 38a6c74c78.

This also updates some tests to make them compile with the reverted
version of the code.
2023-07-21 12:21:36 +01:00
Gabriela Moldovan 9d818f164b
keymgr: Require callers to be explicit about where to remove keys from.
As with `KeyMgr::insert`, only `KeystoreSelector::Id` and
`KeystoreSelector::Default` are supported.
2023-07-20 19:25:12 +01:00
Gabriela Moldovan 79c382ff50
keymgr: Add EncodableKey::to_bytes for encoding keys.
We'll need this to implement `Keystore::insert`.
2023-07-20 19:25:04 +01:00
Gabriela Moldovan 483bb6712d
keymgr: Add some extra derives to ArtiPath and KeyType. 2023-07-20 19:25:01 +01:00
Gabriela Moldovan 38a6c74c78
keymgr: Require callers to be explicit about which keystore to get keys from. 2023-07-20 19:24:57 +01:00
Gabriela Moldovan 8b0b8785f4
keymgr: Remove unimplemented/unnecessary has_key_bundle function.
The concept of a "key bundle" would introduce a lot of complexity while
providing little to no gain.

Some context:
```
Originally, "key bundles" were meant to be the answer to the question
"which keystore should insert place keys in?":
36606a66dd/crates/tor-keymgr/src/mgr.rs (L60-69)
However, I'm not so sure anymore that "key bundles" are the answer. I
don't think there is any way we can "guess" where a key should go. When
inserting/generating a new key, we should either:

always write to the same, primary key store, OR require the user to be
explicit about which key store the new key should go in (by assigning an
ID to each key store and expecting the user to provide it when
inserting/generating new keys)

I prefer the latter option, because it provides more flexibility, which
we're going to need when implementing the key management CLI (which I
think should allow users to generate keys anywhere they want, e.g. arti
keymgr generate <key type> --keystore hsm ...)
```

For more details, see the discussion on #903.

Closes #903
2023-07-20 19:24:44 +01:00
Gabriela Moldovan 0b20806213
keymgr: Require callers to specify which keystore to insert keys in.
The caller uses `KeystoreSelector` to specify which keystore to insert
the new key into (only `KeystoreSelector::Id` and
`KeystoreSelector::Default` are supported for `insert`).

The ability to insert keys in a particular keystore will come in handy
when we implement the key management CLI (the CLI will have an option
for specifying the keystore to access/modify).
2023-07-20 19:24:29 +01:00
Gabriela Moldovan 6ec1b55938
keymgr: Add a convenience function for boxing keystore errors. 2023-07-20 19:24:19 +01:00
Gabriela Moldovan cf038fb772
keymgr: Add type for specifying which keystore to access. 2023-07-20 19:24:12 +01:00
Gabriela Moldovan 04379dcae6
keymgr: Add an `id` function to `Keystore`.
This will enable the `KeyMgr` to look up `Keystore`s by ID (which is
a requirement for disambiguating the semantics of `insert`, which
currently tries to "guess" which keystore it should be using).
2023-07-20 19:24:05 +01:00
Gabriela Moldovan 9f5974fb7f
keymgr: Explicitly specify the default keystore for `KeyMgr`. 2023-07-20 19:23:58 +01:00
Gabriela Moldovan ac93b1aef6
keymgr-config: Make fields private, add function for checking if keystore is enabled.
Hiding the underlying value of `enabled` enables us to give it a
different `auto` value depending on whether the `keymgr` feature is
enabled or not (it defaults to `true` if `keymgr` is enabled, and
`false` otherwise).
2023-07-20 19:23:48 +01:00
Gabriela Moldovan d8299e8d2f
tor-keymgr: Add ArtiNativeKeystoreConfig.
Previously, the keystore config consisted of a single field in
`StorageConfig`, which encoded 2 bits of information: whether the
keystore is enabled, and its root directory:
```
[storage]
# use this path, fail if compiled out
# keystore = "/path/to/arti/keystore"
#
# use default path, fail if compiled out
# keystore = true
#
# disable
# keystore = false
```

This commit adds `ArtiNativeKeystoreConfig`, which will replace the
multi-purpose `keystore` field. The new config will look like this:
```
#[storage.keystore]
# Whether the keystore is enabled.
#
# If the `keymgr` feature is enabled and this option is:
#     * set to false, we will ignore the configured keystore path.
#     * set to "auto", the configured keystore, or the default keystore, if the
#     keystore path is not specified, will be used
#     * set to true, the configured keystore, or the default keystore, if the
#     keystore path is not specified, will be used
#
# If the `keymgr` feature is disabled and this option is:
#     * set to false, we will ignore the configured keystore path.
#     * set to "auto", we will ignore the configured keystore path.
#
# Setting this option to true when the `keymgr` feature is disabled is a
# configuration error.
#enabled = "auto"
# The root directory of the arti keystore
#path = "${ARTI_LOCAL_DATA}/keystore"
```

While `ArtiNativeKeystoreConfig` currently only has 2 fields, `enabled`
and `path`, future versions of the keystore might require additional
config options.
2023-07-13 12:13:59 +01:00
Gabriela Moldovan bd4955f9ed keymgr: Add semver.md. 2023-07-10 15:38:58 +01:00