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

tenant, web_util: ensure that the content type is actually application/json #845

Merged
merged 2 commits into from
Jan 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions keylime/cloud_verifier_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def prepare_v(agent):
post_data = {
'encrypted_key': b64_encrypted_V
}
v_json_message = json.dumps(post_data)
return v_json_message
return post_data


def prepare_get_quote(agent):
Expand Down
3 changes: 1 addition & 2 deletions keylime/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ def do_quote(self):
if self.payload is not None:
data['payload'] = self.payload.decode('utf-8')

u_json_message = json.dumps(data)

# post encrypted U back to CloudAgent
params = f'/v{self.api_version}/keys/ukey'
Expand All @@ -1038,7 +1037,7 @@ def do_quote(self):
post_ukey = RequestsClient(cloudagent_base_url, tls_enabled=False)
response = post_ukey.post(
params,
data=u_json_message
json=data
)

if response.status_code == 503:
Expand Down
10 changes: 10 additions & 0 deletions keylime/tornado_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from tornado import httpclient

from keylime import json


async def request(method, url, params=None, data=None, context=None, headers=None):

Expand All @@ -20,6 +22,14 @@ async def request(method, url, params=None, data=None, context=None, headers=Non
if context is not None:
url = url.replace('http://', 'https://', 1)

# Convert dict to JSON before sending
if isinstance(data, dict):
data = json.dumps(data)
if headers is None:
headers = {}
if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"

try:
req = httpclient.HTTPRequest(url=url,
method=method,
Expand Down