Agent identifier is useless.
This commit is contained in:
19
essai.csr
19
essai.csr
@@ -1,19 +0,0 @@
|
|||||||
-----BEGIN CERTIFICATE REQUEST-----
|
|
||||||
MIIDHzCCAgcCAQIwdDEbMBkGA1UEAwwScHJpbnRlci50cm9uZWwub3JnMQ8wDQYD
|
|
||||||
VQQKDAZUcm9uZWwxEzARBgNVBAsMCnRyb25lbC5vcmcxCzAJBgNVBAYTAkZSMREw
|
|
||||||
DwYDVQQIDAhCcml0YW5ueTEPMA0GA1UEBwwGQmV0dG9uMIIBIjANBgkqhkiG9w0B
|
|
||||||
AQEFAAOCAQ8AMIIBCgKCAQEAtypYhk+YsTH+hIM1sZ7VcjmPkpPyZli0k/4TJExs
|
|
||||||
rVQVfFrNNCgJVLDrH524YfFJR1yqz1DSD87ng2A0VZrHIQKMPOKPYVHUZ5+mF7Zm
|
|
||||||
SvE4J2eOwMdakTBSBydVgf8JXR7sXKM4t+pO5vpc+lRxqm8n1idnlwjiK1+dHjb9
|
|
||||||
BgXNWf6W5/hp51J2vWWZEyTj2iFiEkmrFQLrQc8kD9lf3SRvkCSXp15cG+ZwFyNs
|
|
||||||
55/BM5TgDv9ItUGHXUKINDcQSNL8LJS2Q3plNLzIg1x1jkycN7YtdIfPwHaKB0Ru
|
|
||||||
GACpnGRxUAUqDA5NHWTWA1FXXXr1FvEE22sjLu9klMy3dwIDAQABoGYwZAYJKoZI
|
|
||||||
hvcNAQkOMVcwVTALBgNVHQ8EBAMCBPAwJwYDVR0lBCAwHgYIKwYBBQUHAwEGCCsG
|
|
||||||
AQUFBwMCBggrBgEFBQcDBDAdBgNVHREEFjAUghJwcmludGVyLnRyb25lbC5vcmcw
|
|
||||||
DQYJKoZIhvcNAQELBQADggEBAHEDemzBPk3YBoDekGXXwnINBBbqjvnha+wF7bQZ
|
|
||||||
t9IoJJpVWo9M8hAtheZ0wTHDsbmesSms4R3DYQQmaCVk+NoK0AZb79LwLW3O8IF0
|
|
||||||
C47bIPevN0V/A7UIVM36MrzhGz55tj7133zXxeyXQG0oiVy1bIAlfUwAZeY/4ihI
|
|
||||||
FAHnuCDE+BfQsd8R4iZP6mUC9qBlTztmfbKwPkpwcHNMbUCqosFx1vSY5/BKQuyt
|
|
||||||
QJ72ZBVtlB2Se2G0FE0qzqLP1FoGp8f3hwEayJsakbvRq+NfV7NhcmfgFegybU4H
|
|
||||||
+eLeaLVEzAYnvxeKVUP8ievbif/Spzo6R9msUq2lCbf59GU=
|
|
||||||
-----END CERTIFICATE REQUEST-----
|
|
||||||
@@ -30,64 +30,6 @@ def getBearer(hostname, verify, username, password):
|
|||||||
|
|
||||||
baseUrl = 'https://%s' % hostname
|
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.')
|
logger.info('Retrieving redirection to login URL.')
|
||||||
|
|
||||||
authUrl = baseUrl+'/cdm/oauth2/v1/authorize'
|
authUrl = baseUrl+'/cdm/oauth2/v1/authorize'
|
||||||
@@ -96,9 +38,14 @@ def getBearer(hostname, verify, username, password):
|
|||||||
nonce = createNonce()
|
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'}
|
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:
|
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)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
@@ -115,7 +62,8 @@ def getBearer(hostname, verify, username, password):
|
|||||||
adminUrl = baseUrl+'/cdm/security/v1/deviceAdminConfig'
|
adminUrl = baseUrl+'/cdm/security/v1/deviceAdminConfig'
|
||||||
|
|
||||||
authenticationUrl = baseUrl+'/cdm/security/v1/authenticate'
|
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.')
|
logger.info('Authenticating to receive authentication code.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user