From 01b75d78c49dff09ba6f4db03152f2ec788b9a0c Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 5 Aug 2020 08:27:09 -0400 Subject: [PATCH] Amend refererer XCC can struggle with link local addresses. Simplify by just using a static fake name so that XCC treats it like maybe some unknown /etc/hosts entry on the client. Change-Id: I1c6dc9d3eb86ae876c24441a924bcff4720b53ac --- pyghmi/ipmi/oem/lenovo/imm.py | 10 ++++------ pyghmi/redfish/oem/lenovo/xcc.py | 4 +++- pyghmi/util/webclient.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 1a1febb0..d9f4ba5f 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -965,22 +965,20 @@ class XCCClient(IMMClient): return None if not login: return wc - srv = self.imm - if ':' in srv: - srv = '[{0}]'.format(self.imm) - referer = 'https://{0}/'.format(srv) adata = json.dumps({'username': self.username, 'password': self.password }) headers = {'Connection': 'keep-alive', - 'Referer': referer, + 'Referer': 'https://xcc/', + 'Host': 'xcc', 'Content-Type': 'application/json'} wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() if rsp.status == 200: rspdata = json.loads(rsp.read()) wc.set_header('Content-Type', 'application/json') - wc.set_header('Referer', referer) + wc.set_header('Referer', 'https://xcc/') + wc.set_header('Host', 'xcc') wc.set_header('Authorization', 'Bearer ' + rspdata['access_token']) if '_csrf_token' in wc.cookies: wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token']) diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index de62a58f..cea4e181 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -463,12 +463,13 @@ class OEMHandler(generic.OEMHandler): return None if not login: return wc - referer = 'https://{0}/'.format(wc.thehost) + referer = 'https://xcc/' adata = json.dumps({'username': self.username, 'password': self.password }) headers = {'Connection': 'keep-alive', 'Referer': referer, + 'Host': 'xcc', 'Content-Type': 'application/json'} wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() @@ -477,6 +478,7 @@ class OEMHandler(generic.OEMHandler): wc.set_header('Content-Type', 'application/json') wc.set_header('Authorization', 'Bearer ' + rspdata['access_token']) wc.set_header('Referer', referer) + wc.set_header('Host', 'xcc') if '_csrf_token' in wc.cookies: wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token']) return wc diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index d9e92aee..7994a467 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -141,7 +141,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): self.cert_reqs = ssl.CERT_NONE # use custom validation else: self.cert_reqs = ssl.CERT_REQUIRED # use standard validation - if '[' not in host and '%' in host: + if '[' not in host and '%' in host and 'Host'not in self.stdheaders: self.stdheaders['Host'] = '[' + host[:host.find('%')] + ']' def dupe(self):