Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 43a215f

Browse files
Master container fixes
1 parent 38c0cc1 commit 43a215f

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

vantage/node/docker_manager.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,9 @@ def get_result(self):
278278
self.active_tasks.remove(finished_task)
279279

280280
# retrieve results from file
281-
with open(finished_task["output_file"]) as fp:
281+
with open(finished_task["output_file"], "rb") as fp:
282282
results = fp.read()
283283

284-
import json
285-
if results:
286-
results = json.loads(results)
287-
288284
return Result(
289285
result_id=finished_task["result_id"],
290286
logs=log,

vantage/node/proxy_server.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import requests
1414
import os
1515
import logging
16+
import json
1617

1718
from flask import Flask, request, jsonify
1819

@@ -21,6 +22,7 @@
2122
unpack_bytes_from_transport,
2223
prepare_bytes_for_transport
2324
)
25+
from vantage.constants import STRING_ENCODING
2426
from vantage.node.server_io import ClientNodeProtocol
2527
from vantage.node.encryption import Cryptor
2628

@@ -82,7 +84,7 @@ def proxy_task():
8284
log.debug(f"{n_organizations} organizations, attemping to encrypt")
8385
encrypted_organizations = []
8486
for organization in organizations:
85-
input_ = organization.get("input", b"")
87+
input_ = organization.get("input", {})
8688
if not input_:
8789
log.error("No input for organization?!")
8890
return
@@ -98,6 +100,12 @@ def proxy_task():
98100

99101
public_key = response.json().get("public_key")
100102

103+
# Simple JSON (only for unencrypted collaborations)
104+
if isinstance(input_, dict):
105+
input_ = prepare_bytes_for_transport(
106+
json.dumps(input_).encode(STRING_ENCODING)
107+
)
108+
101109
input_unpacked = unpack_bytes_from_transport(input_)
102110
encrypted_input = server_io.cryptor.encrypt_bytes_to_base64(
103111
input_unpacked, public_key)
@@ -142,7 +150,10 @@ def proxy_task_result(id):
142150
result["result"] = server_io.cryptor.decrypt_bytes_from_base64(
143151
result["result"]
144152
)
145-
unencrypted.append(result)
153+
result["result"] = prepare_bytes_for_transport(result["result"])
154+
unencrypted.append(
155+
result
156+
)
146157

147158
log.error(unencrypted)
148159

@@ -172,9 +183,11 @@ def proxy_results(id):
172183
headers={'Authorization': auth}
173184
)
174185
encrypted_input = response["result"]
175-
response["result"] = server_io.cryptor.decrypt_bytes_from_base64(
176-
response["result"]
177-
)
186+
response["result"] = prepare_bytes_for_transport(
187+
server_io.cryptor.decrypt_bytes_from_base64(
188+
response["result"]
189+
)
190+
)
178191
log.error(response)
179192
except Exception as e:
180193
log.error("Proxyserver was unable to retrieve results! (2)")

vantage/node/server_io.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ def get_results(self, id=None, state=None, include_task=False,
361361

362362
except ValueError as e:
363363
self.log.warn(
364-
"Could not decrypt input."
365-
"Assuming input was not encrypted"
364+
"Could not decrypt (or unpack in case no encryption "
365+
"is used) input."
366366
)
367367
self.log.debug(e)
368368

@@ -770,27 +770,20 @@ def patch_results(self, id: int, initiator_id: int, result: dict):
770770
task. This is required because we want to encrypt the
771771
results specifically for him
772772
773-
TODO clean, does this actually already work?
774-
TODO when encryption is disabled, we do not need to encrypt
775-
the results either
776773
TODO the key `results` is not always presend, for e.g. when
777774
only the timestamps are updated
778775
"""
779-
780776
if "result" in result:
781777
self.log.debug(
782778
f"retrieving public key from organization={initiator_id}"
783779
)
784780
public_key = self.request(f"organization/{initiator_id}")\
785781
.get("public_key")
786782

787-
self.log.debug(public_key)
783+
# self.log.debug(public_key)
788784

789-
results_unpacked = unpack_bytes_from_transport(
790-
result["result"])
791-
792785
result["result"] = self.cryptor.encrypt_bytes_to_base64(
793-
results_unpacked, public_key
786+
result["result"], public_key
794787
)
795788
self.log.debug("Sending encrypted results to server")
796789

0 commit comments

Comments
 (0)