Repository navigation
Change the Managed Group to accept a KeyStore ref instead of keeping a CredentialBundle ref - #385
Conversation
|
This PR is so big! Please, split it 😊 |
|
This PR is so big! Please, split it 😊 |
|
This PR is so big! Please, split it 😊 |
|
This PR is so big! Please, split it 😊 |
franziskuskiefer
left a comment
There was a problem hiding this comment.
Thanks! I think we're getting there this time 🙂 A couple comments, mostly around the API and some cleanup.
| pub fn add_members( | ||
| &mut self, | ||
| key_store: &KeyStore, | ||
| key_packages: &[KeyPackage], |
There was a problem hiding this comment.
Shouldn't we pass in the key package hashes here now?
There was a problem hiding this comment.
I guess that would mean that the KeyStore also stores KPs from other users. I'm not against it, but it's probably not in scope just now.
There was a problem hiding this comment.
We might want to have that functionality in the KeyStore at some point, but I'd prefer to land it as it currently is. We can add more stuff in later, smaller PRs.
| //! `CredentialBundle` instances, `KeyPackageBundle` instances should not be | ||
| //! used across groups. | ||
| //! | ||
| //! This design is temporary and only until the `ManagedGroup` is refactored to |
There was a problem hiding this comment.
Can you add an issue number here?
| /// Generate a fresh `CredentialBundle` with the given parameters and store | ||
| /// it in the `KeyStore`. Returns the corresponding `Credential` or an error | ||
| /// if the creation of the `CredentialBundle` fails. | ||
| pub fn generate_credential( |
There was a problem hiding this comment.
It is called generate_credential but returns a CredentialBundle that's confusing.
There was a problem hiding this comment.
Also, why only return the credential?
There was a problem hiding this comment.
Wait, your comments are contradicting one another 😄
The idea is to generate a CredentialBundle, store it in the KeyStore and return the corresponding credential. As remarked by @raphaelrobert in the comment above, the name is in line with the return type. That's not to say that we can't name both functions differently, though.
There was a problem hiding this comment.
That should be a generates, not returns in the first comment.
My issue is not with returning a credential, but you don't generate a credential but a credential bundle. That's unexpected.
There was a problem hiding this comment.
I see. So generate_credential_bundle (and _key_package_bundle) as a replacement? The documentation should then explain why it only returns a Credential (or KeyPackage respectively).
There was a problem hiding this comment.
Both isn't really great. I don't have a good suggestion for how to resolve this. But generate_credential_bundle is at least doing what it says. You could also have a separate generate and get function, i.e. don't return anything. But really this is some sort of generate_key_pair, not a generate_random_point, so this has to be made clear.
But since the API will change anyway I'm also fine with an explicit follow up issue.
| //! `KeyPackage` instances are meant to be published so other parties can use | ||
| //! them to add the publishing party to groups. | ||
| //! | ||
| //! ### `KeyPackageBundle` Ownership |
There was a problem hiding this comment.
This makes me expect a "CredentialBundle Ownership" section.
There was a problem hiding this comment.
I'll rename it then, as the section discusses both KPB and CB ownership.
| /// error if no `CredentialBundle` can be found in the `KeyStore` | ||
| /// corresponding to the given `Credential` or if an error occurred during | ||
| /// the creation of the `KeyPackageBundle`. | ||
| pub fn generate_key_package( |
There was a problem hiding this comment.
This generates a KeyPackageBundle not a key_package.
There was a problem hiding this comment.
I think this is fine though, because the bundle is now only stored within the KeyStore. From an outside perspective, we only ever deal with key packages. The return type is consistent with the function name and the caller doesn't need to know what's happening internally.
There was a problem hiding this comment.
It's in line with the other functions. But it's still not doing what it says, i.e. it's not generating only a key package.
| &self.credential_bundle.credential() | ||
| /// Returns own credential. If the group is inactive, it returns a | ||
| /// `UseAfterEviction` error. | ||
| pub fn credential(&self) -> Result<Credential, ManagedGroupError> { |
There was a problem hiding this comment.
Why do you need this to return a copy?
There was a problem hiding this comment.
Because the tree lives in a Refcell and goes out of scope at the end of this function, which would invalidate any reference to the Credential. We'd have to return some sort of guard structure to keep that reference alive. I thought copying the credential would be easier for now.
There was a problem hiding this comment.
Ok, for the sake of getting this landed and as you say this should chnage in future, please add a ToDo and issue number.
| return Err(ManagedGroupError::UseAfterEviction(UseAfterEviction::Error)); | ||
| } | ||
|
|
||
| let credential = self.credential()?; |
There was a problem hiding this comment.
I see this block a lot in here. The code should be factored out somehow to avoid having so many copies of this code.
There was a problem hiding this comment.
That is tricky due to lifetime concerns. The credential_bundle is actually a CbGuard, which contains a reference to the SignaturePublicKey in the credential. I could change the CbGuard to contain a full instance of the key rather than just a reference, which might make a separate function possible, but I haven't tried that yet.
There was a problem hiding this comment.
I don't understand why this would be a problem for a helper function, but I haven't tried it myself. I was thinking about something along the lines of:
fn fetch_credential_bundle(credential: &Credential, key_store: &'a KeyStore) -> Result<CbGuard, ManagedGroupError> {
...
}
There was a problem hiding this comment.
Right, I don't think you can clean this up without changing self.credential() to return a reference.
| pub mod framing; | ||
| pub mod group; | ||
| mod key_packages; | ||
| mod key_store; |
| let number_of_clients = 20; | ||
| let setup = ManagedTestSetup::new(managed_group_config, number_of_clients); | ||
| setup.create_clients(); | ||
| // Create a basic group with more than 4 members to create a tree with intermediate nodes. |
There was a problem hiding this comment.
Can you fix the indentation here?
raphaelrobert
left a comment
There was a problem hiding this comment.
Thanks for tackling this again! Definitely looks good, and we can always change things later if we need them.
| pub fn add_members( | ||
| &mut self, | ||
| key_store: &KeyStore, | ||
| key_packages: &[KeyPackage], |
There was a problem hiding this comment.
I guess that would mean that the KeyStore also stores KPs from other users. I'm not against it, but it's probably not in scope just now.
| } | ||
|
|
||
| impl<'a> Serialize for ManagedGroup<'a> { | ||
| impl<'a> Serialize for ManagedGroup { |
There was a problem hiding this comment.
I think you can also drop the first lifetime here
| /// error if no `CredentialBundle` can be found in the `KeyStore` | ||
| /// corresponding to the given `Credential` or if an error occurred during | ||
| /// the creation of the `KeyPackageBundle`. | ||
| pub fn generate_key_package( |
There was a problem hiding this comment.
I think this is fine though, because the bundle is now only stored within the KeyStore. From an outside perspective, we only ever deal with key packages. The return type is consistent with the function name and the caller doesn't need to know what's happening internally.
|
|
||
| use super::{KeyStore, KeyStoreError}; | ||
|
|
||
| ctest_ciphersuites!(key_storage, test(param: CiphersuiteName) { |
There was a problem hiding this comment.
A brief description of the test would be good
kkohbrok
left a comment
There was a problem hiding this comment.
Thanks for the reviews! I tried to answer to all comments that I didn't immediately address in the code.
| pub fn add_members( | ||
| &mut self, | ||
| key_store: &KeyStore, | ||
| key_packages: &[KeyPackage], |
There was a problem hiding this comment.
We might want to have that functionality in the KeyStore at some point, but I'd prefer to land it as it currently is. We can add more stuff in later, smaller PRs.
| &self.credential_bundle.credential() | ||
| /// Returns own credential. If the group is inactive, it returns a | ||
| /// `UseAfterEviction` error. | ||
| pub fn credential(&self) -> Result<Credential, ManagedGroupError> { |
There was a problem hiding this comment.
Because the tree lives in a Refcell and goes out of scope at the end of this function, which would invalidate any reference to the Credential. We'd have to return some sort of guard structure to keep that reference alive. I thought copying the credential would be easier for now.
| return Err(ManagedGroupError::UseAfterEviction(UseAfterEviction::Error)); | ||
| } | ||
|
|
||
| let credential = self.credential()?; |
There was a problem hiding this comment.
That is tricky due to lifetime concerns. The credential_bundle is actually a CbGuard, which contains a reference to the SignaturePublicKey in the credential. I could change the CbGuard to contain a full instance of the key rather than just a reference, which might make a separate function possible, but I haven't tried that yet.
| //! `KeyPackage` instances are meant to be published so other parties can use | ||
| //! them to add the publishing party to groups. | ||
| //! | ||
| //! ### `KeyPackageBundle` Ownership |
There was a problem hiding this comment.
I'll rename it then, as the section discusses both KPB and CB ownership.
| /// Generate a fresh `CredentialBundle` with the given parameters and store | ||
| /// it in the `KeyStore`. Returns the corresponding `Credential` or an error | ||
| /// if the creation of the `CredentialBundle` fails. | ||
| pub fn generate_credential( |
There was a problem hiding this comment.
Wait, your comments are contradicting one another 😄
The idea is to generate a CredentialBundle, store it in the KeyStore and return the corresponding credential. As remarked by @raphaelrobert in the comment above, the name is in line with the return type. That's not to say that we can't name both functions differently, though.
|
This PR is so big! Please, split it 😊 |
Codecov Report
@@ Coverage Diff @@
## main #385 +/- ##
==========================================
+ Coverage 83.62% 83.84% +0.22%
==========================================
Files 108 111 +3
Lines 7784 7878 +94
==========================================
+ Hits 6509 6605 +96
+ Misses 1275 1273 -2
Continue to review full report at Codecov.
|
raphaelrobert
left a comment
There was a problem hiding this comment.
Except for the code duplication isuue raised by @franziskuskiefer, all other comments were addressed, so I will approve this now from my side.
|
This PR is so big! Please, split it 😊 |
|
This PR is so big! Please, split it 😊 |
franziskuskiefer
left a comment
There was a problem hiding this comment.
Let's get this in 🚢 and follow up on the issues to improve later.
This PR replaces #334, as it goes a step further and doesn't keep the KeyStore reference in the ManagedGroup struct, but instead passes a KeyStore reference into every call into the Managed Group API. This allows us to avoid lifetime issues, as Rust doesn't allow struct-internal references.
One caveat in this PR that might be worth discussing:
unwrap) PoisonErrors when accessing KeyPackageBundles and CredentialBundles. The argument being that there is (to my knowledge) no way that the code can panic while it holds a write lock. In particular while holding a write lock, we only interact with the HashMap usingget,insertorremove, which should be safe.The PR is rather large, but should be easy to review, as a lot of the changes are due to the change of API, so function calls will look different, but in most places, there are no changes in terms of functionality.