Agent identifier is useless.
This commit is contained in:
@@ -30,64 +30,6 @@ def getBearer(hostname, verify, username, password):
|
||||
|
||||
baseUrl = 'https://%s' % hostname
|
||||
|
||||
try:
|
||||
r = requests.get(baseUrl, verify=verify)
|
||||
except Exception as e:
|
||||
logger.error('Exception: %s' % e)
|
||||
exit(-1)
|
||||
|
||||
if r.status_code != 200:
|
||||
logger.error('Imposible to retrieve base content')
|
||||
exit(-1)
|
||||
|
||||
content = StringIO(r.content.decode('utf8'))
|
||||
|
||||
logger.info('Retrieving main javascript path.')
|
||||
p = re.compile('^.*src="(?P<main>main[^"]+)".*$')
|
||||
|
||||
found = False
|
||||
nbLines = 0
|
||||
for line in content.readlines():
|
||||
nbLines+=1
|
||||
m = p.match(line)
|
||||
if m != None:
|
||||
found = True
|
||||
main = m.group('main')
|
||||
break
|
||||
|
||||
if not found:
|
||||
logger.error('Impossible to retrieve main path.')
|
||||
exit(-1)
|
||||
|
||||
mainUrl = baseUrl+'/'+main
|
||||
logger.debug('Main javascript is located at %s.' % mainUrl)
|
||||
|
||||
r = requests.get(mainUrl, verify=verify)
|
||||
if r.status_code != 200:
|
||||
logger.error('Imposible to retrieve main javascript content.')
|
||||
exit(-1)
|
||||
|
||||
content = StringIO(r.content.decode('utf8'))
|
||||
|
||||
logger.info('Retrieving agent id')
|
||||
p = re.compile('^.*It\.DEVICE_ADMIN="(?P<agentid>[0-9a-f\-]+)".*$')
|
||||
|
||||
found = False
|
||||
nbLines = 0
|
||||
for line in content.readlines():
|
||||
nbLines+=1
|
||||
m = p.match(line)
|
||||
if m != None:
|
||||
found = True
|
||||
agentId = m.group('agentid')
|
||||
break
|
||||
|
||||
if not found:
|
||||
logger.error('Impossible to retrieve agent identifier.')
|
||||
exit(-1)
|
||||
|
||||
logger.debug('Agent identifier: %s' % agentId)
|
||||
|
||||
logger.info('Retrieving redirection to login URL.')
|
||||
|
||||
authUrl = baseUrl+'/cdm/oauth2/v1/authorize'
|
||||
@@ -96,9 +38,14 @@ def getBearer(hostname, verify, username, password):
|
||||
nonce = createNonce()
|
||||
params = { 'response_type':'code', 'client_id':'com.hp.cdm.client.hpEws', 'state':nonce, 'redirect_uri':certificateManagementUrl, 'scope':'com.hp.cdm.auth.alias.deviceRole.deviceAdmin'}
|
||||
|
||||
r = requests.get(authUrl, params=params, allow_redirects=False, verify=verify)
|
||||
try:
|
||||
r = requests.get(authUrl, params=params, allow_redirects=False, verify=verify)
|
||||
except Exception as e:
|
||||
logger.error('Impossible to retrieve URL: %s. Error: %s' % (authUrl, e))
|
||||
exit(-1)
|
||||
|
||||
if r.status_code != 302:
|
||||
logger.error('Impossible to retrieve redirection to login URL')
|
||||
logger.error('Impossible to retrieve redirection to login URL. Status code: %d' % r.status_code)
|
||||
exit(-1)
|
||||
|
||||
|
||||
@@ -115,7 +62,8 @@ def getBearer(hostname, verify, username, password):
|
||||
adminUrl = baseUrl+'/cdm/security/v1/deviceAdminConfig'
|
||||
|
||||
authenticationUrl = baseUrl+'/cdm/security/v1/authenticate'
|
||||
payload = { 'agentId':agentId, 'username':username, 'password':password, 'client_id':'com.hp.cdm.client.hpEws', 'scope':'com.hp.cdm.auth.alias.deviceRole.deviceAdmin', 'grant_type':'authorization_code' , 'state':nonce }
|
||||
# Agent ID is useless
|
||||
payload = { 'username':username, 'password':password, 'client_id':'com.hp.cdm.client.hpEws', 'scope':'com.hp.cdm.auth.alias.deviceRole.deviceAdmin', 'grant_type':'authorization_code' , 'state':nonce }
|
||||
|
||||
logger.info('Authenticating to receive authentication code.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user