Skip to content

Commit bbfb668

Browse files
committed
Move to using padding like TLS
1 parent c622e1a commit bbfb668

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

nodejs/ece.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function unpad(data, last) {
338338
}
339339
} else {
340340
if (data[i] !== 1) {
341-
throw new Error('record needs to start padding with a 1');
341+
throw new Error('last record needs to start padding with a 2');
342342
}
343343
}
344344
return data.slice(0, i);

python/http_ece/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,13 @@ def unpad_legacy(data):
232232
def unpad(data, last):
233233
i = len(data) - 1
234234
for i in range(len(data) - 1, -1, -1):
235-
x = struct.unpack('B', data[i:i+1])[0]
236-
if x != 0:
237-
if not last and x != 1:
235+
v = struct.unpack('B', data[i:i+1])[0]
236+
if v != 0:
237+
if not last and v != 1:
238238
raise ECEException(u'record delimiter != 1')
239-
if last and x != 2:
239+
if last and v != 2:
240240
raise ECEException(u'last record delimiter != 2')
241241
return data[0:i]
242-
i -= 1
243242
raise ECEException(u'all zero record plaintext')
244243

245244
if version not in versions:
@@ -341,7 +340,7 @@ def encrypt_record(key, nonce, counter, buf, last):
341340
if version == 'aes128gcm':
342341
data = encryptor.update(buf + (b'\x02' if last else b'\x01'))
343342
else:
344-
data = encryptor.update((b"\0" * pad_size) + buf)
343+
data = encryptor.update((b"\x00" * pad_size) + buf)
345344
data += encryptor.finalize()
346345
data += encryptor.tag
347346
return data

python/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'Programming Language :: Python :: 2.7',
2424
'Programming Language :: Python :: 3.4',
2525
'Programming Language :: Python :: 3.5',
26+
'Programming Language :: Python :: 3.6',
2627
],
2728
keywords='crypto http',
2829
install_requires=[

0 commit comments

Comments
 (0)