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

Refactor key generation classes #2284

Merged
merged 15 commits into from
Nov 10, 2024
Merged

Refactor key generation classes #2284

merged 15 commits into from
Nov 10, 2024

Conversation

ni4
Copy link
Contributor

@ni4 ni4 commented Oct 21, 2024

This PR refactors key generation classes.

@ni4 ni4 force-pushed the ni4-refactor-keygen-classes branch 4 times, most recently from de160d5 to 1aaa2e6 Compare October 21, 2024 11:18
src/lib/key_material.cpp Dismissed Show dismissed Hide dismissed
src/lib/key_material.cpp Dismissed Show dismissed Hide dismissed
src/lib/keygen.cpp Dismissed Show dismissed Hide dismissed
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 87.06564% with 67 lines in your changes missing coverage. Please review.

Project coverage is 84.81%. Comparing base (135775a) to head (b5b6de2).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/lib/keygen.cpp 81.63% 36 Missing ⚠️
src/lib/rnp.cpp 87.34% 21 Missing ⚠️
src/lib/key_material.cpp 84.00% 8 Missing ⚠️
src/lib/json-utils.cpp 97.72% 1 Missing ⚠️
src/lib/pgp-key.cpp 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2284      +/-   ##
==========================================
+ Coverage   84.67%   84.81%   +0.14%     
==========================================
  Files         116      116              
  Lines       23436    23292     -144     
==========================================
- Hits        19844    19755      -89     
+ Misses       3592     3537      -55     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ni4 ni4 force-pushed the ni4-refactor-keygen-classes branch 3 times, most recently from 83d4c18 to f7971e7 Compare October 22, 2024 16:14
@ni4
Copy link
Contributor Author

ni4 commented Nov 1, 2024

@ronaldtse @desvxx @maxirmx ping for review!

@maxirmx
Copy link
Member

maxirmx commented Nov 1, 2024

This one is significant
I will find a couple of hours to understand itearly next week

@ni4
Copy link
Contributor Author

ni4 commented Nov 1, 2024

@maxirmx Thanks! Wanna make another also large PR, based on this one.

{
if (dsa_generate(&params.ctx->rng, &key_, params.dsa.p_bitlen, params.dsa.q_bitlen)) {
auto &dsa = dynamic_cast<const DSAKeyParams &>(params);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something, but is it ok to use just static_cast here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was to avoid theoretical possibility of getting wrong object here by throwing exception. Not sure how that could happen, just to be cautious.

size_t qbits_;

public:
DSAKeyParams();
Copy link
Contributor

Choose a reason for hiding this comment

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

qbits_ init missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is actually initialized in constructor implementation, but let's move it to the header for better clarity, thanks.

pgp_pubkey_alg_t alg_;
pgp_hash_alg_t hash_;
pgp_version_t version_;
SecurityContext & ctx_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Risky solution imho (to use reference here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SecurityContext is a singleton which lives the whole life of the top-level rnp_ffi_t object, and it would be destroyed after all the internal stuff. Is this good enough or there could be other solution?

Copy link
Member

Choose a reason for hiding this comment

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

if it is singleton, I would do
static SecurityContext& SecurityContext::getContext()
and do not keep the reference

But this is probably not inportant

@@ -2618,14 +2525,14 @@ pgp_key_t::add_sub_binding(pgp_key_t & subsec,
pgp_signature_t sig;
sign_init(ctx.rng, sig, hash, ctx.time(), version());
sig.set_type(PGP_SIG_SUBKEY);
if (binding.key_expiration) {
sig.set_key_expiration(binding.key_expiration);
if (binding.expiration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

May be confusing - "what expiration?". IMHO keep key_expiration will be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, renamed.

key_desc.rsa.modulus_bit_len = 1024;
key_desc.ctx = &global_ctx;
rnp::KeygenParams keygen(PGP_PKA_RSA, global_ctx);
auto & rsa = dynamic_cast<pgp::RSAKeyParams &>(keygen.key_params());
Copy link
Contributor

Choose a reason for hiding this comment

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

weird spacing:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, unfortunately that's how clang-format 11 behaves. Don't like these as well.

@ni4 ni4 force-pushed the ni4-refactor-keygen-classes branch from 5b04e51 to 43d5524 Compare November 4, 2024 11:08
Copy link
Member

@maxirmx maxirmx left a comment

Choose a reason for hiding this comment

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

OK

pgp_pubkey_alg_t alg_;
pgp_hash_alg_t hash_;
pgp_version_t version_;
SecurityContext & ctx_;
Copy link
Member

Choose a reason for hiding this comment

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

if it is singleton, I would do
static SecurityContext& SecurityContext::getContext()
and do not keep the reference

But this is probably not inportant

@ni4
Copy link
Contributor Author

ni4 commented Nov 5, 2024

@maxirmx thanks for the review. Having static variable would have issues with multi-threaded applications, which now could use at least separate rnp_ffi_t objects in different threads.

@ni4 ni4 force-pushed the ni4-refactor-keygen-classes branch from 43d5524 to b5b6de2 Compare November 10, 2024 11:01
@ni4
Copy link
Contributor Author

ni4 commented Nov 10, 2024

Merging with two approvals and green CI. Thanks!

@ni4 ni4 merged commit 0fc76d5 into main Nov 10, 2024
124 checks passed
@ni4 ni4 deleted the ni4-refactor-keygen-classes branch November 10, 2024 13:52
@ni4 ni4 mentioned this pull request Jan 7, 2025
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.

3 participants