Skip to content

Commit 0393ed8

Browse files
committed
Update python to match node, bump version numbers
1 parent 0309902 commit 0393ed8

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http_ece",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "Encrypted Content-Encoding for HTTP",
55
"homepage": "https://github.com/martinthomson/encrypted-content-encoding",
66
"bugs": "https://github.com/martinthomson/encrypted-content-encoding/issues",

python/http_ece/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
keys = {}
1111
labels = {}
1212

13-
def deriveKey(mode, salt, key=None, dh=None, keyid=None, authSecret=None):
13+
def deriveKey(mode, salt, key=None, dh=None, keyid=None, authSecret=None, padSize=2):
1414
def buildInfo(base, context):
1515
return b"Content-Encoding: " + base + b"\0" + context
1616

@@ -63,24 +63,27 @@ def lengthPrefix(key):
6363
)
6464
secret = hkdf_auth.derive(secret)
6565

66-
keyinfo = b"aesgcm"
6766
if padSize == 2:
68-
keyinfo = b"aesgcm128"
69-
elif padSize != 1:
67+
keyinfo = buildInfo(b"aesgcm", context)
68+
nonceinfo = buildInfo(b"nonce", context)
69+
elif padSize == 1:
70+
keyinfo = b"Content-Encoding: aesgcm128"
71+
nonceinfo = b"Content-Encoding: nonce"
72+
else:
7073
raise Exception(u"unable to set context for padSize=" + str(padSize))
7174

7275
hkdf_key = HKDF(
7376
algorithm=hashes.SHA256(),
7477
length=16,
7578
salt=salt,
76-
info=buildInfo(keyinfo, context),
79+
info=keyinfo,
7780
backend=default_backend()
7881
)
7982
hkdf_nonce = HKDF(
8083
algorithm=hashes.SHA256(),
8184
length=12,
8285
salt=salt,
83-
info=buildInfo(b"nonce", context),
86+
info=nonceinfo,
8487
backend=default_backend()
8588
)
8689
result = (hkdf_key.derive(secret), hkdf_nonce.derive(secret))
@@ -108,7 +111,7 @@ def decryptRecord(key, nonce, counter, buffer):
108111

109112
(key_, nonce_) = deriveKey(mode="decrypt", salt=salt,
110113
key=key, keyid=keyid, dh=dh,
111-
authSecret=authSecret)
114+
authSecret=authSecret, padSize=padSize)
112115
if rs <= padSize:
113116
raise Exception(u"Record size too small")
114117
rs += 16 # account for tags
@@ -135,7 +138,7 @@ def encryptRecord(key, nonce, counter, buffer):
135138

136139
(key_, nonce_) = deriveKey(mode="encrypt", salt=salt,
137140
key=key, keyid=keyid, dh=dh,
138-
authSecret=authSecret)
141+
authSecret=authSecret, padSize=padSize)
139142
if rs <= padSize:
140143
raise Exception(u"Record size too small")
141144
rs -= padSize # account for padding

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='http_ece',
6-
version='0.4.2',
6+
version='0.4.3',
77
author='Martin Thomson',
88
author_email='martin.thomson@gmail.com',
99
scripts=[],

0 commit comments

Comments
 (0)