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

Organize some of the duplicated TLS code into a separate crate #3835

Merged
merged 7 commits into from
Dec 4, 2024

Conversation

alexpyattaev
Copy link

Problem

A whole bunch of places in the code have been defining the same structure SkipServerVerification for use in quic related code. There were at least 3 independent definitions for this struct with zero functional differences in different project locations.

This created unnecessary duplication as well as strange code dependencies where turbine would depend on quic-client for this one struct, even though logically it makes no sense for turbine to depend on quic-client.

Summary of Changes

The following moved to tls-utils crate:

SkipServerVerification
SkipClientVerification
new_dummy_x509_certificate

All references to them redirected. Multiple redundant definitions removed.


[dependencies]
solana-sdk = { workspace = true }

Choose a reason for hiding this comment

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

dependencies should be sorted

Copy link
Author

Choose a reason for hiding this comment

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

done

Choose a reason for hiding this comment

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

have you pushed your changes? I still see space and unsorted dependencies.

Copy link
Author

Choose a reason for hiding this comment

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

yes, just did

solana-signer = { workspace = true }
solana-pubkey = { workspace = true }


Choose a reason for hiding this comment

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

extra space

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,14 @@
//! Collection of TLS related code fragments that end up popping up everywhere where quic is used.
//! Aggregated here to avoid bugs due to conflicting implementations of the same functionality

Choose a reason for hiding this comment

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

Suggested change
//! Aggregated here to avoid bugs due to conflicting implementations of the same functionality
//! Aggregated here to avoid bugs due to conflicting implementations of the same functionality.

Copy link
Author

Choose a reason for hiding this comment

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

corrected

tls-utils/README Outdated Show resolved Hide resolved
@KirillLykov
Copy link

Looks like a good change to me

@KirillLykov
Copy link

I think you can press now "ready for review"

@alexpyattaev
Copy link
Author

alexpyattaev commented Dec 2, 2024 via email

Copy link

@gregcusack gregcusack left a comment

Choose a reason for hiding this comment

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

just a few initial thoughts on this! thank you for making these changes. making sure the crate isn't published will help get this PR past CI

solana-transaction-error = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }

Choose a reason for hiding this comment

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

should be a new line here

Copy link
Author

Choose a reason for hiding this comment

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

addressed.

@@ -1,3 +1,4 @@
#![allow(clippy::arithmetic_side_effects)]

Choose a reason for hiding this comment

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

is this addition needed? isn't the file just moved to a new location?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this is necessary. A similar "allow" was on the crate level in the original crate. Clippy gets confused with benign addition for a buffer size computation otherwise. If it is not benign then please let me know why. I've changed the code to appease clippy without the #allow, though I feel like in this case it was overly protective.

The bigger problem is the streamer crate from which the code was taken, where the same clippy warning is triggered many many times if the allow line is removed. I can look into that in a different PR.

Choose a reason for hiding this comment

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

looks like you removed this?

tls-utils/README Outdated Show resolved Hide resolved
Comment on lines 3 to 7
description = "Solana TLS utilities"
documentation = "https://docs.rs/solana-tls-utils"

version.workspace = true

Choose a reason for hiding this comment

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

Suggested change
description = "Solana TLS utilities"
documentation = "https://docs.rs/solana-tls-utils"
version.workspace = true
description = "Solana TLS utilities"
documentation = "https://docs.rs/solana-tls-utils"
publish = false
version.workspace = true

Copy link
Author

Choose a reason for hiding this comment

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

set to publish=false as suggested

},
solana_tls_utils::{QuicClientCertificate,new_dummy_x509_certificate},

Choose a reason for hiding this comment

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

space after 'QuicClientCertificate', can you do a "cargo fmt"

Copy link
Author

Choose a reason for hiding this comment

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

thanks, cargo fmt done as suggested on all files.

@alexpyattaev alexpyattaev force-pushed the organize_tls_utils branch 4 times, most recently from 0474c3f to 87b4eae Compare December 3, 2024 16:27
description = "Solana TLS utilities"
documentation = "https://docs.rs/solana-tls-utils"
publish = false

Choose a reason for hiding this comment

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

extra line here

Copy link
Author

Choose a reason for hiding this comment

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

publish=false will have to go away after this is merged as far as I understand.

Choose a reason for hiding this comment

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

ya are we going to publish this on crates.io? or no?

Copy link
Author

Choose a reason for hiding this comment

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

I have no idea if anyone would ever use it there. Probably there is no benefit to that in this case.

@alexpyattaev
Copy link
Author

alexpyattaev commented Dec 3, 2024 via email

KirillLykov
KirillLykov previously approved these changes Dec 3, 2024
@gregcusack gregcusack self-requested a review December 3, 2024 21:25
if keypair_secret_len != 32 {
panic!("Unexpected secret key length!");
}
let need_buffer = PKCS8_PREFIX

Choose a reason for hiding this comment

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

Suggested change
let need_buffer = PKCS8_PREFIX
let buffer_size = PKCS8_PREFIX

Copy link
Author

Choose a reason for hiding this comment

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

corrected as suggested.

.len()
.checked_add(keypair_secret_len) //clippy being overly guarded here but optimizer will elide checked_add
.expect("Unexpected secret key length!");
let mut key_pkcs8_der = Vec::<u8>::with_capacity(need_buffer);

Choose a reason for hiding this comment

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

Suggested change
let mut key_pkcs8_der = Vec::<u8>::with_capacity(need_buffer);
let mut key_pkcs8_der = Vec::<u8>::with_capacity(buffer_size);

Copy link
Author

Choose a reason for hiding this comment

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

corrected as suggested.

Copy link

@gregcusack gregcusack left a comment

Choose a reason for hiding this comment

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

looks good. just need to remove the extra blank line in tls-utils/Cargo.toml

edition = { workspace = true }

[dependencies]

Copy link

@gregcusack gregcusack Dec 3, 2024

Choose a reason for hiding this comment

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

nit: shouldn't be a blank line at line 15

Copy link
Author

Choose a reason for hiding this comment

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

corrected

Copy link

@gregcusack gregcusack left a comment

Choose a reason for hiding this comment

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

lgtm!

@alexpyattaev alexpyattaev merged commit 1d3c961 into anza-xyz:master Dec 4, 2024
51 checks passed
@joncinque
Copy link

This crate needs to be published -- solana-quic-client depends on it, which is used by the CLI and many other clients. We can also remove the dependency on solana-sdk. I'll put in a PR for all that

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.

5 participants