Debian Codegraph @

src/connection/tls.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::collationrust-analyzer cargo sqlx-mysql 0.8.3 collation/::{CharSetrust-analyzer cargo sqlx-mysql 0.8.3 collation/CharSet#, Collationrust-analyzer cargo sqlx-mysql 0.8.3 collation/Collation#};
2 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::connectionrust-analyzer cargo sqlx-mysql 0.8.3 connection/::{MySqlStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#, Waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/Waiting#};
3 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::errorrust-analyzer cargo sqlx-mysql 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
4 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::netrust-analyzer cargo sqlx-core 0.8.3 net/::tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/::TlsConfigrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#;
5 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::netrust-analyzer cargo sqlx-core 0.8.3 net/::{tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/, BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#, Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#, WithSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket#};
6 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::connectrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/::SslRequestrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest#;
7 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#;
8 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::{MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#, MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#};
9 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#;
10
11 struct MapStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream# {
12 server_versionrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#server_version.: (u16, u16, u16),
13 capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#capabilities.: Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#,
14 sequence_idrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#sequence_id.: u8,
15 waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#waiting.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<Waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/Waiting#>,
16 charsetrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#charset.: CharSetrust-analyzer cargo sqlx-mysql 0.8.3 collation/CharSet#,
17 collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#collation.: Collationrust-analyzer cargo sqlx-mysql 0.8.3 collation/Collation#,
18 }
19
20 pub(superrust-analyzer cargo sqlx-mysql 0.8.3 connection/) async fn maybe_upgraderust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/maybe_upgrade().<S: Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#>(
21 mut stream: MySqlStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#<S>,
22 options: &MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#,
23 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<MySqlStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
24 let server_supports_tls = stream.capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#capabilities..containsrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]contains().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::SSLrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]SSL.);
25
26 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(options.ssl_moderust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_mode., MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Disabledrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Disabled#) || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/::availablerust-analyzer cargo sqlx-core 0.8.3 net/tls/available().() {
27 // remove the SSL capability if SSL has been explicitly disabled
28 stream.capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#capabilities..removerust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]remove().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::SSLrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]SSL.);
29 }
30
31 // https://www.postgresql.org/docs/12/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS
32 match options.ssl_moderust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_mode. {
33 MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Disabledrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Disabled# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(stream.boxed_socketrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/impl#[`MySqlStream<S>`]boxed_socket().()),
34
35 MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Preferredrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Preferred# => {
36 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/::availablerust-analyzer cargo sqlx-core 0.8.3 net/tls/available().() {
37 // Client doesn't support TLS
38 tracingrust-analyzer cargo tracing 0.1.44 crate/::debugrust-analyzer cargo tracing 0.1.44 macros/debug!!("not performing TLS upgrade: TLS support not compiled in");
39 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(stream.boxed_socketrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/impl#[`MySqlStream<S>`]boxed_socket().());
40 }
41
42 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().server_supports_tls {
43 // Server doesn't support TLS
44 tracingrust-analyzer cargo tracing 0.1.44 crate/::debugrust-analyzer cargo tracing 0.1.44 macros/debug!!("not performing TLS upgrade: unsupported by server");
45 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(stream.boxed_socketrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/impl#[`MySqlStream<S>`]boxed_socket().());
46 }
47 }
48
49 MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Requiredrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Required# | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyIdentityrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyIdentity# | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyCarust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyCa# => {
50 tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/::error_if_unavailablerust-analyzer cargo sqlx-core 0.8.3 net/tls/error_if_unavailable().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
51
52 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().server_supports_tls {
53 // upgrade failed, die
54 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Tlsrust-analyzer cargo sqlx-core 0.8.3 error/Error#Tls#("server does not support TLS".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()));
55 }
56 }
57 }
58
59 let tls_config = TlsConfigrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig# {
60 accept_invalid_certsrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#accept_invalid_certs.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
61 options.ssl_moderust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_mode.,
62 MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyCarust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyCa# | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyIdentityrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyIdentity#
63 ),
64 accept_invalid_hostnamesrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#accept_invalid_hostnames.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(options.ssl_moderust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_mode., MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyIdentityrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyIdentity#),
65 hostnamerust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#hostname.: &options.hostrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#host.,
66 root_cert_pathrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#root_cert_path.: options.ssl_carust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_ca..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
67 client_cert_pathrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#client_cert_path.: options.ssl_client_certrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_client_cert..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
68 client_key_pathrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#client_key_path.: options.ssl_client_keyrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_client_key..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
69 };
70
71 // Request TLS upgrade
72 stream.write_packetrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/impl#[`MySqlStream<S>`]write_packet().(SslRequestrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest# {
73 max_packet_sizerust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest#max_packet_size.: superrust-analyzer cargo sqlx-mysql 0.8.3 connection/::MAX_PACKET_SIZErust-analyzer cargo sqlx-mysql 0.8.3 connection/MAX_PACKET_SIZE.,
74 collationrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest#collation.: stream.collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#collation. as u8,
75 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
76
77 stream.flushrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]flush().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
78
79 tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/::handshakerust-analyzer cargo sqlx-core 0.8.3 net/tls/handshake().(
80 stream.socketrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#socket..into_innerrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]into_inner().(),
81 tls_config,
82 MapStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream# {
83 server_versionrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#server_version.: stream.server_versionrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#server_version.,
84 capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#capabilities.: stream.capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#capabilities.,
85 sequence_idrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#sequence_id.: stream.sequence_idrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#sequence_id.,
86 waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#waiting.: stream.waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#waiting.,
87 charsetrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#charset.: stream.charsetrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#charset.,
88 collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#collation.: stream.collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#collation.,
89 },
90 )
91 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
92 }
93
94 impl WithSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket# for MapStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream# {
95 type Outputrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/impl#[MapStream][WithSocket]Output# = MySqlStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#;
96
97 async fn with_socketrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/impl#[MapStream][WithSocket]with_socket().<S: Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#>(self, socket: S) -> Selfrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/impl#[MapStream][WithSocket]::Outputrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket#Output# {
98 MySqlStreamrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream# {
99 socketrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#socket.: BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#::newrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]new().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(socket)),
100 server_versionrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#server_version.: self.server_versionrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#server_version.,
101 capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#capabilities.: self.capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#capabilities.,
102 sequence_idrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#sequence_id.: self.sequence_idrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#sequence_id.,
103 waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#waiting.: self.waitingrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#waiting.,
104 charsetrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#charset.: self.charsetrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#charset.,
105 collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#collation.: self.collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/tls/MapStream#collation.,
106 is_tlsrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#is_tls.: true,
107 }
108 }
109 }