@@ -20,6 +20,9 @@ class SSL
2020 ssl_context ::METHODS . reject { |method | method . match ( /server|client/ ) }
2121 end . sort . reverse
2222
23+ # Returns OpenSSL::SSL::*_VERSION values for min_version and max_version
24+ MIN_MAX_VERSIONS = OpenSSL ::SSL . constants . select { |constant | constant =~/_VERSION$/ } . map { |version | version . to_s . gsub ( /_VERSION$/ , '' ) . to_sym } . reverse
25+
2326 # Returns whether SSL configuration is present.
2427 def present?
2528 ( verify_mode == :none ) || ( cert && cert_key ) || ca_cert_file
@@ -90,6 +93,36 @@ def ssl_version=(version)
9093 @ssl_version = version
9194 end
9295
96+ # Returns the SSL min_version number. Defaults to <tt>nil</tt> (auto-negotiate).
97+ def min_version
98+ @min_version ||= nil
99+ end
100+
101+ # Sets the SSL min_version number. Expects one of <tt>HTTPI::Auth::SSL::MIN_MAX_VERSIONS</tt>.
102+ def min_version = ( version )
103+ unless MIN_MAX_VERSIONS . include? version
104+ raise ArgumentError , "Invalid SSL min_version #{ version . inspect } \n " +
105+ "Please specify one of #{ MIN_MAX_VERSIONS . inspect } "
106+ end
107+
108+ @min_version = version
109+ end
110+
111+ # Returns the SSL min_version number. Defaults to <tt>nil</tt> (auto-negotiate).
112+ def max_version
113+ @max_version ||= nil
114+ end
115+
116+ # Sets the SSL min_version number. Expects one of <tt>HTTPI::Auth::SSL::MIN_MAX_VERSIONS</tt>.
117+ def max_version = ( version )
118+ unless MIN_MAX_VERSIONS . include? version
119+ raise ArgumentError , "Invalid SSL max_version #{ version . inspect } \n " +
120+ "Please specify one of #{ MIN_MAX_VERSIONS . inspect } "
121+ end
122+
123+ @max_version = version
124+ end
125+
93126 # Returns an <tt>OpenSSL::X509::Certificate</tt> for the +cert_file+.
94127 def cert
95128 @cert ||= ( OpenSSL ::X509 ::Certificate . new File . read ( cert_file ) if cert_file )
0 commit comments