You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Only establish connections to the DB as needed. If set to `true`, the db connection will
67
75
/// be created using SQLx's [connect_lazy](https://docs.rs/sqlx/latest/sqlx/struct.Pool.html#method.connect_lazy)
68
76
/// method.
@@ -148,6 +156,29 @@ where
148
156
}
149
157
}
150
158
159
+
#[derive(Debug,Clone,Copy)]
160
+
/// Options for controlling the level of protection provided for MySQL or PostgreSQL SSL connections.
161
+
pubenumSslMode{
162
+
/// I don't care about security, and I don't want to pay the overhead of encryption.
163
+
/// This corresponds to postgres `sslmode=disable` and mysql `ssl-mode=DISABLED`.
164
+
Disable,
165
+
/// I don't care about encryption, but I wish to pay the overhead of encryption if the server supports it.
166
+
/// This corresponds to postgres `sslmode=prefer` and mysql `ssl-mode=PREFERRED`.
167
+
/// This is the default.
168
+
Prefer,
169
+
/// I want my data to be encrypted, and I accept the overhead. I trust that the network will make sure I always connect to the server I want.
170
+
/// This corresponds to postgres `sslmode=require` and mysql `ssl-mode=REQUIRED`.
171
+
Require,
172
+
/// I want my data encrypted, and I accept the overhead. I want to be sure that I connect to a server that I trust.
173
+
/// like `Self::Require`, but additionally verify the server Certificate Authority (CA) certificate against the configured CA certificates.
174
+
/// This corresponds to postgres `sslmode=verify-ca` and mysql `ssl-mode=VERIFY_CA`.
175
+
VerifyCa,
176
+
/// I want my data encrypted, and I accept the overhead. I want to be sure that I connect to a server I trust, and that it's the one I specify.
177
+
/// like `Self::VerifyCa`, but additionally perform host name identity verification by checking the host name the client uses for connecting to the server against the identity in the certificate that the server sends to the client.
178
+
/// This corresponds to postgres `sslmode=verify-full` and mysql `ssl-mode=VERIFY_IDENTITY`.
179
+
VerifyIdentity,
180
+
}
181
+
151
182
implConnectOptions{
152
183
/// Create new [ConnectOptions] for a [Database] by passing in a URI string
153
184
pubfnnew<T>(url:T) -> Self
@@ -170,6 +201,10 @@ impl ConnectOptions {
170
201
schema_search_path:None,
171
202
test_before_acquire:true,
172
203
connect_lazy:false,
204
+
ssl_mode:None,
205
+
ssl_client_cert:None,
206
+
ssl_client_key:None,
207
+
ssl_root_cert:None,
173
208
}
174
209
}
175
210
@@ -311,6 +346,99 @@ impl ConnectOptions {
311
346
self
312
347
}
313
348
349
+
/// Sets whether or with what priority a secure SSL TCP/IP connection will be negotiated
350
+
/// with the server.
351
+
///
352
+
/// By default, the SSL mode is [`Prefer`](SSLMode::Prefer), and the client will
353
+
/// first attempt an SSL connection but fallback to a non-SSL connection on failure.
354
+
///
355
+
/// Ignored for Unix domain socket communication.
356
+
///
357
+
/// # Example
358
+
///
359
+
/// ```rust
360
+
/// # use sea_orm::database::{ConnectOptions, SSLMode};
361
+
/// let options = ConnectOptions::new().ssl_mode(SSLMode::Require);
362
+
/// ```
363
+
pubfnssl_mode(&mutself,mode:SslMode) -> &mutSelf{
364
+
self.ssl_mode = Some(mode);
365
+
self
366
+
}
367
+
368
+
/// Sets the SSL client certificate as a PEM-encoded byte slice.
369
+
///
370
+
/// This should be an ASCII-encoded blob that starts with `-----BEGIN CERTIFICATE-----`.
371
+
///
372
+
/// # Example
373
+
/// Note: embedding SSL certificates and keys in the binary is not advised.
374
+
/// This is for illustration purposes only.
375
+
///
376
+
/// ```rust
377
+
/// # use sea_orm::database::{ConnectOptions, SSLMode};
378
+
///
379
+
/// const CERT: &[u8] = b"\
380
+
/// -----BEGIN CERTIFICATE-----
381
+
/// <Certificate data here.>
382
+
/// -----END CERTIFICATE-----";
383
+
///
384
+
/// let options = ConnectOptions::new()
385
+
/// // Providing a CA certificate with less than VerifyCa is pointless
0 commit comments