Skip to content

Commit 32c1b59

Browse files
committed
Default min_version: to 1 for all TLS methods (closes #500).
* This will allow using TLS 1, 1.1, or 1.2, instead of always using TLS 1.2.
1 parent 7fa3992 commit 32c1b59

File tree

4 files changed

+354
-34
lines changed

4 files changed

+354
-34
lines changed

lib/ronin/support/network/tls.rb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module TLS
4242
#
4343
# @api semipublic
4444
#
45-
def self.context(version: 1.2, **kwargs)
46-
SSL.context(version: version, **kwargs)
45+
def self.context(min_version: 1, **kwargs)
46+
SSL.context(min_version: min_version, **kwargs)
4747
end
4848

4949
#
@@ -92,8 +92,8 @@ def self.context(version: 1.2, **kwargs)
9292
#
9393
# @since 1.1.0
9494
#
95-
def self.socket(socket, version: 1.2, **kwargs)
96-
SSL.socket(socket,version: version, **kwargs)
95+
def self.socket(socket, min_version: 1, **kwargs)
96+
SSL.socket(socket,min_version: min_version, **kwargs)
9797
end
9898

9999
#
@@ -162,8 +162,8 @@ def self.socket(socket, version: 1.2, **kwargs)
162162
#
163163
# @since 1.1.0
164164
#
165-
def self.open?(host,port, version: 1.2, **kwargs)
166-
SSL.open?(host,port, version: version, **kwargs)
165+
def self.open?(host,port, min_version: 1, **kwargs)
166+
SSL.open?(host,port, min_version: min_version, **kwargs)
167167
end
168168

169169
#
@@ -241,8 +241,8 @@ def self.open?(host,port, version: 1.2, **kwargs)
241241
#
242242
# @since 1.1.0
243243
#
244-
def self.connect(host,port, version: 1.2, **kwargs, &block)
245-
SSL.connect(host,port, version: version, **kwargs, &block)
244+
def self.connect(host,port, min_version: 1, **kwargs, &block)
245+
SSL.connect(host,port, min_version: min_version, **kwargs, &block)
246246
end
247247

248248
#
@@ -306,8 +306,8 @@ def self.connect(host,port, version: 1.2, **kwargs, &block)
306306
#
307307
# @since 1.1.0
308308
#
309-
def self.connect_and_send(data,host,port, version: 1.2, **kwargs, &block)
310-
SSL.connect_and_send(data,host,port, version: version, **kwargs, &block)
309+
def self.connect_and_send(data,host,port, min_version: 1, **kwargs, &block)
310+
SSL.connect_and_send(data,host,port, min_version: min_version, **kwargs, &block)
311311
end
312312

313313
#
@@ -366,8 +366,8 @@ def self.connect_and_send(data,host,port, version: 1.2, **kwargs, &block)
366366
#
367367
# @since 1.1.0
368368
#
369-
def self.get_cert(host,port, version: 1.2, **kwargs)
370-
SSL.get_cert(host,port, version: version, **kwargs)
369+
def self.get_cert(host,port, min_version: 1, **kwargs)
370+
SSL.get_cert(host,port, min_version: min_version, **kwargs)
371371
end
372372

373373
#
@@ -436,8 +436,8 @@ def self.get_cert(host,port, version: 1.2, **kwargs)
436436
#
437437
# @since 1.1.0
438438
#
439-
def self.banner(host,port, version: 1.2, **kwargs, &block)
440-
SSL.banner(host,port, version: version, **kwargs, &block)
439+
def self.banner(host,port, min_version: 1, **kwargs, &block)
440+
SSL.banner(host,port, min_version: min_version, **kwargs, &block)
441441
end
442442

443443
#
@@ -504,8 +504,8 @@ def self.banner(host,port, version: 1.2, **kwargs, &block)
504504
#
505505
# @since 1.1.0
506506
#
507-
def self.send(data,host,port, version: 1.2, **kwargs)
508-
SSL.send(data,host,port, version: version, **kwargs)
507+
def self.send(data,host,port, min_version: 1, **kwargs)
508+
SSL.send(data,host,port, min_version: min_version, **kwargs)
509509
end
510510

511511
#
@@ -536,8 +536,8 @@ def self.send(data,host,port, version: 1.2, **kwargs)
536536
#
537537
# @since 1.1.0
538538
#
539-
def self.server_socket(socket, version: 1.2, **kwargs)
540-
SSL.server_socket(socket, version: version, **kwargs)
539+
def self.server_socket(socket, min_version: 1, **kwargs)
540+
SSL.server_socket(socket, min_version: min_version, **kwargs)
541541
end
542542

543543
#
@@ -595,8 +595,8 @@ def self.server_socket(socket, version: 1.2, **kwargs)
595595
#
596596
# @since 1.1.0
597597
#
598-
def self.server(version: 1.2, **kwargs, &block)
599-
SSL.server(version: version, **kwargs, &block)
598+
def self.server(version: 1, **kwargs, &block)
599+
SSL.server(min_version: min_version, **kwargs, &block)
600600
end
601601

602602
#
@@ -655,8 +655,8 @@ def self.server(version: 1.2, **kwargs, &block)
655655
#
656656
# @since 1.1.0
657657
#
658-
def self.server_session(version: 1.2, **kwargs, &block)
659-
SSL.server_session(version: version, **kwargs, &block)
658+
def self.server_session(min_version: 1, **kwargs, &block)
659+
SSL.server_session(min_version: min_version, **kwargs, &block)
660660
end
661661

662662
#
@@ -724,8 +724,8 @@ def self.server_session(version: 1.2, **kwargs, &block)
724724
#
725725
# @since 1.1.0
726726
#
727-
def self.server_loop(version: 1.2, **kwargs, &block)
728-
SSL.server_loop(version: 1.2, **kwargs, &block)
727+
def self.server_loop(min_version: 1, **kwargs, &block)
728+
SSL.server_loop(min_version: min_version, **kwargs, &block)
729729
end
730730

731731
#
@@ -796,8 +796,8 @@ def self.server_loop(version: 1.2, **kwargs, &block)
796796
#
797797
# @since 1.1.0
798798
#
799-
def self.accept(version: 1.2, **kwargs, &block)
800-
SSL.accept(version: version, **kwargs, &block)
799+
def self.accept(min_version: 1, **kwargs, &block)
800+
SSL.accept(min_version: min_version, **kwargs, &block)
801801
end
802802
end
803803
end

lib/ronin/support/network/tls/mixin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ module Mixin
6767
#
6868
# @api semipublic
6969
#
70-
def tls_context(version: 1.2, **kwargs)
71-
TLS.context(version: version, **kwargs)
70+
def tls_context(min_version: 1, **kwargs)
71+
TLS.context(min_version: min_version, **kwargs)
7272
end
7373

7474
#

spec/network/tls/mixin_spec.rb

Lines changed: 161 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@
4848
context "when no version: keyword argument is given" do
4949
let(:context) { double(OpenSSL::SSL::SSLContext) }
5050

51-
it "must call OpenSSL::SSL::SSLContext#ssl_version= with OpenSSL::SSL::TLS1_2_VERSION" do
51+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_VERSION" do
5252
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
53-
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_2_VERSION)
54-
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_2_VERSION)
53+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
5554
allow(context).to receive(:verify_mode=).with(0)
5655

5756
subject.tls_context
@@ -141,6 +140,165 @@
141140
end
142141
end
143142

143+
context "when given the min_version: keyword argument" do
144+
let(:context) { double(OpenSSL::SSL::SSLContext) }
145+
146+
context "and it's 1" do
147+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_VERSION" do
148+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
149+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
150+
allow(context).to receive(:verify_mode=).with(0)
151+
152+
subject.tls_context(min_version: 1)
153+
end
154+
end
155+
156+
context "and it's 1.1" do
157+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_1_VERSION" do
158+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
159+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_1_VERSION)
160+
allow(context).to receive(:verify_mode=).with(0)
161+
162+
subject.tls_context(min_version: 1.1)
163+
end
164+
end
165+
166+
context "and it's 1_2" do
167+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_2_VERSION" do
168+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
169+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_2_VERSION)
170+
allow(context).to receive(:verify_mode=).with(0)
171+
172+
subject.tls_context(min_version: 1.2)
173+
end
174+
end
175+
176+
context "and it's a Symbol" do
177+
let(:symbol) { :TLS1 }
178+
179+
it "must call OpenSSL::SSL::SSLContext#min_version= with the Symbol" do
180+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
181+
expect(context).to receive(:min_version=).with(symbol)
182+
allow(context).to receive(:verify_mode=).with(0)
183+
184+
subject.tls_context(min_version: symbol)
185+
end
186+
187+
context "but it's :TLSv1" do
188+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_VERSION" do
189+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
190+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
191+
allow(context).to receive(:verify_mode=).with(0)
192+
193+
subject.tls_context(min_version: :TLSv1)
194+
end
195+
end
196+
197+
context "but it's :TLSv1_1" do
198+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_1_VERSION" do
199+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
200+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_1_VERSION)
201+
allow(context).to receive(:verify_mode=).with(0)
202+
203+
subject.tls_context(min_version: :TLSv1_1)
204+
end
205+
end
206+
207+
context "but it's :TLSv1_2" do
208+
it "must call OpenSSL::SSL::SSLContext#min_version= with OpenSSL::SSL::TLS1_2_VERSION" do
209+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
210+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_2_VERSION)
211+
allow(context).to receive(:verify_mode=).with(0)
212+
213+
subject.tls_context(min_version: :TLSv1_2)
214+
end
215+
end
216+
end
217+
end
218+
219+
context "when given the max_version: keyword argument" do
220+
let(:context) { double(OpenSSL::SSL::SSLContext) }
221+
222+
context "and it's 1" do
223+
it "must call OpenSSL::SSL::SSLContext#max_version= with OpenSSL::SSL::TLS1_VERSION" do
224+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
225+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
226+
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_VERSION)
227+
allow(context).to receive(:verify_mode=).with(0)
228+
229+
subject.tls_context(max_version: 1)
230+
end
231+
end
232+
233+
context "and it's 1.1" do
234+
it "must call OpenSSL::SSL::SSLContext#max_version= with OpenSSL::SSL::TLS1_1_VERSION" do
235+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
236+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
237+
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_1_VERSION)
238+
allow(context).to receive(:verify_mode=).with(0)
239+
240+
subject.tls_context(max_version: 1.1)
241+
end
242+
end
243+
244+
context "and it's 1_2" do
245+
it "must call OpenSSL::SSL::SSLContext#max_version= with OpenSSL::SSL::TLS1_2_VERSION" do
246+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
247+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
248+
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_2_VERSION)
249+
allow(context).to receive(:verify_mode=).with(0)
250+
251+
subject.tls_context(max_version: 1.2)
252+
end
253+
end
254+
255+
context "and it's a Symbol" do
256+
let(:symbol) { :TLS1 }
257+
258+
it "must call OpenSSL::SSL::SSLContext#max_version= with the Symbol" do
259+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
260+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
261+
expect(context).to receive(:max_version=).with(symbol)
262+
allow(context).to receive(:verify_mode=).with(0)
263+
264+
subject.tls_context(max_version: symbol)
265+
end
266+
267+
context "but it's :TLSv1" do
268+
it "must call OpenSSL::SSL::SSLContext#max_version= with OpenSSL::SSL::TLS1_VERSION" do
269+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
270+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
271+
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_VERSION)
272+
allow(context).to receive(:verify_mode=).with(0)
273+
274+
subject.tls_context(max_version: :TLSv1)
275+
end
276+
end
277+
278+
context "but it's :TLSv1_1" do
279+
it "must call OpenSSL::SSL::SSLContext#max_version= with OpenSSL::SSL::TLS1_1_VERSION" do
280+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
281+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
282+
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_1_VERSION)
283+
allow(context).to receive(:verify_mode=).with(0)
284+
285+
subject.tls_context(max_version: :TLSv1_1)
286+
end
287+
end
288+
289+
context "but it's :TLSv1_2" do
290+
it "must call OpenSSL::SSL::SSLContext#max_version= with OpenSSL::SSL::TLS1_2_VERSION" do
291+
expect(OpenSSL::SSL::SSLContext).to receive(:new).and_return(context)
292+
expect(context).to receive(:min_version=).with(OpenSSL::SSL::TLS1_VERSION)
293+
expect(context).to receive(:max_version=).with(OpenSSL::SSL::TLS1_2_VERSION)
294+
allow(context).to receive(:verify_mode=).with(0)
295+
296+
subject.tls_context(max_version: :TLSv1_2)
297+
end
298+
end
299+
end
300+
end
301+
144302
describe "when given the verify: keyword argument" do
145303
subject { super().tls_context(verify: :peer) }
146304

0 commit comments

Comments
 (0)