linotp.lib.util module

contains utility functions

linotp.lib.util.check_selfservice_session(cookies=None, params=None, url=None)

This function checks the session cookie for the selfservice / userservice session

linotp.lib.util.check_session(request)

This function checks if the client is in the allowed IP range. The session cookie is no longer checked here because flask-jwt-extended does this now in BaseController::jwt_check.

Parameters

request – the request object

Returns

boolean

linotp.lib.util.checksum(msg: bytes) int
linotp.lib.util.dict_copy(dict_)

recursively copies a dict

linotp.lib.util.generate_otpkey(key_size: int = 20) str

generates the HMAC key of keysize. Should be 20 or 32 THe key is returned as a hexlified string

linotp.lib.util.generate_password(size=6, characters=None)
linotp.lib.util.getLowerParams(param)
linotp.lib.util.getParam()
input:
  • param (hash set): the set, which contains all parameters

  • which (lteral): the entry lookup

  • optional (boolean): defines if this parameter is optional or not
    • an exception is thrown if the parameter is required

    • otherwise: nothing done!

return:
  • the value (literal) of the parameter if exists or nothing in case the parameter is optional, otherwise throw an exception

linotp.lib.util.get_api_version()

return the api version number

linotp.lib.util.get_client(request)

This function returns the client.

It first tries to get the client as it is passed as the HTTP Client via REMOTE_ADDR.

If this client Address is in a list, that is allowed to overwrite its client address (like e.g. a FreeRADIUS server, which will always pass the FreeRADIUS address but not the address of the RADIUS client) it checks for the existance of the client parameter.

This returns the copyright information displayed in the WebUI and selfservice portal.

linotp.lib.util.get_request_param(request, key, default=None)

Returns the get / post / etc. param with the given key dependent on the content type

linotp.lib.util.get_version()

This returns the version, that is displayed in the WebUI and self service portal.

linotp.lib.util.get_version_number()

returns the linotp version

linotp.lib.util.int_from_bytes(bytes_, byteorder='little')

converts bytes to an integer

Parameters
  • bytes – The bytes, that should be converted

  • byteorder – ‘little’ for little endian (default) or ‘big’ for big endian

linotp.lib.util.is_valid_fqdn(hostname, split_port=False)

Checks if the hostname is a valid FQDN

linotp.lib.util.modhex_decode(m: str) str
linotp.lib.util.modhex_encode(s: str) str
linotp.lib.util.normalize_activation_code(activationcode, upper=True, convert_o=True, convert_0=True)

This normalizes the activation code. 1. lower letters are capitaliezed 2. Oh’s in the last two characters are turned to zeros 3. zeros before the last 2 characters are turned to Ohs

linotp.lib.util.remove_empty_lines(doc)

remove empty lines from the input document

Parameters

doc (string) – documemt containing long multiline text

Returns

data without empty lines

Return type

string

linotp.lib.util.remove_session_from_param(param)

Some low level functions like the userlisting do not like to have a session parameter in the param dictionary. So we remove the session from the params.

linotp.lib.util.str2unicode(input_str)

convert as binary string into a unicode string by trying various encodings :param input_str: input binary string :return: unicode output

linotp.lib.util.unicode_compare(x, y)

locale and unicode aware comparison operator - for usage in sorted()

Parameters
  • x – left value

  • y – right value

Returns

the locale aware comparison result

linotp.lib.util.uniquify(doubleList)