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

chore(tls): Refactor parsing certificate and identity #1763

Merged

Conversation

tottoto
Copy link
Collaborator

@tottoto tottoto commented Jun 29, 2024

Refactors parsing certificate and identity.

@tottoto tottoto changed the title Refactor parsing certificate and identity chore(tls): Refactor parsing certificate and identity Jun 29, 2024
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch 2 times, most recently from 1b5d429 to e0a63b4 Compare June 30, 2024 10:48
@djc
Copy link
Contributor

djc commented Jul 1, 2024

I think this and #1748 need a more holistic design discussion of what we're trying to achieve here and how to balance the trade-offs. As is, I don't think the changes here are a clear improvement. I think the goals are:

  1. Hide rustls API surface so we can semver-compatibly bump rustls
  2. Be easy to use
  3. Provide type safety

Given the developments in upstream rustls with the migration to rustls-pki-types, personally I think it could be worth simplifying so that our public API fully relies on rustls-pki-types directly (which was not the case before rustls adopted rustls-pki-types). We could still provide wrapper around the use of rustls-pemfile but I'm personally not convinced the benefit on (2) is worth the costs on (3), and some of the ways in which it might make the API worse.

@tottoto
Copy link
Collaborator Author

tottoto commented Jul 1, 2024

As is, I don't think the changes here are a clear improvement.

Can you elaborate what points in the existing implementations are clear than this changes?

Regarding to #1748, this pull request is not related to it. Since it contains difficult problem, this is completely separated patch to make easier implementation at the moment. This change reduces the duplicate logic implementation and reimplementing of rustls providing.

@djc
Copy link
Contributor

djc commented Jul 3, 2024

Can you elaborate what points in the existing implementations are clear than this changes?

The previous implementation had a higher-level interface (adding certificates to the root store). This implementation ends up deduplicating the certificate parsing (good) but actually duplicates how certificates get added to the root store (even though this doesn't result in much extra code).

I'm also not a fan of the impl blocks living in a separate file from the struct definition they're linked to, and I don't think parse() is a great name for the methods -- parse() is usually associated with FromStr which generally provided more like a 1:1 conversion whereas at least for certificates this is more like a 1:n conversion.

@tottoto
Copy link
Collaborator Author

tottoto commented Jul 3, 2024

Thanks for the explanation.

The previous implementation had a higher-level interface (adding certificates to the root store). This implementation ends up deduplicating the certificate parsing (good) but actually duplicates how certificates get added to the root store (even though this doesn't result in much extra code).

Given this opinion, I feel it sounds this implementation is better than the previous one regarding this point. What I aimed to do are removing the higher level interface, and resolves the asymmetry between what add_certs_from_pem and load_identity do by separating the responsibilities of add_certs_from_pem, and eliminate the distribution of the actual implementations of the process of registering certificates to the root store.

I'm also not a fan of the impl blocks living in a separate file from the struct definition they're linked to

I understand what you concern. I think it is an acceptable drawback thinking of reducing importing the previous functions and expressing that they are related to certificate or identity type, but I also understand the cost of not being located at one place. I will change them to independent functions.

I don't think parse() is a great name for the methods -- parse() is usually associated with FromStr which generally provided more like a 1:1 conversion whereas at least for certificates this is more like a 1:n conversion.

In this case, I would think this can be thought as one set of certificates, so it can be regarded as 1:1 conversion. But I think we can name more descriptively as well.

@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from 1cd611a to 1a5de9d Compare July 7, 2024 09:49
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from 1a5de9d to db60247 Compare July 19, 2024 15:09
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from db60247 to 6dca94e Compare August 5, 2024 22:36
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from 6dca94e to 357845d Compare September 4, 2024 17:11
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch 4 times, most recently from 8a8e8e2 to 2f41f4a Compare September 26, 2024 20:23
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from 2f41f4a to 52b4d50 Compare October 3, 2024 23:24
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from 52b4d50 to 045008c Compare October 3, 2024 23:47
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch 2 times, most recently from b223884 to e11bab6 Compare October 16, 2024 16:23
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from e11bab6 to b756b0b Compare October 21, 2024 21:59
@tottoto tottoto force-pushed the refactor-parsing-certificate-and-identity branch from b756b0b to 335e1a9 Compare November 5, 2024 11:27
@tottoto tottoto added this pull request to the merge queue Nov 5, 2024
Merged via the queue into hyperium:master with commit 8def0bb Nov 5, 2024
17 checks passed
@tottoto tottoto deleted the refactor-parsing-certificate-and-identity branch November 5, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants