Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use base64 encoding in preference to ascii85 for v2 protocol #28

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flaskserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ def _complete_server_call_v1(pin_func, udata):
return jsonify({'encrypted_key': encrypted_key.hex(),
'hmac': hmac.hex()})

# NOTE: v2 is one concatentated field, ascii85-encoded
# NOTE: v2 is one concatentated field, base64-encoded
def _complete_server_call_v2(pin_func, udata):
assert 'data' in udata
data = base64.a85decode(udata['data'].encode())
data = base64.b64decode(udata['data'].encode())
assert len(data) > 37 # cke and counter and some encrypted payload

cke = data[:33]
Expand All @@ -99,7 +99,7 @@ def _complete_server_call_v2(pin_func, udata):
assert len(encrypted_key) == AES_KEY_LEN_256 + (2*AES_BLOCK_LEN) + HMAC_SHA256_LEN

# Return response
return jsonify({'data': base64.a85encode(encrypted_key).decode()})
return jsonify({'data': base64.b64encode(encrypted_key).decode()})

def _complete_server_call(pin_func):
try:
Expand Down
8 changes: 4 additions & 4 deletions test/test_pinserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def server_call_v1(self, private_key, client, endpoint, pin_secret, entropy,
# Make the server call to get/set the pin - returns the decrypted response
# NOTE: signature covers replay counter
# NOTE: implicit hmac
# NOTE: all fields concatenated into one, and ascii85 encoded
# NOTE: all fields concatenated into one, and base64 encoded
def server_call_v2(self, private_key, client, endpoint, pin_secret, entropy,
fn_perturb_request=None):
assert isinstance(client, PINClientECDHv2)
Expand All @@ -179,16 +179,16 @@ def server_call_v2(self, private_key, client, endpoint, pin_secret, entropy,
if fn_perturb_request:
urldata = fn_perturb_request(urldata)

# v2 concatenates all the fields into one and uses ascii85-encoding
# v2 concatenates all the fields into one and uses base64-encoding
cke = bytes.fromhex(urldata.get('cke', ''))
replay_counter = bytes.fromhex(urldata.get('replay_counter', ''))
encrypted = bytes.fromhex(urldata.get('encrypted_data', ''))
payload = cke + replay_counter + encrypted
data = base64.a85encode(payload).decode()
data = base64.b64encode(payload).decode()
urldata = {'data': data}

response = self.post(endpoint, urldata)
encrypted = base64.a85decode(response['data'].encode())
encrypted = base64.b64decode(response['data'].encode())

# Return decrypted payload
return client.decrypt_response_payload(encrypted)
Expand Down
Loading