linotp.lib.util module

contains utility functions

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

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

linotp.lib.util.check_session(request, scope='admin')[source]

This function checks the session cookie and compares it to the session parameter


recursively copies a dict


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)[source]
  • 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!
  • the value (literal) of the parameter if exists or nothing in case the parameter is optional, otherwise throw an exception

return the api version number


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)[source]

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


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


returns the linotp version

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

converts bytes to an integer

  • 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)[source]

Checks if the hostname is a valid FQDN

linotp.lib.util.normalize_activation_code(activationcode, upper=True, convert_o=True, convert_0=True)[source]

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


remove empty lines from the input document

Parameters:doc (string) – documemt containing long multiline text
Returns:data without empty lines
Return type:string

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.


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)[source]

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

  • x – left value
  • y – right value

the locale aware comparison result