@@ -413,14 +413,16 @@ pub fn needs_custom_http_transport(config: &Config) -> CargoResult<bool> {
413
413
let cainfo = config. get_path ( "http.cainfo" ) ?;
414
414
let check_revoke = config. get_bool ( "http.check-revoke" ) ?;
415
415
let user_agent = config. get_string ( "http.user-agent" ) ?;
416
- let ssl_version = config. get_string ( "http.ssl-version" ) ?;
416
+ let has_ssl_version = config. get_string ( "http.ssl-version" ) ?. is_some ( )
417
+ || config. get_string ( "http.ssl-version.min" ) ?. is_some ( )
418
+ || config. get_string ( "http.ssl-version.max" ) ?. is_some ( ) ;
417
419
418
420
Ok ( proxy_exists
419
421
|| timeout
420
422
|| cainfo. is_some ( )
421
423
|| check_revoke. is_some ( )
422
424
|| user_agent. is_some ( )
423
- || ssl_version . is_some ( ) )
425
+ || has_ssl_version )
424
426
}
425
427
426
428
/// Configure a libcurl http handle with the defaults options for Cargo
@@ -440,17 +442,48 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
440
442
handle. useragent ( & version ( ) . to_string ( ) ) ?;
441
443
}
442
444
443
- if let Some ( ssl_version ) = config . get_string ( "http.ssl-version" ) ? {
444
- let version = match ssl_version . val . as_str ( ) {
445
+ fn to_ssl_version ( s : & str ) -> CargoResult < SslVersion > {
446
+ let version = match s {
445
447
"default" => SslVersion :: Default ,
446
448
"tlsv1" => SslVersion :: Tlsv1 ,
447
449
"tlsv1.0" => SslVersion :: Tlsv10 ,
448
450
"tlsv1.1" => SslVersion :: Tlsv11 ,
449
451
"tlsv1.2" => SslVersion :: Tlsv12 ,
450
452
"tlsv1.3" => SslVersion :: Tlsv13 ,
451
- _ => bail ! ( "Invalid ssl version `{}`, choose from 'default', 'tlsv1', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', 'tlsv1.3'." , & ssl_version. val) ,
453
+ _ => bail ! ( "Invalid ssl version `{}`,\
454
+ choose from 'default', 'tlsv1', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', 'tlsv1.3'.",
455
+ s) ,
452
456
} ;
453
- handle. ssl_min_max_version ( version, version) ?;
457
+ Ok ( version)
458
+ }
459
+ if config. get_string ( "http.ssl-version" ) ?. is_some ( )
460
+ || config. get_string ( "http.ssl-version.min" ) ?. is_some ( )
461
+ || config. get_string ( "http.ssl-version.max" ) ?. is_some ( ) {
462
+
463
+ let mut min_version = SslVersion :: Default ;
464
+ let mut max_version = SslVersion :: Default ;
465
+
466
+ // There are two ways to configure `ssl-version`:
467
+ // 1. set single `ssl-version`
468
+ // [http]
469
+ // ssl-version = "tlsv1.3"
470
+ if let Some ( ssl_version) = config. get_string ( "http.ssl-version" ) ? {
471
+ min_version = to_ssl_version ( ssl_version. val . as_str ( ) ) ?;
472
+ max_version = min_version;
473
+ }
474
+
475
+ // 2. set min and max of ssl version respectively
476
+ // [http]
477
+ // ssl-version.min = "tlsv1.2"
478
+ // ssl-version.max = "tlsv1.3"
479
+ if let Some ( ssl_version) = config. get_string ( "http.ssl-version.min" ) ? {
480
+ min_version = to_ssl_version ( ssl_version. val . as_str ( ) ) ?;
481
+ }
482
+ if let Some ( ssl_version) = config. get_string ( "http.ssl-version.max" ) ? {
483
+ max_version = to_ssl_version ( ssl_version. val . as_str ( ) ) ?;
484
+ }
485
+
486
+ handle. ssl_min_max_version ( min_version, max_version) ?;
454
487
}
455
488
456
489
if let Some ( true ) = config. get :: < Option < bool > > ( "http.debug" ) ? {
0 commit comments