arachni-reactor 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/lib/arachni/reactor/connection/tls.rb +2 -0
- data/lib/arachni/reactor/version.rb +1 -1
- data/lib/arachni/reactor.rb +44 -66
- data/spec/arachni/reactor/connection/tls_spec.rb +5 -2
- data/spec/arachni/reactor/iterator_spec.rb +1 -1
- data/spec/arachni/reactor/tasks_spec.rb +4 -4
- data/spec/support/helpers/utilities.rb +1 -1
- data/spec/support/servers/echo_tls.rb +1 -1
- data/spec/support/servers/echo_unix.rb +1 -1
- data/spec/support/servers/echo_unix_tls.rb +1 -1
- data/spec/support/shared/connection.rb +9 -9
- data/spec/support/shared/reactor.rb +1 -1
- metadata +31 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ef5b5d0eb1a76745be3671829841cbd1c9780d9c731c12e9933bafadf2c622ff
|
|
4
|
+
data.tar.gz: 0e2a91dc4a9159042ce590bd6c1a09ae61cd660ad18aa9a900a19fe04d2a599d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 314fb418807020a5d9aed021e6bb55063d343ea514ff5b06df75f6b0c894ac3c4e53c25fade813313205e4326841c391e441c2432ad758c6c0142f412cdf85e7
|
|
7
|
+
data.tar.gz: 23a506068c6b7b8c529b3c8d4500d709fb05f8fd8e8c1b40848bf08719104b684602a4816a77a5e79c5515e51dc3a1a367c1d132754ae3d9bc5e8c8f446c6b69
|
data/CHANGELOG.md
CHANGED
|
@@ -113,6 +113,7 @@ module TLS
|
|
|
113
113
|
return ssl_accept if accept?
|
|
114
114
|
|
|
115
115
|
super
|
|
116
|
+
rescue OpenSSL::SSL::SSLErrorWaitReadable
|
|
116
117
|
end
|
|
117
118
|
|
|
118
119
|
private
|
|
@@ -150,6 +151,7 @@ module TLS
|
|
|
150
151
|
@ssl_context
|
|
151
152
|
)
|
|
152
153
|
ssl_socket.sync_close = true
|
|
154
|
+
ssl.accept if @start_immediately
|
|
153
155
|
ssl_socket
|
|
154
156
|
end
|
|
155
157
|
rescue IO::WaitReadable, IO::WaitWritable
|
data/lib/arachni/reactor.rb
CHANGED
|
@@ -414,7 +414,7 @@ class Reactor
|
|
|
414
414
|
def schedule( &block )
|
|
415
415
|
fail_if_not_running
|
|
416
416
|
|
|
417
|
-
if
|
|
417
|
+
if in_same_thread?
|
|
418
418
|
block.call
|
|
419
419
|
else
|
|
420
420
|
next_tick(&block)
|
|
@@ -551,32 +551,8 @@ class Reactor
|
|
|
551
551
|
'The host OS does not support UNIX-domain sockets.'
|
|
552
552
|
end
|
|
553
553
|
|
|
554
|
-
def process_connections
|
|
555
|
-
if @connections.empty?
|
|
556
|
-
sleep @max_tick_interval
|
|
557
|
-
return
|
|
558
|
-
end
|
|
559
|
-
|
|
560
|
-
# Required for OSX as it connects immediately and then #select returns
|
|
561
|
-
# nothing as there's no activity, given that, OpenSSL doesn't get a chance
|
|
562
|
-
# to do its handshake so explicitly connect pending sockets, bypassing #select.
|
|
563
|
-
@connections.each do |_, connection|
|
|
564
|
-
connection._connect if !connection.connected?
|
|
565
|
-
end
|
|
566
|
-
|
|
567
|
-
# Get connections with available events - :read, :write, :error.
|
|
568
|
-
selected = select_connections
|
|
569
|
-
|
|
570
|
-
# Close connections that have errors.
|
|
571
|
-
[selected.delete(:error)].flatten.compact.each(&:close)
|
|
572
|
-
|
|
573
|
-
# Call the corresponding event on the connections.
|
|
574
|
-
selected.each { |event, connections| connections.each(&"_#{event}".to_sym) }
|
|
575
|
-
end
|
|
576
|
-
|
|
577
554
|
def determine_connection_options( *args )
|
|
578
555
|
options = {}
|
|
579
|
-
host = port = unix_socket = nil
|
|
580
556
|
|
|
581
557
|
if args[1].is_a? Integer
|
|
582
558
|
options[:host], options[:port], options[:handler], *handler_options = *args
|
|
@@ -634,6 +610,22 @@ class Reactor
|
|
|
634
610
|
@connections.values.each(&:close)
|
|
635
611
|
end
|
|
636
612
|
|
|
613
|
+
def process_connections
|
|
614
|
+
if @connections.empty?
|
|
615
|
+
sleep @max_tick_interval
|
|
616
|
+
return
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
# Get connections with available events - :read, :write, :error.
|
|
620
|
+
selected = self.select_connections
|
|
621
|
+
|
|
622
|
+
# Close connections that have errors.
|
|
623
|
+
selected.delete(:error)&.each(&:close)
|
|
624
|
+
|
|
625
|
+
# Call the corresponding event on the connections.
|
|
626
|
+
selected.each { |event, connections| connections.each(&"_#{event}".to_sym) }
|
|
627
|
+
end
|
|
628
|
+
|
|
637
629
|
# @return [Hash]
|
|
638
630
|
#
|
|
639
631
|
# Connections grouped by their available events:
|
|
@@ -643,17 +635,34 @@ class Reactor
|
|
|
643
635
|
# {Connection#has_outgoing_data? outgoing buffer).
|
|
644
636
|
# * `:error`
|
|
645
637
|
def select_connections
|
|
646
|
-
|
|
638
|
+
r = []
|
|
639
|
+
w = []
|
|
640
|
+
e = []
|
|
641
|
+
|
|
642
|
+
@connections.values.each do |connection|
|
|
643
|
+
|
|
644
|
+
# Required for OSX as it connects immediately and then #select returns
|
|
645
|
+
# nothing as there's no activity, given that, OpenSSL doesn't get a chance
|
|
646
|
+
# to do its handshake so explicitly connect pending sockets, bypassing #select.
|
|
647
|
+
connection._connect if !connection.connected?
|
|
648
|
+
|
|
649
|
+
socket = connection.socket
|
|
650
|
+
|
|
651
|
+
e << socket
|
|
652
|
+
|
|
653
|
+
if connection.listener? || connection.connected?
|
|
654
|
+
r << socket
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
if connection.connected? && connection.has_outgoing_data?
|
|
658
|
+
w << socket
|
|
659
|
+
end
|
|
660
|
+
end
|
|
647
661
|
|
|
648
662
|
selected_sockets =
|
|
649
663
|
begin
|
|
650
664
|
Connection::Error.translate do
|
|
651
|
-
select(
|
|
652
|
-
readables,
|
|
653
|
-
write_sockets,
|
|
654
|
-
all_sockets,
|
|
655
|
-
@select_timeout
|
|
656
|
-
)
|
|
665
|
+
select( r, w, e, @select_timeout )
|
|
657
666
|
end
|
|
658
667
|
rescue Connection::Error => e
|
|
659
668
|
nil
|
|
@@ -668,8 +677,8 @@ class Reactor
|
|
|
668
677
|
# So force a read for SSL sockets to cover all our bases.
|
|
669
678
|
#
|
|
670
679
|
# This is apparent especially on JRuby.
|
|
671
|
-
if
|
|
672
|
-
(
|
|
680
|
+
if r.size != selected_sockets[0].size
|
|
681
|
+
(r - selected_sockets[0]).each do |socket|
|
|
673
682
|
next if !socket.is_a?( OpenSSL::SSL::SSLSocket )
|
|
674
683
|
selected_sockets[0] << socket
|
|
675
684
|
end
|
|
@@ -689,39 +698,8 @@ class Reactor
|
|
|
689
698
|
}
|
|
690
699
|
end
|
|
691
700
|
|
|
692
|
-
# @return [Array<Socket>]
|
|
693
|
-
# Sockets of all connections, we want to be ready to read at any time.
|
|
694
|
-
def read_sockets
|
|
695
|
-
s = []
|
|
696
|
-
@connections.each do |_, connection|
|
|
697
|
-
next if !connection.listener? && !connection.connected?
|
|
698
|
-
s << connection.socket
|
|
699
|
-
end
|
|
700
|
-
s
|
|
701
|
-
end
|
|
702
|
-
|
|
703
|
-
# @return [Array<Socket>]
|
|
704
|
-
# Sockets of connections with
|
|
705
|
-
# {Connection#has_outgoing_data? outgoing data}.
|
|
706
|
-
def write_sockets
|
|
707
|
-
s = []
|
|
708
|
-
@connections.each do |_, connection|
|
|
709
|
-
next if connection.connected? && !connection.has_outgoing_data?
|
|
710
|
-
s << connection.socket
|
|
711
|
-
end
|
|
712
|
-
s
|
|
713
|
-
end
|
|
714
|
-
|
|
715
|
-
def all_sockets
|
|
716
|
-
@connections.values.map(&:socket)
|
|
717
|
-
end
|
|
718
|
-
|
|
719
701
|
def connections_from_sockets( sockets )
|
|
720
|
-
sockets.map { |s|
|
|
721
|
-
end
|
|
722
|
-
|
|
723
|
-
def connection_from_socket( socket )
|
|
724
|
-
@connections[socket.to_io]
|
|
702
|
+
sockets.map { |s| @connections[s.to_io] }
|
|
725
703
|
end
|
|
726
704
|
|
|
727
705
|
end
|
|
@@ -129,10 +129,12 @@ describe Arachni::Reactor::Connection::TLS do
|
|
|
129
129
|
reactor.listen( host, port, TLSHandler, options )
|
|
130
130
|
|
|
131
131
|
client.write data
|
|
132
|
+
sleep 1
|
|
133
|
+
|
|
132
134
|
reactor.stop
|
|
133
135
|
reactor.wait rescue Arachni::Reactor::Error::NotRunning
|
|
134
136
|
|
|
135
|
-
received_data.
|
|
137
|
+
expect(received_data).to eq data
|
|
136
138
|
end
|
|
137
139
|
end
|
|
138
140
|
|
|
@@ -324,7 +326,8 @@ describe Arachni::Reactor::Connection::TLS do
|
|
|
324
326
|
connection.write data
|
|
325
327
|
end
|
|
326
328
|
|
|
327
|
-
|
|
329
|
+
sleep 1
|
|
330
|
+
expect(received).to eq data
|
|
328
331
|
end
|
|
329
332
|
end
|
|
330
333
|
|
|
@@ -25,14 +25,14 @@ describe Arachni::Reactor::Tasks do
|
|
|
25
25
|
context 'when it includes the given task' do
|
|
26
26
|
it 'returns true' do
|
|
27
27
|
subject << task
|
|
28
|
-
subject.
|
|
28
|
+
expect(subject.include?( task )).to be_truthy
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
context 'when it does not includes the given task' do
|
|
33
33
|
it 'returns false' do
|
|
34
34
|
subject << task
|
|
35
|
-
subject.
|
|
35
|
+
expect(subject.include?( another_task )).to be_falsey
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -125,8 +125,8 @@ describe Arachni::Reactor::Tasks do
|
|
|
125
125
|
|
|
126
126
|
subject.call
|
|
127
127
|
|
|
128
|
-
called_one.should
|
|
129
|
-
called_two.should
|
|
128
|
+
called_one.should be_truthy
|
|
129
|
+
called_two.should be_truthy
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
it 'returns self' do
|
|
@@ -114,7 +114,7 @@ def convert_server_to_ssl( server, options = {} )
|
|
|
114
114
|
context.cert.version = 2
|
|
115
115
|
context.cert.serial = 1
|
|
116
116
|
|
|
117
|
-
context.cert.sign( context.key, OpenSSL::Digest::
|
|
117
|
+
context.cert.sign( context.key, OpenSSL::Digest::SHA256.new )
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
OpenSSL::SSL::SSLServer.new( server, context )
|
|
@@ -290,10 +290,10 @@ shared_examples_for 'Arachni::Reactor::Connection' do
|
|
|
290
290
|
|
|
291
291
|
reactor.run_in_thread
|
|
292
292
|
|
|
293
|
-
connection.attach( reactor ).should
|
|
293
|
+
connection.attach( reactor ).should be_truthy
|
|
294
294
|
sleep 1
|
|
295
295
|
|
|
296
|
-
reactor.attached?( configured ).should
|
|
296
|
+
reactor.attached?( configured ).should be_truthy
|
|
297
297
|
end
|
|
298
298
|
|
|
299
299
|
it 'calls #on_attach' do
|
|
@@ -319,7 +319,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
|
|
|
319
319
|
connection.attach reactor
|
|
320
320
|
sleep 0.1 while connection.detached?
|
|
321
321
|
|
|
322
|
-
connection.attach( reactor ).should
|
|
322
|
+
connection.attach( reactor ).should be_falsey
|
|
323
323
|
end
|
|
324
324
|
end
|
|
325
325
|
|
|
@@ -337,11 +337,11 @@ shared_examples_for 'Arachni::Reactor::Connection' do
|
|
|
337
337
|
r.run_in_thread
|
|
338
338
|
|
|
339
339
|
configured.should receive(:on_detach)
|
|
340
|
-
connection.attach( r ).should
|
|
340
|
+
connection.attach( r ).should be_truthy
|
|
341
341
|
|
|
342
342
|
sleep 2
|
|
343
343
|
|
|
344
|
-
r.attached?( configured ).should
|
|
344
|
+
r.attached?( configured ).should be_truthy
|
|
345
345
|
end
|
|
346
346
|
end
|
|
347
347
|
end
|
|
@@ -363,7 +363,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
|
|
|
363
363
|
connection.detach
|
|
364
364
|
sleep 0.1 while connection.attached?
|
|
365
365
|
|
|
366
|
-
reactor.attached?( configured ).should
|
|
366
|
+
reactor.attached?( configured ).should be_falsey
|
|
367
367
|
end
|
|
368
368
|
|
|
369
369
|
it 'calls #on_detach' do
|
|
@@ -582,7 +582,7 @@ shared_examples_for 'Arachni::Reactor::Connection' do
|
|
|
582
582
|
end
|
|
583
583
|
end
|
|
584
584
|
|
|
585
|
-
configured.called_on_flush.should
|
|
585
|
+
configured.called_on_flush.should be_truthy
|
|
586
586
|
end
|
|
587
587
|
end
|
|
588
588
|
end
|
|
@@ -601,13 +601,13 @@ shared_examples_for 'Arachni::Reactor::Connection' do
|
|
|
601
601
|
configured.write 'test'
|
|
602
602
|
sleep 0.1 while !configured.has_outgoing_data?
|
|
603
603
|
|
|
604
|
-
configured.has_outgoing_data?.should
|
|
604
|
+
configured.has_outgoing_data?.should be_truthy
|
|
605
605
|
end
|
|
606
606
|
end
|
|
607
607
|
|
|
608
608
|
context 'when the send-buffer is empty' do
|
|
609
609
|
it 'returns false' do
|
|
610
|
-
configured.has_outgoing_data?.should
|
|
610
|
+
configured.has_outgoing_data?.should be_falsey
|
|
611
611
|
end
|
|
612
612
|
end
|
|
613
613
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: arachni-reactor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tasos Laskos
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-12-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |2
|
|
14
14
|
Arachni::Reactor is a simple, lightweight, pure-Ruby implementation of the Reactor
|
|
@@ -97,45 +97,44 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
97
97
|
- !ruby/object:Gem::Version
|
|
98
98
|
version: '0'
|
|
99
99
|
requirements: []
|
|
100
|
-
|
|
101
|
-
rubygems_version: 2.5.1
|
|
100
|
+
rubygems_version: 3.3.0.dev
|
|
102
101
|
signing_key:
|
|
103
102
|
specification_version: 4
|
|
104
103
|
summary: A pure-Ruby implementation of the Reactor pattern.
|
|
105
104
|
test_files:
|
|
106
|
-
- spec/
|
|
107
|
-
- spec/
|
|
105
|
+
- spec/arachni/reactor/connection/tls_spec.rb
|
|
106
|
+
- spec/arachni/reactor/connection_spec.rb
|
|
107
|
+
- spec/arachni/reactor/iterator_spec.rb
|
|
108
|
+
- spec/arachni/reactor/queue_spec.rb
|
|
109
|
+
- spec/arachni/reactor/tasks/base.rb
|
|
110
|
+
- spec/arachni/reactor/tasks/delayed_spec.rb
|
|
111
|
+
- spec/arachni/reactor/tasks/one_off_spec.rb
|
|
112
|
+
- spec/arachni/reactor/tasks/periodic_spec.rb
|
|
113
|
+
- spec/arachni/reactor/tasks/persistent_spec.rb
|
|
114
|
+
- spec/arachni/reactor/tasks_spec.rb
|
|
115
|
+
- spec/arachni/reactor_spec.rb
|
|
116
|
+
- spec/arachni/reactor_tls_spec.rb
|
|
117
|
+
- spec/spec_helper.rb
|
|
118
|
+
- spec/support/fixtures/handlers/echo_client.rb
|
|
119
|
+
- spec/support/fixtures/handlers/echo_client_tls.rb
|
|
120
|
+
- spec/support/fixtures/handlers/echo_server.rb
|
|
121
|
+
- spec/support/fixtures/handlers/echo_server_tls.rb
|
|
108
122
|
- spec/support/fixtures/pems/cacert.pem
|
|
109
|
-
- spec/support/fixtures/pems/client/foo-key.pem
|
|
110
123
|
- spec/support/fixtures/pems/client/cert.pem
|
|
111
124
|
- spec/support/fixtures/pems/client/foo-cert.pem
|
|
125
|
+
- spec/support/fixtures/pems/client/foo-key.pem
|
|
112
126
|
- spec/support/fixtures/pems/client/key.pem
|
|
113
|
-
- spec/support/fixtures/
|
|
114
|
-
- spec/support/fixtures/
|
|
115
|
-
- spec/support/fixtures/handlers/echo_client_tls.rb
|
|
116
|
-
- spec/support/fixtures/handlers/echo_server_tls.rb
|
|
117
|
-
- spec/support/servers/echo_unix.rb
|
|
118
|
-
- spec/support/servers/echo_tls.rb
|
|
119
|
-
- spec/support/servers/echo.rb
|
|
120
|
-
- spec/support/servers/echo_unix_tls.rb
|
|
121
|
-
- spec/support/helpers/utilities.rb
|
|
127
|
+
- spec/support/fixtures/pems/server/cert.pem
|
|
128
|
+
- spec/support/fixtures/pems/server/key.pem
|
|
122
129
|
- spec/support/helpers/paths.rb
|
|
123
|
-
- spec/support/
|
|
124
|
-
- spec/support/lib/servers/runner.rb
|
|
130
|
+
- spec/support/helpers/utilities.rb
|
|
125
131
|
- spec/support/lib/server_option_parser.rb
|
|
126
|
-
- spec/support/
|
|
132
|
+
- spec/support/lib/servers/runner.rb
|
|
133
|
+
- spec/support/lib/servers.rb
|
|
134
|
+
- spec/support/servers/echo.rb
|
|
135
|
+
- spec/support/servers/echo_tls.rb
|
|
136
|
+
- spec/support/servers/echo_unix.rb
|
|
137
|
+
- spec/support/servers/echo_unix_tls.rb
|
|
127
138
|
- spec/support/shared/connection.rb
|
|
139
|
+
- spec/support/shared/reactor.rb
|
|
128
140
|
- spec/support/shared/task.rb
|
|
129
|
-
- spec/spec_helper.rb
|
|
130
|
-
- spec/arachni/reactor_tls_spec.rb
|
|
131
|
-
- spec/arachni/reactor_spec.rb
|
|
132
|
-
- spec/arachni/reactor/queue_spec.rb
|
|
133
|
-
- spec/arachni/reactor/tasks_spec.rb
|
|
134
|
-
- spec/arachni/reactor/connection_spec.rb
|
|
135
|
-
- spec/arachni/reactor/iterator_spec.rb
|
|
136
|
-
- spec/arachni/reactor/connection/tls_spec.rb
|
|
137
|
-
- spec/arachni/reactor/tasks/base.rb
|
|
138
|
-
- spec/arachni/reactor/tasks/persistent_spec.rb
|
|
139
|
-
- spec/arachni/reactor/tasks/delayed_spec.rb
|
|
140
|
-
- spec/arachni/reactor/tasks/one_off_spec.rb
|
|
141
|
-
- spec/arachni/reactor/tasks/periodic_spec.rb
|