Package gluon :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

This file is part of the web2py Web Framework Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

This file specifically includes utilities for security.

Functions [hide private]
 
AES_new(key, IV=None)
Returns an AES cipher object and random IV if None specified
source code
 
compare(a, b)
compares two strings and not vulnerable to timing attacks
source code
 
md5_hash(text)
Generate a md5 hash with the given text
source code
 
simple_hash(text, key='', salt='', digest_alg='md5')
Generates hash with the given text using the specified digest hashing algorithm
source code
 
get_digest(value)
Returns a hashlib digest algorithm from a string
source code
 
pad(s, n=32, padchar=' ') source code
 
secure_dumps(data, encryption_key, hash_key=None, compression_level=None) source code
 
secure_loads(data, encryption_key, hash_key=None, compression_level=None) source code
 
initialize_urandom()
This function and the web2py_uuid follow from the following discussion: http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09
source code
 
fast_urandom16(urandom=[], locker=<_RLock owner=None count=0>)
this is 4x faster than calling os.urandom(16) and prevents the "too many files open" issue with concurrent access to os.urandom()
source code
 
web2py_uuid(ctokens=(9717086711068788442, 6984105393121222892))
This function follows from the following discussion: http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09
source code
 
is_valid_ip_address(address) source code
 
is_loopback_ip_address(ip=None, addrinfo=None)
Determines whether the address appears to be a loopback address.
source code
 
getipaddrinfo(host)
Filter out non-IP and bad IP addresses from getaddrinfo
source code
Variables [hide private]
  _struct_2_long_long = struct.Struct('=QQ')
  python_version = 2
  HAVE_PBKDF2 = True
  logger = logging.getLogger("web2py")
  DIGEST_ALG_BY_SIZE = {32: 'md5', 40: 'sha1', 56: 'sha224', 64:...
  REGEX_IPv4 = re.compile(r'(\d+)\.(\d+)\.(\d+)\.(\d+)')
  HAVE_URANDOM = True
  UNPACKED_CTOKENS = (9717086711068788442, 6984105393121222892)
  __package__ = 'gluon'
Function Details [hide private]

initialize_urandom()

source code 

This function and the web2py_uuid follow from the following discussion: http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09

At startup web2py compute a unique ID that identifies the machine by adding uuid.getnode() + int(time.time() * 1e3)

This is a 48-bit number. It converts the number into 16 8-bit tokens. It uses this value to initialize the entropy source ('/dev/urandom') and to seed random.

If os.random() is not supported, it falls back to using random and issues a warning.

web2py_uuid(ctokens=(9717086711068788442, 6984105393121222892))

source code 

This function follows from the following discussion: http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09

It works like uuid.uuid4 except that tries to use os.urandom() if possible and it XORs the output with the tokens uniquely associated with this machine.

is_loopback_ip_address(ip=None, addrinfo=None)

source code 

Determines whether the address appears to be a loopback address. This assumes that the IP is valid.


Variables Details [hide private]

DIGEST_ALG_BY_SIZE

Value:
{32: 'md5',
 40: 'sha1',
 56: 'sha224',
 64: 'sha256',
 96: 'sha384',
 128: 'sha512'}