byte encoding changed to ASCII

This commit is contained in:
deflax 2016-04-02 02:53:16 +03:00
parent 73e1eba43a
commit d98ca0c5ae
3 changed files with 9 additions and 9 deletions

View file

@ -23,8 +23,8 @@ def addclient(vmid, vmname, clientid, clientname, clientemail, vmpass):
newpass = utils.genpassword(30) newpass = utils.genpassword(30)
ioconfig.logger.info('client[{}]> initial password is: {}'.format(clientid, newpass)) ioconfig.logger.info('client[{}]> initial password is: {}'.format(clientid, newpass))
salt = bcrypt.gensalt() salt = bcrypt.gensalt()
b_newpass = newpass.encode('utf-8') b_newpass = newpass.encode('ascii')
encpasswd = bcrypt.hashpw(b_newpass, salt).decode('utf-8') encpasswd = bcrypt.hashpw(b_newpass, salt).decode('ascii')
vcard = { 'name':str(clientname), 'email':str(clientemail), 'encpasswd':str(encpasswd) } vcard = { 'name':str(clientname), 'email':str(clientemail), 'encpasswd':str(encpasswd) }
newclient = { str(clientid):vcard } newclient = { str(clientid):vcard }
clientsdb.update(newclient) clientsdb.update(newclient)
@ -42,8 +42,8 @@ def addclient(vmid, vmname, clientid, clientname, clientemail, vmpass):
def setencpasswd(clientemail, newpass): def setencpasswd(clientemail, newpass):
""" setup a new management password """ """ setup a new management password """
salt = bcrypt.gensalt() salt = bcrypt.gensalt()
b_newpass = newpass.encode('utf-8') b_newpass = newpass.encode('ascii')
encpasswd = bcrypt.hashpw(b_newpass, salt).decode('utf-8') encpasswd = bcrypt.hashpw(b_newpass, salt).decode('ascii')
try: try:
clientsdb = readclientsdb() clientsdb = readclientsdb()
@ -82,8 +82,8 @@ def validate(clientemail, password):
#2. check the password #2. check the password
encpass = clientsdb[c_id]['encpasswd'] encpass = clientsdb[c_id]['encpasswd']
b_srvpass = password.encode('utf-8') b_srvpass = password.encode('ascii')
b_encpass = encpass.encode('utf-8') b_encpass = encpass.encode('ascii')
if (hmac.compare_digest(bcrypt.hashpw(b_srvpass, b_encpass), b_encpass)): if (hmac.compare_digest(bcrypt.hashpw(b_srvpass, b_encpass), b_encpass)):
#login successful #login successful

View file

@ -45,8 +45,8 @@ def sync(cached=True):
slave_masterip = config.get(slave_section, 'masterip') slave_masterip = config.get(slave_section, 'masterip')
slave_password = config.get(slave_section, 'password') slave_password = config.get(slave_section, 'password')
slave_regionid = config.get(slave_section, 'regionid') slave_regionid = config.get(slave_section, 'regionid')
enc_slave_password = base64.b64encode(slave_password.encode('ascii')) #encode base64 to avoid shoulder surfers enc_slave_password = base64.b64encode(slave_password.encode('ascii')) #encode base64 in grid
decoded_password = enc_slave_password.decode('utf-8') decoded_password = enc_slave_password.decode('ascii')
real_slave = { "id":slave_id, "slave":slave_name, "masterip":slave_masterip, "password":decoded_password } real_slave = { "id":slave_id, "slave":slave_name, "masterip":slave_masterip, "password":decoded_password }
optional_slave = {} optional_slave = {}
cache_file = 'cache-slave-' + slave_id + '.json' cache_file = 'cache-slave-' + slave_id + '.json'

View file

@ -46,7 +46,7 @@ def apicheck(params):
#API methods #API methods
class Validate(object): class Validate(object):
def on_post(self, req, resp): def on_post(self, req, resp):
""" get clientemail and mgmt pass and compare it with the client db and returns an authed object ID """ """ get clientemail and password and compare it with the client db and returns a list of managed object IDs """
clientemail = req.params['clientemail'] clientemail = req.params['clientemail']
passwd = req.params['password'] passwd = req.params['password']
logger.info('grid> access requested for {} with {}'.format(clientemail, passwd)) logger.info('grid> access requested for {} with {}'.format(clientemail, passwd))