From c894195cb16186dd6415227b79fcccbca26822b2 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 8 Nov 2021 13:24:19 -0500 Subject: [PATCH] Support nonce based web login Support the newer web loogin procedure that requires a nonce to get going. Change-Id: Ia6c532f0e18d2b101ca9cd9ba1c539fdedea2862 --- pyghmi/ipmi/oem/lenovo/imm.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index b414d5da..fa730eb0 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -1035,10 +1035,19 @@ class XCCClient(IMMClient): adata = json.dumps({'username': self.username, 'password': self.password }) + nonce = None + wc.request('POST', '/api/providers/get_nonce', '{}') + rsp = wc.getresponse() + tokbody = rsp.read() + if rsp.status == 200: + rsp = json.loads(tokbody) + nonce = rsp.get('nonce', None) headers = {'Connection': 'keep-alive', 'Referer': 'https://xcc/', 'Host': 'xcc', 'Content-Type': 'application/json'} + if nonce: + headers['Content-Security-Policy'] = 'nonce={0}'.format(nonce) wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() if rsp.status == 200: