@@ -339,15 +339,15 @@ def jabber_connect_msg(hostname)
339
339
340
340
def tls_jabber
341
341
sock . put ( jabber_connect_msg ( xmpp_domain ) )
342
- res = sock . get_once ( - 1 , response_timeout )
342
+ res = get_data
343
343
if res && res . include? ( 'host-unknown' )
344
344
jabber_host = res . match ( / from='([\w .]*)' / )
345
345
if jabber_host && jabber_host [ 1 ]
346
346
disconnect
347
347
establish_connect
348
348
vprint_status ( "#{ peer } - Connecting with autodetected remote XMPP hostname: #{ jabber_host [ 1 ] } ..." )
349
349
sock . put ( jabber_connect_msg ( jabber_host [ 1 ] ) )
350
- res = sock . get_once ( - 1 , response_timeout )
350
+ res = get_data
351
351
end
352
352
end
353
353
if res . nil? || res . include? ( 'stream:error' ) || res !~ /<starttls xmlns=['"]urn:ietf:params:xml:ns:xmpp-tls['"]/
@@ -356,14 +356,14 @@ def tls_jabber
356
356
end
357
357
msg = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
358
358
sock . put ( msg )
359
- res = sock . get_once ( - 1 , response_timeout )
359
+ res = get_data
360
360
return nil if res . nil? || !res . include? ( '<proceed' )
361
361
res
362
362
end
363
363
364
364
def tls_ftp
365
365
# http://tools.ietf.org/html/rfc4217
366
- res = sock . get_once ( - 1 , response_timeout )
366
+ res = get_data
367
367
return nil if res . nil?
368
368
sock . put ( "AUTH TLS\r \n " )
369
369
res = get_data
@@ -383,18 +383,25 @@ def tls_ftp
383
383
# Get data from the socket
384
384
# this ensures the requested length is read (if available)
385
385
def get_data ( length = -1 )
386
-
387
- return sock . get_once ( -1 , response_timeout ) if length == -1
388
-
389
386
to_receive = length
390
387
data = ''
391
- while to_receive > 0
392
- temp = sock . get_once ( to_receive , response_timeout )
388
+ done = false
389
+ while done == false
390
+ begin
391
+ temp = sock . get_once ( to_receive , response_timeout )
392
+ rescue EOFError
393
+ break
394
+ end
395
+
393
396
break if temp . nil?
394
397
395
398
data << temp
396
- to_receive -= temp . length
399
+ if length != -1
400
+ to_receive -= temp . length
401
+ done = true if to_receive <= 0
402
+ end
397
403
end
404
+
398
405
data
399
406
end
400
407
@@ -417,8 +424,7 @@ def establish_connect
417
424
418
425
vprint_status ( "#{ peer } - Sending Client Hello..." )
419
426
sock . put ( client_hello )
420
-
421
- server_hello = sock . get_once ( -1 , response_timeout )
427
+ server_hello = get_data
422
428
unless server_hello
423
429
vprint_error ( "#{ peer } - No Server Hello after #{ response_timeout } seconds..." )
424
430
return nil
@@ -777,19 +783,19 @@ def parse_certificate_data(data)
777
783
cert_len_padding = unpacked [ 0 ]
778
784
cert_len = unpacked [ 1 ]
779
785
vprint_debug ( "\t \t Certificates length: #{ cert_len } " )
786
+ vprint_debug ( "\t \t Data length: #{ data . length } " )
780
787
# contains multiple certs
781
788
already_read = 3
782
789
cert_counter = 0
783
790
while already_read < cert_len
784
- start = already_read
785
791
cert_counter += 1
786
792
# get single certificate length
787
- single_cert_unpacked = data [ start , 3 ] . unpack ( 'Cn' )
793
+ single_cert_unpacked = data [ already_read , 3 ] . unpack ( 'Cn' )
788
794
single_cert_len_padding = single_cert_unpacked [ 0 ]
789
795
single_cert_len = single_cert_unpacked [ 1 ]
790
796
vprint_debug ( "\t \t Certificate ##{ cert_counter } :" )
791
797
vprint_debug ( "\t \t \t Certificate ##{ cert_counter } : Length: #{ single_cert_len } " )
792
- certificate_data = data [ ( start + 3 ) , single_cert_len ]
798
+ certificate_data = data [ ( already_read + 3 ) , single_cert_len ]
793
799
cert = OpenSSL ::X509 ::Certificate . new ( certificate_data )
794
800
# First received certificate is the one from the server
795
801
@cert = cert if @cert . nil?
0 commit comments