@@ -413,14 +413,16 @@ pub fn needs_custom_http_transport(config: &Config) -> CargoResult<bool> {
413413 let cainfo = config. get_path ( "http.cainfo" ) ?;
414414 let check_revoke = config. get_bool ( "http.check-revoke" ) ?;
415415 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 ( ) ;
417419
418420 Ok ( proxy_exists
419421 || timeout
420422 || cainfo. is_some ( )
421423 || check_revoke. is_some ( )
422424 || user_agent. is_some ( )
423- || ssl_version . is_some ( ) )
425+ || has_ssl_version )
424426}
425427
426428/// 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<
440442 handle. useragent ( & version ( ) . to_string ( ) ) ?;
441443 }
442444
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 {
445447 "default" => SslVersion :: Default ,
446448 "tlsv1" => SslVersion :: Tlsv1 ,
447449 "tlsv1.0" => SslVersion :: Tlsv10 ,
448450 "tlsv1.1" => SslVersion :: Tlsv11 ,
449451 "tlsv1.2" => SslVersion :: Tlsv12 ,
450452 "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) ,
452456 } ;
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) ?;
454487 }
455488
456489 if let Some ( true ) = config. get :: < Option < bool > > ( "http.debug" ) ? {
0 commit comments