@@ -79,12 +79,12 @@ def send_recv(packet_payload)
79
79
end
80
80
rescue Errno ::ECONNRESET
81
81
if @state == :metakey_state
82
- fail 'Server reset the connection. Probably rejecting ' \
83
- 'the private key and/or client name (e.g. client name not associated ' \
84
- 'with client public key on server side). ' \
85
- 'Wrong server public key possible too. ' \
86
- 'Please recheck client name, client private key and ' \
87
- 'server public key.'
82
+ fail 'Server reset the connection. Probably rejecting ' +
83
+ 'the private key and/or client name (e.g. client name not associated ' +
84
+ 'with client public key on server side). ' +
85
+ 'Wrong server public key possible too. ' +
86
+ 'Please recheck client name, client private key and ' +
87
+ 'server public key.'
88
88
else
89
89
fail 'Server reset the connection, reason unknown.'
90
90
end
@@ -149,7 +149,7 @@ def process_data(data)
149
149
data = read_line
150
150
vprint_status ( "Received Metakey from server: [#{ data [ 0 ..30 ] } ...]" )
151
151
data = data . split ( ' ' )
152
- fail 'Error in protocol. The first byte should be an ASCII 1.' unless data [ 0 ] == '1'
152
+ fail 'Error in protocol. The first byte should be an ASCII 1.' unless data . first == '1'
153
153
hexkey_s2 = data [ 5 ] . rstrip # ("\n")
154
154
fail "Error in protocol. metakey length should be #{ @client_key_len } ." unless hexkey_s2 . length == @client_key_len * 2
155
155
@enckey_s2 = [ hexkey_s2 ] . pack ( 'H*' )
@@ -179,10 +179,10 @@ def process_data(data)
179
179
need_len = 2 * @client_key_len + 3
180
180
if @inbuffer . length >= need_len
181
181
data = pop_inbuffer_and_decrypt ( need_len )
182
- vprint_status ( "Received challenge from server: " \
183
- "[#{ data . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
182
+ vprint_status ( "Received challenge from server: " +
183
+ "[#{ data . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
184
184
data = data . split ( ' ' , 2 )
185
- fail 'Error in protocol. The first byte should be an ASCII 2. Got #{data[0]}.' unless data [ 0 ] == '2'
185
+ fail 'Error in protocol. The first byte should be an ASCII 2. Got #{data[0]}.' unless data . first == '2'
186
186
challenge2 = data [ 1 ] [ 0 ...2 * @client_key_len ]
187
187
challenge2 = [ challenge2 ] . pack ( 'H*' )
188
188
fail "Error in protocol. challenge2 length should be #{ @client_key_len } ." unless challenge2 . length == @client_key_len
@@ -193,17 +193,17 @@ def process_data(data)
193
193
need_len = 43
194
194
if @inbuffer . length >= need_len
195
195
data = pop_inbuffer_and_decrypt ( need_len )
196
- vprint_status ( "Received challenge reply from server:" \
197
- " [#{ data . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
196
+ vprint_status ( "Received challenge reply from server:" +
197
+ " [#{ data . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
198
198
@state = :ack_state
199
199
ack
200
200
end
201
201
when :ack_state
202
202
need_len = 12
203
203
if @inbuffer . length >= need_len
204
204
data = pop_inbuffer_and_decrypt ( need_len )
205
- vprint_status ( "Received ack (server accepted challenge response):" \
206
- "[#{ data . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
205
+ vprint_status ( "Received ack (server accepted challenge response):" +
206
+ "[#{ data . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
207
207
@state = :done_state
208
208
send_packet
209
209
end
@@ -216,7 +216,7 @@ def process_data(data)
216
216
#
217
217
def handle_write
218
218
# handle encryption queue first
219
- if @encryption_queue . length > 0
219
+ unless @encryption_queue . empty?
220
220
msg = @encryption_queue [ 0 ]
221
221
@encryption_queue . delete_at ( 0 )
222
222
@buffer = @bf_enc_cipher . update ( msg )
@@ -225,10 +225,10 @@ def handle_write
225
225
# the resulting block is used to encrypt the next block.
226
226
end
227
227
228
- if @buffer . length > 0
228
+ unless @buffer . empty?
229
229
sent = send_data ( @buffer )
230
- vprint_status ( "Sent #{ sent } bytes: " \
231
- "[#{ @buffer . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
230
+ vprint_status ( "Sent #{ sent } bytes: " +
231
+ "[#{ @buffer . unpack ( 'H*' ) [ 0 ] [ 0 ..30 ] } ...]" )
232
232
@buffer = @buffer [ sent ..@buffer . length ]
233
233
end
234
234
end
@@ -318,8 +318,8 @@ def challenge_reply(challenge2)
318
318
# Ack state to signalise challenge/response was successfull
319
319
#
320
320
def ack
321
- vprint_status ( 'Sending ack (signalise server that we accept challenge' \
322
- 'reply, ciphertext)' )
321
+ vprint_status ( 'Sending ack (signalise server that we accept challenge' +
322
+ 'reply, ciphertext)' )
323
323
@encryption_queue . push ( "4 #{ datastore [ 'RPORT' ] } 123 0 \n " )
324
324
handle_write
325
325
end
0 commit comments