Skip to content
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

signatures: use OwnedKeyId instead of String for PublicKeySet index #1808

Closed
wants to merge 1 commit into from

Conversation

Kladki
Copy link
Member

@Kladki Kladki commented May 11, 2024

No description provided.

Copy link
Contributor

@zecakeh zecakeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have mostly nitpicks.

crates/ruma-signatures/src/functions.rs Outdated Show resolved Hide resolved
crates/ruma-signatures/src/keys.rs Outdated Show resolved Hide resolved
crates/ruma-signatures/CHANGELOG.md Outdated Show resolved Hide resolved
@Kladki Kladki force-pushed the signatures-key-set-id branch 4 times, most recently from e4b4528 to a7c01c6 Compare May 11, 2024 16:23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the error has changed

thread 'functions::tests::verify_event_with_single_key_with_unknown_algorithm_should_not_accept_event' panicked at crates/ruma-signatures/src/functions.rs:1163:9:
match assertion failed
 pattern: `Err(Error::Verification(VerificationError::UnknownPublicKeysForSignature))`
   value: `Err(Verification(Signature(signature::Error { source: Some(Verification equation was not satisfied) })))`

I am not sure why though, as even when setting the let ok ... else statements to panic on else, it still seems to get this new error instead of panicking there. 🤔

@@ -1,5 +1,8 @@
# [unreleased]

Breaking changes:
- Use `OwnedServerSigningKeyId` for the keys of `PublicKeySet` instead of `String`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A double space.

Suggested change
- Use `OwnedServerSigningKeyId` for the keys of `PublicKeySet` instead of `String`.
- Use `OwnedServerSigningKeyId` for the keys of `PublicKeySet` instead of `String`.

@zecakeh
Copy link
Contributor

zecakeh commented May 12, 2024

So I believe that we should remove split_id completely and replace it with ServerSigningKeyId everywhere. This should happen in this PR, I'll make a separate PR to copy the validation from split_id to KeyName.

@Kladki
Copy link
Member Author

Kladki commented May 12, 2024 via email

@zecakeh
Copy link
Contributor

zecakeh commented May 12, 2024

It's probably better, if you don't want to have to edit your code again. But if you don't mind that, you can probably start to make changes.

@@ -181,7 +181,7 @@ pub type PublicKeyMap = BTreeMap<String, PublicKeySet>;
/// A set of public keys for a single homeserver.
///
/// This is represented as a map from key ID to base64-encoded signature.
pub type PublicKeySet = BTreeMap<String, Base64>;
pub type PublicKeySet = BTreeMap<OwnedServerSigningKeyId, Base64>;
Copy link
Contributor

@zecakeh zecakeh May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this change, is there any value for PublicKeyMap to use OwnedServerName for the keys? Or is it used in cases where the entity is not a server name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be good, would make working with this function much more clear, and also ensure that consumers of the function are passing in the correct type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I do that in this pull request, or a new one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do that separately, it will make this PR a bit smaller.

Copy link
Member Author

@Kladki Kladki May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be ok to also convert entity_id of sign_json and friends to &ServerName (currently &str)?

Copy link
Contributor

@zecakeh zecakeh May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking more into it, both sign_json and verify_json could be used on the client side (to sign/verify devices or cross-signing keys signatures), so they shouldn't use server signatures specific types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this isn't as big of a deal as I thought for us anyways, and if there is a usecase outside of servers, then I think it would be best to close this then.

@zecakeh
Copy link
Contributor

zecakeh commented May 12, 2024

So I believe that we should remove split_id completely and replace it with ServerSigningKeyId everywhere. This should happen in this PR, I'll make a separate PR to copy the validation from split_id to KeyName.

It actually turns out that KeyName is validated indirectly, because the characters of the substring are validated when parsing KeyId. So there is no other PR needed for that, you can just get rid of split_id.

There is a small difference in validation in that compat-signatures-id on ruma-signatures only allows a few more characters for the version, while compat-key-id on ruma-common doesn't validate the version at all. But that will have no conflict with this so we can see it separately.

@Kladki
Copy link
Member Author

Kladki commented May 29, 2024

As per #1808 (comment)

@Kladki Kladki closed this May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants