1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-03-20 06:50:23 +03:00

Add compatibility for decoding text fields converted to password fields

This commit is contained in:
Adolfo Gómez García 2025-01-08 17:10:59 +01:00
parent 4d2ddd3909
commit 08b7fd549a
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23

View File

@ -1645,14 +1645,17 @@ class UserInterface(metaclass=UserInterfaceType):
if internal_field_type not in FIELD_DECODERS:
logger.warning('Field %s has no decoder', field_name)
continue
if field_type != internal_field_type.name:
logger.warning(
'Field %s has different type than expected: %s != %s',
field_name,
field_type,
internal_field_type.name,
)
continue
# Especial case for text fields converted to password fields
if not (internal_field_type == types.ui.FieldType.PASSWORD and field_type == types.ui.FieldType.TEXT.name):
logger.warning(
'Field %s has different type than expected: %s != %s',
field_name,
field_type,
internal_field_type.name,
)
continue
self._gui[field_name].value = FIELD_DECODERS[internal_field_type](field_value)
return False
@ -1776,6 +1779,17 @@ class UserInterface(metaclass=UserInterfaceType):
return field_name in self._gui
def password_compat_field_decoder(value: str) -> str:
"""
Compatibility function to decode text fields converted to password fields
"""
try:
value = CryptoManager.manager().aes_decrypt(value.encode('utf8'), UDSK, True).decode()
except Exception:
pass
logger.info('Decoding password field: %s', value)
return value
# Dictionaries used to encode/decode fields to be stored on database
FIELDS_ENCODERS: typing.Final[
collections.abc.Mapping[
@ -1804,9 +1818,7 @@ FIELD_DECODERS: typing.Final[
types.ui.FieldType.TEXT: lambda x: x,
types.ui.FieldType.TEXT_AUTOCOMPLETE: lambda x: x,
types.ui.FieldType.NUMERIC: int,
types.ui.FieldType.PASSWORD: lambda x: (
CryptoManager.manager().aes_decrypt(x.encode(), UDSK, True).decode()
),
types.ui.FieldType.PASSWORD: password_compat_field_decoder,
types.ui.FieldType.HIDDEN: lambda x: x,
types.ui.FieldType.CHOICE: lambda x: x,
types.ui.FieldType.MULTICHOICE: lambda x: serializer.deserialize(base64.b64decode(x.encode())),