Skip to content

Commit

Permalink
Prelogin is working (sending username)
Browse files Browse the repository at this point in the history
Now I need to encode to sjcl.hash.sha256 so the login works
Actually, code "says" it's logged in.... but it's not

Signed-off-by: Christian Tremblay <christian.tremblay@servisys.com>
  • Loading branch information
ChristianTremblay committed Mar 6, 2017
1 parent 7fadc60 commit adf6c0a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 88 deletions.
2 changes: 1 addition & 1 deletion pyhaystack/client/http/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _merge(given, defaults, exclude):
else:
result = (defaults or {}).copy()
if exclude is not None:
for param in exclude:
for param in given:
result.pop(param, None)

if given is not None:
Expand Down
2 changes: 1 addition & 1 deletion pyhaystack/client/http/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _request(self, method, uri, callback, body,
raise HTTPRedirectError(e.message)
except requests.exceptions.ConnectionError as e:
raise HTTPConnectionError(e.strerror, e.errno)
except requests.exceptions.RequestException:
except requests.exceptions.RequestException as e:
# TODO: handle this with a more specific exception
raise HTTPBaseError(e.message)

Expand Down
58 changes: 0 additions & 58 deletions pyhaystack/client/niagara4_v2.py

This file was deleted.

1 change: 1 addition & 0 deletions pyhaystack/client/ops/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def _on_response(self, response):
decoded = [hszinc.parse(body, mode=hszinc.MODE_JSON)]
else:
# We don't recognise this!
print(body)
raise ValueError('Unrecognised content type %s' % content_type)

# Check for exceptions
Expand Down
4 changes: 2 additions & 2 deletions pyhaystack/client/ops/vendor/niagara.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ....util import state
from ....util.asyncexc import AsynchronousException
from ...http.auth import BasicAuthenticationCredentials
from ...http.auth import DigestAuthenticationCredentials
from ...http.exceptions import HTTPStatusError

class NiagaraAXAuthenticateOperation(state.HaystackOperation):
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, session, retries=0):
self._retries = retries
self._session = session
self._cookies = {}
self._auth = BasicAuthenticationCredentials(session._username,
self._auth = DigestAuthenticationCredentials(session._username,
session._password)

self._state_machine = fysom.Fysom(
Expand Down
55 changes: 30 additions & 25 deletions pyhaystack/client/ops/vendor/niagara4.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

from ....util import state
from ....util.asyncexc import AsynchronousException
from ...http.auth import BasicAuthenticationCredentials
from ...http.auth import DigestAuthenticationCredentials
from ...http.exceptions import HTTPStatusError

class Niagara4AuthenticateOperation(state.HaystackOperation):
"""
An implementation of the log-in procedure for Niagara AX. The procedure
An implementation of the log-in procedure for Niagara 4. The procedure
is as follows:
1. Do a request of the log-in URL, without credentials. This sets session
Expand Down Expand Up @@ -49,10 +49,11 @@ def __init__(self, session, retries=0):
"""

super(Niagara4AuthenticateOperation, self).__init__()
print('init')
self._retries = retries
self._session = session
self._cookies = {}
self._auth = BasicAuthenticationCredentials(session._username,
self._auth = DigestAuthenticationCredentials(session._username,
session._password)

self._state_machine = fysom.Fysom(
Expand All @@ -79,6 +80,7 @@ def go(self):
Start the request.
"""
# Are we logged in?
print('Go called')
try:
self._state_machine.get_new_session()
except: # Catch all exceptions to pass to caller.
Expand All @@ -88,9 +90,10 @@ def _do_new_session(self, event):
"""
Request the log-in cookie.
"""
print('New session called')
try:
self._session._get('prelogin?clear=true', self._on_new_session,
cookies={}, headers={}, exclude_cookies=True,
cookies={}, headers={}, exclude_cookies=False,
exclude_headers=True, api=False)
except: # Catch all exceptions to pass to caller.
self._state_machine.exception(result=AsynchronousException())
Expand All @@ -99,6 +102,7 @@ def _on_new_session(self, response):
"""
Retrieve the log-in cookie.
"""
print('Response : ')
try:
if isinstance(response, AsynchronousException):
try:
Expand All @@ -109,8 +113,8 @@ def _on_new_session(self, response):
else:
raise

self._cookies = response.cookies.copy()
print(self._cookies)
self._cookies = self._session._client._session.cookies.get_dict().copy()
print('Cookies', self._cookies)
self._state_machine.do_username()
except: # Catch all exceptions to pass to caller.
self._state_machine.exception(result=AsynchronousException())
Expand All @@ -119,15 +123,14 @@ def _do_username(self, event):
"""
Prelogin step : enter username
"""
print('Prelogin step')
try:
self._session._post('prelogin', self._on_username,
params={
'token':'',
'scheme':'cookieDigest',
'absPathBase':'/',
'Referer':self._session._client.uri+'prelogin/',
'accept':'text/zinc; charset=utf-8',
'cookiePostfix' : self._cookies['JSESSIONID'],
self._session._post('login-submit', self._on_username,
params={
'Referer':self._session._client.uri+'/prelogin/',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'contentType':'application/x-www-form-urlencoded',
'Cookie' : self._cookies['JSESSIONID'],
},
headers={}, cookies=self._cookies,
exclude_cookies=True, exclude_proxies=True,
Expand All @@ -139,6 +142,7 @@ def _on_username(self, response):
"""
Retrieve the log-in cookie.
"""
print('On Username')
try:
if isinstance(response, AsynchronousException):
try:
Expand All @@ -149,25 +153,23 @@ def _on_username(self, response):
else:
raise

print(response.text)

self._cookies = response.cookies.copy()
print('cookies', self._cookies)
print(response)
self._cookies = self._session._client._session.cookies.get_dict().copy()
#self._cookies = response.cookies.copy()
print('2- cookies', self._cookies)
self._state_machine.do_login()
except: # Catch all exceptions to pass to caller.
self._state_machine.exception(result=AsynchronousException())


def _do_login(self, event):
print('Do Login...')
try:
self._session._post('login', self._on_login,
self._session._get('j_security_check', self._on_login,
params={
'token':'',
'scheme':'cookieDigest',
'absPathBase':'/',
'Referer':self._session._client.uri+'login/',
'accept':'text/zinc; charset=utf-8',
'cookiePostfix' : self._cookies['JSESSIONID'],
'Referer':self._session._client.uri+'/login/',
'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Cookie' : self._cookies['JSESSIONID'],
},
headers={}, cookies=self._cookies,
exclude_cookies=True, exclude_proxies=True,
Expand All @@ -179,6 +181,8 @@ def _on_login(self, response):
"""
See if the login succeeded.
"""
print('On Login')
print(response)
try:
if isinstance(response, AsynchronousException):
try:
Expand All @@ -204,6 +208,7 @@ def _do_fail_retry(self, event):
"""
if self._retries > 0:
self._retries -= 1
print('Retry')
self._state_machine.retry()
else:
self._state_machine.abort(result=event.result)
Expand Down
2 changes: 1 addition & 1 deletion pyhaystack/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

__author__ = 'Christian Tremblay, Stuart J. Longland, @sudo-Whateverman, Igor'
__author_email__ = 'christian.tremblay@servisys.com'
__version__ = '0.91.1.1'
__version__ = '0.91.1.2'
__license__ = 'LGPL'
__copyright__ = "Christian Tremblay / SERVISYS inc. | Stuart J. Longland / VRT | 2016"

0 comments on commit adf6c0a

Please sign in to comment.