Skip to content

Commit d98a06f

Browse files
committed
Fix all
1 parent fcb52d6 commit d98a06f

File tree

16 files changed

+71
-75
lines changed

16 files changed

+71
-75
lines changed

lib/packetgen/plugin/crypto.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def compute_iv_for_decrypting(salt, msg)
100100
# @param [String] salt salt to use
101101
# @return [void]
102102
def compute_iv_for_encrypting(iv, salt) # rubocop:disable Naming/MethodParameterName
103-
real_iv = force_binary(salt) + force_binary(iv)
103+
real_iv = salt.b + iv.b
104104
real_iv += [1].pack('N') if confidentiality_mode == 'ctr'
105105
@conf.iv = real_iv
106106
end

lib/packetgen/plugin/esp.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ def initialize(options={})
140140
def read(str)
141141
return self if str.nil?
142142

143-
force_binary str
144-
self[:spi].read str[0, 4]
145-
self[:sn].read str[4, 4]
146-
self[:tfc].read ''
147-
self[:padding].read ''
143+
str = str.b
144+
self[:spi].read(str[0, 4])
145+
self[:sn].read(str[4, 4])
146+
self[:tfc].read('')
147+
self[:padding].read('')
148148

149149
read_icv_dependent_fields(str[8..-1])
150150
read_icv(str)
@@ -239,7 +239,7 @@ def read_icv(str)
239239
def get_auth_data(opt)
240240
ad = self[:spi].to_s
241241
if opt[:esn]
242-
@esn = BinStruct::Int32.new(opt[:esn])
242+
@esn = BinStruct::Int32.new(value: opt[:esn])
243243
ad << @esn.to_s if @conf.authenticated?
244244
end
245245
ad << self[:sn].to_s
@@ -273,12 +273,12 @@ def encrypt_set_pad_length
273273
def encrypt_set_padding(opt)
274274
if opt[:pad_length]
275275
self.pad_length = opt[:pad_length]
276-
padding = force_binary(opt[:padding] || (1..self.pad_length).to_a.pack('C*'))
277-
self[:padding].read padding
276+
padding = opt[:padding] || (1..self.pad_length).to_a.pack('C*')
278277
else
279-
padding = force_binary(opt[:padding] || (1..self.pad_length).to_a.pack('C*'))
280-
self[:padding].read padding[0...self.pad_length]
278+
padding = opt[:padding] || (1..self.pad_length).to_a.pack('C*')
279+
padding = padding[0...self.pad_length]
281280
end
281+
self[:padding].read(padding)
282282
end
283283

284284
def generate_tfc(opt)
@@ -293,7 +293,7 @@ def generate_tfc(opt)
293293
else
294294
(tfc_size / 4) * 4
295295
end
296-
tfc = force_binary("\0" * tfc_size)
296+
tfc = "\0".b * tfc_size
297297
end
298298
tfc
299299
end

lib/packetgen/plugin/ike/sk.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def decrypt!(cipher, options={})
9595
opt = { salt: '', parse: true }.merge!(options)
9696

9797
set_crypto cipher, opt[:intmode]
98-
iv = compute_iv_for_decrypting(force_binary(opt[:salt]), self[:content])
98+
iv = compute_iv_for_decrypting(opt[:salt].b, self[:content])
9999

100100
if authenticated?
101101
if @icv_length.zero?
@@ -163,7 +163,7 @@ def authenticate_if_needed(iv, icv=nil) # rubocop:disable Naming/MethodParameter
163163

164164
def encrypt_body(iv, opt) # rubocop:disable Naming/MethodParameterName
165165
padding, pad_length = compute_padding(iv, opt)
166-
msg = self[:body].to_s + padding + BinStruct::Int8.new(pad_length).to_s
166+
msg = self[:body].to_s + padding.b + BinStruct::Int8.new(value: pad_length).to_s
167167
encrypted_msg = encipher(msg)
168168
@conf.final # message is already padded. No need for mode padding
169169
encrypted_msg
@@ -172,10 +172,10 @@ def encrypt_body(iv, opt) # rubocop:disable Naming/MethodParameterName
172172
def compute_padding(iv, opt) # rubocop:disable Naming/MethodParameterName
173173
if opt[:pad_length]
174174
pad_length = opt[:pad_length]
175-
padding = force_binary(opt[:padding] || ([0] * pad_length).pack('C*'))
175+
padding = opt[:padding] || ([0] * pad_length).pack('C*')
176176
else
177177
pad_length = compute_pad_length(iv)
178-
padding = force_binary(opt[:padding] || ([0] * pad_length).pack('C*'))
178+
padding = opt[:padding] || ([0] * pad_length).pack('C*')
179179
padding = padding[0, pad_length]
180180
end
181181
[padding, pad_length]

spec/esp_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Plugin
1414
end
1515

1616
it 'in UDP packets' do
17-
int32 = PacketGen::Types::Int32.new(1)
17+
int32 = BinStruct::Int32.new(value: 1)
1818
expect(PacketGen::Header::UDP).to know_header(ESP).with(dport: 4500, sport: nil, body: int32.to_s)
1919
expect(PacketGen::Header::UDP).to know_header(ESP).with(sport: 4500, dport: nil, body: int32.to_s)
2020
int32.value = 0
@@ -117,8 +117,8 @@ module Plugin
117117
esp.body = 'body'
118118
esp.spi = 1
119119
esp.sn = 2
120-
expected = [1, 2].pack('N2') + 'body' + "\x00" * 2
121-
expect(esp.to_s).to eq(force_binary expected)
120+
expected = [1, 2].pack('N2') + 'body'.b + "\x00".b * 2
121+
expect(esp.to_s).to eq(expected)
122122
end
123123
end
124124

@@ -127,7 +127,7 @@ module Plugin
127127
esp = ESP.new
128128
str = esp.inspect
129129
expect(str).to be_a(String)
130-
(esp.fields - %i(body)).each do |attr|
130+
(esp.attributes - %i(body)).each do |attr|
131131
expect(str).to include(attr.to_s)
132132
end
133133
end
@@ -196,7 +196,7 @@ module Plugin
196196
key = [key.to_s(16)].pack('H*')
197197
salt = [0xe6971987.to_s(16)].pack('H*')
198198
cipher = get_cipher('gcm', :encrypt, key)
199-
iv = force_binary("\xD9\xD2\x1F\xCE\xDA\xE0Uj")
199+
iv = "\xD9\xD2\x1F\xCE\xDA\xE0Uj".b
200200
black_pkt.esp.encrypt! cipher, iv, salt: salt, tfc: true, tfc_size: 1000
201201
expect(black_pkt.esp.to_s).to eq(esp_pkt.esp.to_s)
202202
end
@@ -215,7 +215,7 @@ module Plugin
215215
pkt.esp.decrypt!(cipher, salt: salt, esn: 0)
216216

217217
cipher = get_cipher('gcm', :encrypt, key)
218-
iv = force_binary("\xAB\r\xE6M\x84E\xF7V")
218+
iv = "\xAB\r\xE6M\x84E\xF7V".b
219219
pkt.esp.encrypt! cipher, iv, salt: salt, esn: 0
220220
expect(pkt.to_s).to eq(expected_pkt_s)
221221
end
@@ -234,7 +234,7 @@ module Plugin
234234

235235
black_pkt.esp.decrypt! get_cipher('gcm', :decrypt, key), salt: salt
236236
expect(black_pkt.esp.pad_length).to eq(2)
237-
expect(black_pkt.esp.padding).to eq(force_binary("\xff\xff"))
237+
expect(black_pkt.esp.padding).to eq("\xff\xff".b)
238238
end
239239

240240
it 'encrypts a payload with given padding length' do
@@ -269,8 +269,8 @@ module Plugin
269269

270270
black_pkt.esp.decrypt! get_cipher('gcm', :decrypt, key), salt: salt
271271
expect(black_pkt.esp.pad_length).to eq(15)
272-
expect(black_pkt.esp.padding).to eq(force_binary("\xff" * 15))
273-
expect(black_pkt.body[-9..-1]).to eq(force_binary("\xff" * 9))
272+
expect(black_pkt.esp.padding).to eq("\xff".b * 15)
273+
expect(black_pkt.body[-9..-1]).to eq("\xff".b * 9)
274274
end
275275
end
276276

@@ -315,8 +315,8 @@ module Plugin
315315
cipher = get_cipher('gcm', :decrypt, key)
316316
expect(pkt.esp.decrypt!(cipher, salt: salt)).to be(true)
317317
expect(pkt.esp.tfc.length).to eq(916)
318-
expect(pkt.esp.tfc).to eq(force_binary("\x00" * 916))
319-
expect(pkt.esp.padding).to eq(force_binary("\x01\x02"))
318+
expect(pkt.esp.tfc).to eq("\x00".b * 916)
319+
expect(pkt.esp.padding).to eq("\x01\x02".b)
320320
expect(pkt.esp.body.to_s).to eq(red_pkt.ip.to_s)
321321
end
322322

@@ -343,7 +343,7 @@ module Plugin
343343

344344
cipher = get_cipher('gcm', :decrypt, key)
345345
expect(pkt.esp.decrypt!(cipher, salt: salt, parse: false)).to be(true)
346-
expect(pkt.esp[:body]).to be_a(Types::String)
346+
expect(pkt.esp[:body]).to be_a(BinStruct::String)
347347
end
348348

349349
it 'returns false when ICV check failed' do
@@ -399,7 +399,7 @@ module Plugin
399399
pkt.body.read("\x00" * 16)
400400
str = pkt.to_s
401401
pkt2 = Packet.parse(str)
402-
expect(pkt2.udp[:body]).to be_a(Types::String)
402+
expect(pkt2.udp[:body]).to be_a(BinStruct::String)
403403
end
404404
end
405405
end

spec/ike/auth_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class IKE
7070
it 'returns a binary string' do
7171
auth = Auth.new(next: 2, auth_method: 'PASSWORD', content: 'abcd')
7272
auth.calc_length
73-
expected = "\x02\x00\x00\x0c\x0c\x00\x00\x00abcd"
74-
expect(auth.to_s).to eq(force_binary expected)
73+
expected = "\x02\x00\x00\x0c\x0c\x00\x00\x00abcd".b
74+
expect(auth.to_s).to eq(expected)
7575
end
7676
end
7777

spec/ike/cert_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class IKE
6969
it 'returns a binary string' do
7070
cert = Cert.new(next: 2, encoding: 'X509_CERT_SIG', content: 'abcd')
7171
cert.calc_length
72-
expected = "\x02\x00\x00\x09\x04abcd"
73-
expect(cert.to_s).to eq(force_binary expected)
72+
expected = "\x02\x00\x00\x09\x04abcd".b
73+
expect(cert.to_s).to eq(expected)
7474
end
7575
end
7676

@@ -79,7 +79,7 @@ class IKE
7979
cert = Cert.new
8080
str = cert.inspect
8181
expect(str).to be_a(String)
82-
(cert.fields - %i(body)).each do |attr|
82+
(cert.attributes - %i(body)).each do |attr|
8383
expect(str).to include(attr.to_s)
8484
end
8585
end

spec/ike/certreq_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class IKE
6969
it 'returns a binary string' do
7070
certreq = CertReq.new(next: 2, encoding: 'X509_CERT_SIG', content: 'a' * 20)
7171
certreq.calc_length
72-
expected = "\x02\x00\x00\x19\x04" + 'a' * 20
73-
expect(certreq.to_s).to eq(force_binary expected)
72+
expected = ("\x02\x00\x00\x19\x04" + 'a' * 20).b
73+
expect(certreq.to_s).to eq(expected)
7474
end
7575
end
7676

@@ -79,7 +79,7 @@ class IKE
7979
certreq = CertReq.new(content: 'a' * 20 + 'b' * 20)
8080
str = certreq.inspect
8181
expect(str).to be_a(String)
82-
(certreq.fields - %i(body)).each do |attr|
82+
(certreq.attributes - %i(body)).each do |attr|
8383
expect(str).to include(attr.to_s)
8484
if attr == :content
8585
expect(str).to match(/^\s+hashes/)

spec/ike/id_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ class IKE
7979
it 'returns a binary string' do
8080
id = IDi.new(next: 2, type: 'IPV6_ADDR', content: IPAddr.new('8000::1').hton)
8181
id.calc_length
82-
expected = "\x02\x00\x00\x18\x05\x00\x00\x00\x80" + "\0" * 14 + "\x01"
83-
expect(id.to_s).to eq(force_binary expected)
82+
expected = ("\x02\x00\x00\x18\x05\x00\x00\x00\x80" + "\0" * 14 + "\x01").b
83+
expect(id.to_s).to eq(expected)
8484

8585
name = OpenSSL::X509::Name.parse('/CN=toto/DC=tata').to_der
8686
id = IDi.new(next: 2, type: 'DER_ASN1_DN', content: name)
8787
id.calc_length
88-
expected = "\x02\x00\x00\x2f\x09\x00\x00\x00" + name
89-
expect(id.to_s).to eq(force_binary expected)
88+
expected = ("\x02\x00\x00\x2f\x09\x00\x00\x00" + name).b
89+
expect(id.to_s).to eq(expected)
9090
end
9191
end
9292

spec/ike/ke_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class IKE
5050
it 'returns a binary string' do
5151
ke = KE.new(next: 1, group: 'ECP256', content: 'abcdefghijkl')
5252
ke.calc_length
53-
expected = "\x01\x00\x00\x14\x00\x13\x00\x00abcdefghijkl"
54-
expect(ke.to_s).to eq(force_binary expected)
53+
expected = "\x01\x00\x00\x14\x00\x13\x00\x00abcdefghijkl".b
54+
expect(ke.to_s).to eq(expected)
5555
end
5656
end
5757

@@ -60,7 +60,7 @@ class IKE
6060
ke = KE.new
6161
str = ke.inspect
6262
expect(str).to be_a(String)
63-
(ke.fields - %i(body)).each do |attr|
63+
(ke.attributes - %i(body)).each do |attr|
6464
expect(str).to include(attr.to_s)
6565
end
6666
end

spec/ike/nonce_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class IKE
4545
it 'returns a binary string' do
4646
nonce = Nonce.new(next: 2, content: 'abcdefghijkl')
4747
nonce.calc_length
48-
expected = "\x02\x00\x00\x10abcdefghijkl"
49-
expect(nonce.to_s).to eq(force_binary expected)
48+
expected = "\x02\x00\x00\x10abcdefghijkl".b
49+
expect(nonce.to_s).to eq(expected)
5050
end
5151
end
5252

@@ -55,7 +55,7 @@ class IKE
5555
nonce = Nonce.new
5656
str = nonce.inspect
5757
expect(str).to be_a(String)
58-
(nonce.fields - %i(body)).each do |attr|
58+
(nonce.attributes - %i(body)).each do |attr|
5959
expect(str).to include(attr.to_s)
6060
end
6161
end

0 commit comments

Comments
 (0)