@@ -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 ( -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
0 commit comments