PyFoam.Infrastructure.Authentication module

Simple public key authentication with RSA based on the implementation http://code.activestate.com/recipes/578797-public-key-encryption-rsa/

class PyFoam.Infrastructure.Authentication.Key(exponent, modulus)

Bases: tuple

__dict__ = dict_proxy({'__module__': 'PyFoam.Infrastructure.Authentication', '__getstate__': <function __getstate__>, '__new__': <staticmethod object>, '_make': <classmethod object>, '_replace': <function _replace>, '__slots__': (), '_asdict': <function _asdict>, '__repr__': <function __repr__>, '__dict__': <property object>, '_fields': ('exponent', 'modulus'), '__getnewargs__': <function __getnewargs__>, 'modulus': <property object>, '__doc__': 'Key(exponent, modulus)', 'exponent': <property object>})
__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__module__ = 'PyFoam.Infrastructure.Authentication'
static __new__(_cls, exponent, modulus)

Create new instance of Key(exponent, modulus)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('exponent', 'modulus')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new Key object from a sequence or iterable

_replace(**kwds)

Return a new Key object replacing specified fields with new values

exponent

Alias for field number 0

modulus

Alias for field number 1

class PyFoam.Infrastructure.Authentication.KeyPair(public, private)

Bases: tuple

__dict__ = dict_proxy({'__module__': 'PyFoam.Infrastructure.Authentication', '__getstate__': <function __getstate__>, '__new__': <staticmethod object>, '_make': <classmethod object>, 'private': <property object>, '__doc__': 'KeyPair(public, private)', '_replace': <function _replace>, '__slots__': (), '_asdict': <function _asdict>, '__repr__': <function __repr__>, '__dict__': <property object>, '_fields': ('public', 'private'), '__getnewargs__': <function __getnewargs__>, 'public': <property object>})
__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__module__ = 'PyFoam.Infrastructure.Authentication'
static __new__(_cls, public, private)

Create new instance of KeyPair(public, private)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('public', 'private')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new KeyPair object from a sequence or iterable

_replace(**kwds)

Return a new KeyPair object replacing specified fields with new values

private

Alias for field number 1

public

Alias for field number 0

PyFoam.Infrastructure.Authentication.authenticatedKeys()[source]
PyFoam.Infrastructure.Authentication.checkAuthentication(userName, challenge)[source]
PyFoam.Infrastructure.Authentication.checkChallenge(challenge, pubKey)[source]
PyFoam.Infrastructure.Authentication.createChallengeString(msg)[source]
PyFoam.Infrastructure.Authentication.decode(bcipher, privkey, verbose=False)[source]
PyFoam.Infrastructure.Authentication.encode(msg, pubkey, verbose=False)[source]
PyFoam.Infrastructure.Authentication.ensureKeyPair()[source]
PyFoam.Infrastructure.Authentication.is_prime(n, k=30)[source]
PyFoam.Infrastructure.Authentication.key_to_str(key)[source]

Convert Key to string representation >>> key_to_str(Key(50476910741469568741791652650587163073, 95419691922573224706255222482923256353)) ‘25f97fd801214cdc163796f8a43289c1:47c92a08bc374e96c7af66eb141d7a21’

PyFoam.Infrastructure.Authentication.keygen(n, public=None)[source]

Generate public and private keys from primes up to N.

Optionally, specify the public key exponent (65537 is popular choice).

>>> pubkey, privkey = keygen(2**64)
>>> msg = 123456789012345
>>> coded = pow(msg, *pubkey)
>>> plain = pow(coded, *privkey)
>>> assert msg == plain
PyFoam.Infrastructure.Authentication.multinv(modulus, value)[source]

Multiplicative inverse in a given modulus

>>> multinv(191, 138)
18
>>> multinv(191, 38)
186
>>> multinv(120, 23)
47
PyFoam.Infrastructure.Authentication.myAuthenticatedKeysFile()[source]
PyFoam.Infrastructure.Authentication.myPrivateKey()[source]
PyFoam.Infrastructure.Authentication.myPrivateKeyFile()[source]
PyFoam.Infrastructure.Authentication.myPublicKey()[source]
PyFoam.Infrastructure.Authentication.myPublicKeyFile()[source]
PyFoam.Infrastructure.Authentication.myPublicKeyText()[source]
PyFoam.Infrastructure.Authentication.randprime(n=100000000)[source]
PyFoam.Infrastructure.Authentication.str_to_key(key_str)[source]

Convert string representation to Key (assuming valid input) >>> (str_to_key(‘25f97fd801214cdc163796f8a43289c1:47c92a08bc374e96c7af66eb141d7a21’) == … Key(exponent=50476910741469568741791652650587163073, modulus=95419691922573224706255222482923256353)) True