@@ -7,7 +7,7 @@ use std::time::Duration;
77use std:: { cmp, env} ;
88
99use crates_io:: { NewCrate , NewCrateDependency , Registry } ;
10- use curl:: easy:: { Easy , InfoType , SslOpt } ;
10+ use curl:: easy:: { Easy , InfoType , SslOpt , SslVersion } ;
1111use failure:: { bail, format_err} ;
1212use log:: { log, Level } ;
1313use percent_encoding:: { percent_encode, NON_ALPHANUMERIC } ;
@@ -18,7 +18,7 @@ use crate::core::source::Source;
1818use crate :: core:: { Package , SourceId , Workspace } ;
1919use crate :: ops;
2020use crate :: sources:: { RegistrySource , SourceConfigMap , CRATES_IO_REGISTRY } ;
21- use crate :: util:: config:: { self , Config } ;
21+ use crate :: util:: config:: { self , Config , SslVersionConfig , SslVersionConfigRange } ;
2222use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
2323use crate :: util:: important_paths:: find_root_manifest_for_wd;
2424use crate :: util:: IntoUrl ;
@@ -413,12 +413,14 @@ 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 :: < Option < SslVersionConfig > > ( "http.ssl-version" ) ?;
416417
417418 Ok ( proxy_exists
418419 || timeout
419420 || cainfo. is_some ( )
420421 || check_revoke. is_some ( )
421- || user_agent. is_some ( ) )
422+ || user_agent. is_some ( )
423+ || ssl_version. is_some ( ) )
422424}
423425
424426/// Configure a libcurl http handle with the defaults options for Cargo
@@ -438,6 +440,38 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
438440 handle. useragent ( & version ( ) . to_string ( ) ) ?;
439441 }
440442
443+ fn to_ssl_version ( s : & str ) -> CargoResult < SslVersion > {
444+ let version = match s {
445+ "default" => SslVersion :: Default ,
446+ "tlsv1" => SslVersion :: Tlsv1 ,
447+ "tlsv1.0" => SslVersion :: Tlsv10 ,
448+ "tlsv1.1" => SslVersion :: Tlsv11 ,
449+ "tlsv1.2" => SslVersion :: Tlsv12 ,
450+ "tlsv1.3" => SslVersion :: Tlsv13 ,
451+ _ => bail ! (
452+ "Invalid ssl version `{}`,\
453+ choose from 'default', 'tlsv1', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', 'tlsv1.3'.",
454+ s
455+ ) ,
456+ } ;
457+ Ok ( version)
458+ }
459+ if let Some ( ssl_version) = config. get :: < Option < SslVersionConfig > > ( "http.ssl-version" ) ? {
460+ match ssl_version {
461+ SslVersionConfig :: Single ( s) => {
462+ let version = to_ssl_version ( s. as_str ( ) ) ?;
463+ handle. ssl_version ( version) ?;
464+ }
465+ SslVersionConfig :: Range ( SslVersionConfigRange { min, max } ) => {
466+ let min_version =
467+ min. map_or ( Ok ( SslVersion :: Default ) , |s| to_ssl_version ( s. as_str ( ) ) ) ?;
468+ let max_version =
469+ max. map_or ( Ok ( SslVersion :: Default ) , |s| to_ssl_version ( s. as_str ( ) ) ) ?;
470+ handle. ssl_min_max_version ( min_version, max_version) ?;
471+ }
472+ }
473+ }
474+
441475 if let Some ( true ) = config. get :: < Option < bool > > ( "http.debug" ) ? {
442476 handle. verbose ( true ) ?;
443477 handle. debug_function ( |kind, data| {
0 commit comments