1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

* update of cryptomanager Xor

* Fix config command
This commit is contained in:
Adolfo Gómez García 2019-04-10 08:17:52 +02:00
parent 6ab3fd5559
commit 3caa49705e
2 changed files with 7 additions and 10 deletions

View File

@ -132,15 +132,15 @@ class CryptoManager(object):
return
def xor(self, s1, s2):
if isinstance(s1, six.text_type):
if isinstance(s1, str):
s1 = s1.encode('utf-8')
if isinstance(s2, six.text_type):
if isinstance(s2, str):
s2 = s2.encode('utf-8')
mult = int(len(s1) / len(s2)) + 1
s1 = array.array('B', s1)
s2 = array.array('B', s2 * mult)
# We must return bynary in xor, because result is in fact binary
return array.array('B', (s1[i] ^ s2[i] for i in range(len(s1)))).tostring()
return array.array('B', (s1[i] ^ s2[i] for i in range(len(s1)))).tobytes()
def symCrypt(self, text, key):
return self.xor(text, key)

View File

@ -30,9 +30,6 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
from __future__ import unicode_literals
import six
from django.core.management.base import BaseCommand
from uds.core.util.Config import Config, GLOBAL_SECTION, GlobalConfig
import logging
@ -45,14 +42,13 @@ class Command(BaseCommand):
help = "Updates configuration values. If mod is omitted, UDS will be used. Omit whitespaces betwen name, =, and value (they must be a single param)"
def add_arguments(self, parser):
parser.add_argument('name_value', nargs='+', type=six.text_type)
parser.add_argument('name_value', nargs='+', type=str)
def handle(self, *args, **options):
logger.debug("Handling settings")
GlobalConfig.initialize()
try:
for param in options['name_value']:
config = param.decode('utf-8')
for config in options['name_value']:
logger.debug('Config: {}'.format(config))
first, value = config.split('=')
first = first.split('.')
@ -62,5 +58,6 @@ class Command(BaseCommand):
mod, name = GLOBAL_SECTION, first[0]
if Config.update(mod, name, value) is False: # If not exists, try to store value without any special parameters
Config.section(mod).value(name, value).get()
except Exception:
except Exception as e:
print('The command could not be processed: {}'.format(e))
logger.exception('Exception processing {}'.format(args))