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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ members = [
"test-validator",
"thin-client",
"timings",
"tls-utils",
"tokens",
"tps-client",
"tpu-client",
Expand Down Expand Up @@ -523,8 +524,8 @@ solana-rent = { path = "sdk/rent", version = "=2.2.0", default-features = false
solana-rent-debits = { path = "sdk/rent-debits", version = "=2.2.0" }
solana-reserved-account-keys = { path = "sdk/reserved-account-keys", version = "=2.2.0", default-features = false }
solana-reward-info = { path = "sdk/reward-info", version = "=2.2.0" }
solana-secp256r1-program = { path = "sdk/secp256r1-program", version = "=2.2.0", default-features = false }
solana-sanitize = { path = "sdk/sanitize", version = "=2.2.0" }
solana-secp256r1-program = { path = "sdk/secp256r1-program", version = "=2.2.0", default-features = false }
solana-seed-derivable = { path = "sdk/seed-derivable", version = "=2.2.0" }
solana-seed-phrase = { path = "sdk/seed-phrase", version = "=2.2.0" }
solana-serde = { path = "sdk/serde", version = "=2.2.0" }
Expand All @@ -537,6 +538,7 @@ solana-slot-hashes = { path = "sdk/slot-hashes", version = "=2.2.0" }
solana-slot-history = { path = "sdk/slot-history", version = "=2.2.0" }
solana-time-utils = { path = "sdk/time-utils", version = "=2.2.0" }
solana-timings = { path = "timings", version = "=2.2.0" }
solana-tls-utils = { path = "tls-utils", version = "=2.2.0" }
solana-unified-scheduler-logic = { path = "unified-scheduler-logic", version = "=2.2.0" }
solana-unified-scheduler-pool = { path = "unified-scheduler-pool", version = "=2.2.0" }
solana-rpc = { path = "rpc", version = "=2.2.0" }
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ solana-streamer = { workspace = true }
solana-svm = { workspace = true }
solana-svm-transaction = { workspace = true }
solana-timings = { workspace = true }
solana-tls-utils = { workspace = true }
solana-tpu-client = { workspace = true }
solana-transaction-status = { workspace = true }
solana-turbine = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions core/src/repair/quic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use {
CertificateError, KeyLogFile,
},
solana_gossip::contact_info::Protocol,
solana_quic_client::nonblocking::quic_client::SkipServerVerification,
solana_runtime::bank_forks::BankForks,
solana_sdk::{pubkey::Pubkey, signature::Keypair},
solana_streamer::{quic::SkipClientVerification, tls_certificates::new_dummy_x509_certificate},
solana_tls_utils::{
new_dummy_x509_certificate, SkipClientVerification, SkipServerVerification,
},
std::{
cmp::Reverse,
collections::{hash_map::Entry, HashMap},
Expand Down
17 changes: 17 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions quic-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ solana-quic-definitions = { workspace = true }
solana-rpc-client-api = { workspace = true }
solana-signer = { workspace = true }
solana-streamer = { workspace = true }
solana-tls-utils = { workspace = true }
solana-transaction-error = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
Expand Down
7 changes: 4 additions & 3 deletions quic-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ extern crate solana_metrics;
use {
crate::{
nonblocking::quic_client::{
QuicClient, QuicClientCertificate,
QuicClientConnection as NonblockingQuicClientConnection, QuicLazyInitializedEndpoint,
QuicClient, QuicClientConnection as NonblockingQuicClientConnection,
QuicLazyInitializedEndpoint,
},
quic_client::QuicClientConnection as BlockingQuicClientConnection,
},
Expand All @@ -25,7 +25,8 @@ use {
solana_keypair::Keypair,
solana_pubkey::Pubkey,
solana_signer::Signer,
solana_streamer::{streamer::StakedNodes, tls_certificates::new_dummy_x509_certificate},
solana_streamer::streamer::StakedNodes,
solana_tls_utils::{new_dummy_x509_certificate, QuicClientCertificate},
std::{
net::{IpAddr, SocketAddr},
sync::{Arc, RwLock},
Expand Down
64 changes: 2 additions & 62 deletions quic-client/src/nonblocking/quic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ use {
QUIC_CONNECTION_HANDSHAKE_TIMEOUT, QUIC_KEEP_ALIVE, QUIC_MAX_TIMEOUT,
},
solana_rpc_client_api::client_error::ErrorKind as ClientErrorKind,
solana_streamer::{
nonblocking::quic::ALPN_TPU_PROTOCOL_ID, tls_certificates::new_dummy_x509_certificate,
},
solana_streamer::nonblocking::quic::ALPN_TPU_PROTOCOL_ID,
solana_tls_utils::{new_dummy_x509_certificate, QuicClientCertificate, SkipServerVerification},
solana_transaction_error::TransportResult,
std::{
net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket},
Expand All @@ -35,65 +34,6 @@ use {
tokio::{sync::OnceCell, time::timeout},
};

#[derive(Debug)]
pub struct SkipServerVerification(Arc<rustls::crypto::CryptoProvider>);

impl SkipServerVerification {
pub fn new() -> Arc<Self> {
Arc::new(Self(Arc::new(rustls::crypto::ring::default_provider())))
}
}

impl rustls::client::danger::ServerCertVerifier for SkipServerVerification {
fn verify_tls12_signature(
&self,
message: &[u8],
cert: &rustls::pki_types::CertificateDer<'_>,
dss: &rustls::DigitallySignedStruct,
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
rustls::crypto::verify_tls12_signature(
message,
cert,
dss,
&self.0.signature_verification_algorithms,
)
}

fn verify_tls13_signature(
&self,
message: &[u8],
cert: &rustls::pki_types::CertificateDer<'_>,
dss: &rustls::DigitallySignedStruct,
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
rustls::crypto::verify_tls13_signature(
message,
cert,
dss,
&self.0.signature_verification_algorithms,
)
}

fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
self.0.signature_verification_algorithms.supported_schemes()
}

fn verify_server_cert(
&self,
_end_entity: &rustls::pki_types::CertificateDer<'_>,
_intermediates: &[rustls::pki_types::CertificateDer<'_>],
_server_name: &rustls::pki_types::ServerName<'_>,
_ocsp_response: &[u8],
_now: rustls::pki_types::UnixTime,
) -> Result<rustls::client::danger::ServerCertVerified, rustls::Error> {
Ok(rustls::client::danger::ServerCertVerified::assertion())
}
}

pub struct QuicClientCertificate {
pub certificate: rustls::pki_types::CertificateDer<'static>,
pub key: rustls::pki_types::PrivateKeyDer<'static>,
}

/// A lazy-initialized Quic Endpoint
pub struct QuicLazyInitializedEndpoint {
endpoint: OnceCell<Arc<Endpoint>>,
Expand Down
6 changes: 2 additions & 4 deletions quic-client/tests/quic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ mod tests {
solana_connection_cache::connection_cache_stats::ConnectionCacheStats,
solana_net_utils::bind_to_localhost,
solana_perf::packet::PacketBatch,
solana_quic_client::nonblocking::quic_client::{
QuicClientCertificate, QuicLazyInitializedEndpoint,
},
solana_quic_client::nonblocking::quic_client::QuicLazyInitializedEndpoint,
solana_sdk::{packet::PACKET_DATA_SIZE, signature::Keypair},
solana_streamer::{
quic::{QuicServerParams, SpawnServerResult},
streamer::StakedNodes,
tls_certificates::new_dummy_x509_certificate,
},
solana_tls_utils::{new_dummy_x509_certificate, QuicClientCertificate},
std::{
net::{SocketAddr, UdpSocket},
sync::{
Expand Down
1 change: 1 addition & 0 deletions streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ solana-quic-definitions = { workspace = true }
solana-signature = { workspace = true }
solana-signer = { workspace = true }
solana-time-utils = { workspace = true }
solana-tls-utils = { workspace = true }
solana-transaction-error = { workspace = true }
solana-transaction-metrics-tracker = { workspace = true }
thiserror = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion streamer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod recvmmsg;
pub mod sendmmsg;
pub mod socket;
pub mod streamer;
pub mod tls_certificates;

#[macro_use]
extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
},
quic::{configure_server, QuicServerError, QuicServerParams, StreamerStats},
streamer::StakedNodes,
tls_certificates::get_pubkey_from_tls_certificate,
},
async_channel::{
unbounded as async_unbounded, Receiver as AsyncReceiver, Sender as AsyncSender,
Expand All @@ -36,6 +35,7 @@ use {
},
solana_signature::Signature,
solana_time_utils as timing,
solana_tls_utils::get_pubkey_from_tls_certificate,
solana_transaction_metrics_tracker::signature_if_should_track_packet,
std::{
array,
Expand Down
56 changes: 1 addition & 55 deletions streamer/src/nonblocking/testing_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use {
MAX_UNSTAKED_CONNECTIONS,
},
streamer::StakedNodes,
tls_certificates::new_dummy_x509_certificate,
},
crossbeam_channel::unbounded,
quinn::{
Expand All @@ -22,67 +21,14 @@ use {
solana_net_utils::bind_to_localhost,
solana_perf::packet::PacketBatch,
solana_quic_definitions::{QUIC_KEEP_ALIVE, QUIC_MAX_TIMEOUT},
solana_tls_utils::{new_dummy_x509_certificate, SkipServerVerification},
std::{
net::{SocketAddr, UdpSocket},
sync::{atomic::AtomicBool, Arc, RwLock},
},
tokio::task::JoinHandle,
};

#[derive(Debug)]
pub struct SkipServerVerification(Arc<rustls::crypto::CryptoProvider>);

impl SkipServerVerification {
pub fn new() -> Arc<Self> {
Arc::new(Self(Arc::new(rustls::crypto::ring::default_provider())))
}
}

impl rustls::client::danger::ServerCertVerifier for SkipServerVerification {
fn verify_tls12_signature(
&self,
message: &[u8],
cert: &rustls::pki_types::CertificateDer<'_>,
dss: &rustls::DigitallySignedStruct,
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
rustls::crypto::verify_tls12_signature(
message,
cert,
dss,
&self.0.signature_verification_algorithms,
)
}

fn verify_tls13_signature(
&self,
message: &[u8],
cert: &rustls::pki_types::CertificateDer<'_>,
dss: &rustls::DigitallySignedStruct,
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
rustls::crypto::verify_tls13_signature(
message,
cert,
dss,
&self.0.signature_verification_algorithms,
)
}

fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
self.0.signature_verification_algorithms.supported_schemes()
}

fn verify_server_cert(
&self,
_end_entity: &rustls::pki_types::CertificateDer<'_>,
_intermediates: &[rustls::pki_types::CertificateDer<'_>],
_server_name: &rustls::pki_types::ServerName<'_>,
_ocsp_response: &[u8],
_now: rustls::pki_types::UnixTime,
) -> Result<rustls::client::danger::ServerCertVerified, rustls::Error> {
Ok(rustls::client::danger::ServerCertVerified::assertion())
}
}

pub fn get_client_config(keypair: &Keypair) -> ClientConfig {
let (cert, key) = new_dummy_x509_certificate(keypair);

Expand Down
Loading
Loading